git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git add --interactive patch improvement for split hunks

From
Jeff King <peff@peff.net>
Date
Jun 24, 2021, 15:41 UTC
Message-ID
<YNSnlhbE30xDfVMY@coredump.intra.peff.net>
In-Reply-To
<60D45FE4020000A100041FCE@gwsmtp.uni-regensburg.de>
On Thu, Jun 24, 2021 at 12:35:16PM +0200, Ulrich Windl wrote:
Show 6 quoted lines
> I noticed that git add -interactive's patch displays the function
> context for the diffs, but that function context is lost when the
> hunks are split.
>
> It would help the user (especially for hunks covering multiple
> functioins) if function context were still provided for split hunks.

This was discussed a while ago (and there is even a patch) in this thread:

  https://lore.kernel.org/git/20201117020522.GD19433@coredump.intra.peff.net/

The short of it is that the upcoming builtin-in-C version of the code will preserve the function header when splitting. The patch in that message adds it to the existing perl version, but I didn't really bother moving it forward, since that code is all supposed to eventually go away[0].

One thing you may not like, though: both the builtin version and that patch only put the funcname context in the _first_ hunk of the split. Doing it for subsequent hunks is much trickier, since there can be a funcname in the split context itself. E.g.:

  @@ ... @@ void foo()
           int x;
  -        int y = 1;
  +        int y = 2;
   
  -        x = 3;
  +        x = 4;
   }
could split into two hunks, both annotated with "void foo()". But:
  @@ ... @@ void foo()
           int x;
  -        x = 3;
  +        x = 4;
   }
   void bar()
   {
  -        int y = 1;
  +        int y = 2;
   }

would be wrong to say "void foo()" for the second hunk. We'd have to re-scan the interior context lines for a funcname to find it. That's all-but-impossible in the perl version, but might be do-able in the C version (since it has easy access to the funcname-matching patterns and machinery).

-Peff
[0] I'm not sure what the timetable is for switching to the C version of
    add--interactive. If it's going to be a while, I don't mind moving
    forward the other patch I showed. But maybe the time is here to
    think about switching the default of add.interactive.useBuiltin, and
    ironing out any final bugs?
Previous: Ulrich WindlNext: Ulrich Windl
Message 2 of 9 in “git add --interactive patch improvement for split hunks”
  1. Ulrich WindlJun 24, 2021
  2. Jeff KingJun 24, 2021
  3. Antw: [EXT] Re: git add --interactive patch improvement for split hunksUlrich Windl, Jun 28, 2021
  4. Ævar Arnfjörð BjarmasonJun 28, 2021
  5. Jeff KingJun 30, 2021
  6. Junio C HamanoJun 30, 2021
  7. Jeff KingJun 30, 2021
  8. Ævar Arnfjörð BjarmasonJun 30, 2021
  9. Jeff KingJun 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.