git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] git-add--interactive: Preserve diff heading when splitting hunks
Date: Mon, 12 May 2014 16:09:52 -0400	[thread overview]
Message-ID: <20140512200952.GA2329@sigill.intra.peff.net> (raw)
In-Reply-To: <CACBZZX4W=1jPGcuBYstQkBDaT_wu38Fhxu642qwaFtCCqBdnyQ@mail.gmail.com>

On Mon, May 12, 2014 at 09:42:56PM +0200, Ævar Arnfjörð Bjarmason wrote:

> Good suggestion, but tricky as you point out. Another thing I've
> wanted many times is to make it smart enough that when you edit code
> like:
> 
>   A()
>   B();
> 
> And change it to:
> 
>   X();
> 
>   Y();
> 
> The change from A->X and B->Y may be completely unrelated and just
> made in code where the author didn't add whitespace between unrelated
> statements.
> 
> But because you change all the lines the tool can't split them up, it
> could try harder and split hunks like that if you add a whitespace
> boundary, or just go all the way down to adding/removing individual
> lines, so you wouldn't have to fall down to "edit" mode and do so
> manually.

Yeah, I frequently run into this, too, and have just gotten good at
editing the patch. :)

I think splitting line-by-line, as you suggest, would be more general.
However, working within a single cluster of lines is difficult (both
line-by-line and in your whitespace example), because you have to
correlate removed and added lines. E.g., the diff for your change above
might look like:

  @@ ... @@
   context
   -A();
   -B();
   +X();
   +
   +Y();
   more context

We would want to end up with three hunks:

  -A();
  +X();

  +

  -B();
  +Y();

but how do we know which preimage lines correspond with which postimage
lines? You can probably come up with heuristics for this case (e.g.,
introduced whitespace gets its own hunk, and then count postimage lines
from each end), but there are many harder cases.

> > I didn't prepare a commit message because I think it should probably
> > just be squashed in.
> 
> Well spotted, indeed, that should be squashed in.

If you do (or Junio does), I think the commit message needs a slight
update.

> On a related note I thought by doing color.ui=auto I was turning on
> all the colors, it would be nice if there was a built-in colorscheme
> that added more coloring to items like these across our tools, it's
> useful to have the hunk headers colored differently so they stand out
> more.

I don't set color.diff.func myself, but having just looked at it when
playing with your patch, I think it looks nice (I did "yellow").

I also set color.diff.meta to "magenta", which I think makes the hunk
header stand out a bit more.

So yeah, I'd be fine with proposing changes to the default color scheme,
though I do not envy you the inevitable bikeshed war. :)

-Peff

  reply	other threads:[~2014-05-12 20:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-11 16:09 [PATCH] git-add--interactive: Preserve diff heading when splitting hunks Ævar Arnfjörð Bjarmason
2014-05-11 17:52 ` Junio C Hamano
2014-05-12 18:39 ` Jeff King
2014-05-12 19:42   ` Ævar Arnfjörð Bjarmason
2014-05-12 20:09     ` Jeff King [this message]
2014-05-12 21:07   ` Junio C Hamano
2014-05-12 21:12     ` Jeff King

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=20140512200952.GA2329@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).