git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: John Keeping <john@keeping.me.uk>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: Different diff strategies in add --interactive
Date: Mon, 10 Jun 2013 17:56:56 -0400	[thread overview]
Message-ID: <20130610215656.GA28345@sigill.intra.peff.net> (raw)
In-Reply-To: <20130610214638.GK22905@serenity.lan>

On Mon, Jun 10, 2013 at 10:46:38PM +0100, John Keeping wrote:

> > Overall, I think respecting diff.algorithm in add--interactive is a very
> > sane thing to do. I would even be tempted to say we should allow a few
> > other select diff options (e.g., fewer or more context lines). If you
> > allowed diff options like this:
> > 
> >   git add --patch="--patience -U5"
> > 
> > that is very flexible, but I would not want to think about what the code
> > does when you pass --patch="--raw" or equal nonsense.
> 
> An alternative would be to permit them to be set from within the
> interactive UI.  I'd find it quite useful to experiment with various
> diff options when I encounter a hunk that isn't as easy to pick as I'd
> like.  I expect it would be very hard to do that on a per-hunk basis,
> although per-file doesn't seem like it would be too hard.

That's an interesting idea, for a subset of options (e.g., "increase
context for this hunk"). I suspect implementing it would be painful,
though, as you would have to re-run diff, and you have no guarantee of
getting the same set of hunks (e.g., the hunk might end up coalesced
with another).

> I don't intend to investigate that though - respecting diff.algorithm is
> good enough for my usage.

I don't blame you. :)

> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index d2c4ce6..0b0fac2 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -44,6 +44,8 @@ my ($diff_new_color) =
>  
>  my $normal_color = $repo->get_color("", "reset");
>  
> +my $diff_algorithm = ($repo->config('diff.algorithm') or 'default');
> +
>  my $use_readkey = 0;
>  my $use_termcap = 0;
>  my %term_escapes;
> @@ -731,6 +733,9 @@ sub run_git_apply {
>  sub parse_diff {
>  	my ($path) = @_;
>  	my @diff_cmd = split(" ", $patch_mode_flavour{DIFF});
> +	if ($diff_algorithm ne "default") {
> +		push @diff_cmd, "--diff-algorithm=${diff_algorithm}";
> +	}
>  	if (defined $patch_mode_revision) {
>  		push @diff_cmd, $patch_mode_revision;

Yeah, that looks like the sane way to do it to me. As a perl style
thing, I think the usual way of spelling 'default' is 'undef'. I.e.:

  my $diff_algorithm = $repo->config('diff.algorithm');
  ...
  if (defined $diff_algorithm) {
          push @diff_cmd, "--diff-algorithm=$diff_algorithm";
  }

-Peff

  reply	other threads:[~2013-06-10 21:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-10 14:28 Different diff strategies in add --interactive John Keeping
2013-06-10 19:28 ` Junio C Hamano
2013-06-10 21:11   ` Jeff King
2013-06-10 21:46     ` John Keeping
2013-06-10 21:56       ` Jeff King [this message]
2013-06-12 18:44         ` [PATCH] add--interactive: respect diff.algorithm John Keeping
2013-06-12 19:18           ` Jeff King
2013-06-23 19:19           ` Junio C Hamano
2013-06-23 19:50             ` John Keeping
2013-06-23 20:37               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130610215656.GA28345@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=john@keeping.me.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).