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

Re: [PATCH v2 1/2] Allow git-apply to ignore the hunk headers

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 5, 2008, 22:39 UTC
Message-ID
<alpine.DEB.1.00.0806052304300.21190@racer>
In-Reply-To
<7vabhz1t2f.fsf@gitster.siamese.dyndns.org>
Hi,
On Thu, 5 Jun 2008, Junio C Hamano wrote:
Show 14 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > Sometimes, the easiest way to fix up a patch is to edit it directly, 
> > even adding or deleting lines.  Now, many people are not as divine as 
> > certain benevolent dictators as to update the hunk headers correctly 
> > at the first try.
> >
> > So teach the tool to do it for us.
> 
> Two comments and a half.
> 
>  * Latest POSIX draft talks about unified context and allows an empty line
>    to represent an empty common context line.  GNU diff already emits such
>    a diff.  fixup_counts() should take this into account.

As you pointed out, I wanted to support only add -e. But that should not be an issue at all. I think a "case ' ': case '\n':" should be enough, right?

>  * I'd sleep better at night if 'Probably "diff ..."' part were written 
>    in a bit more robust way.

How about stopping on "@@" and end of file only, and complaining otherwise?

>  * (minor) There is an established term for this operation: recountdiff, 
>    so --recount might be a better name.  fixup_counts() also is better 
>    called recount_diff() if we go this route.
Fine!
> If you are too narrowly focused to only support "git add -e", the first 
> issue does not matter, because we always emit "SP LF" for such a common 
> context.  The reason why I care about the first two points is because we 
> may want to teach git-am about this new option as well in 1.6.0.
Point taken.
Show 8 quoted lines
> And the robustness issue I worry about the second point also applies to 
> a line that is "^-- $", especially if we were to make this available to 
> git-am.  Perhaps when the line begins with a '-', the logic could be 
> extra careful to detect the case where the line looks like the e-mail 
> signature separator and check one line beyond it to see if it does not 
> look anything like part of a diff (in which case you stop, without 
> considering the line you are currently looking at, "^-- $", a deletion 
> of "^- $", as part of the preimage context).

Is this really an issue? fixup_counts() is only called after a hunk header was read, and that should be well after any "^-- $".

> As to code structure, we might want to make the later parameters to 
> apply_patch() an integer, of OR'ed flag values, or even a pointer to a 
> structure that holds options.
Right.
Will fix up and resubmit.

Ciao, Dscho

Previous: Junio C HamanoNext: Johannes Schindelin
Message 13 of 39 in “Allow git-apply to fix up the line counts”
  1. 1/2 Allow git-apply to fix up the line countsJohannes Schindelin, Jun 5, 2008
  2. 2/2 git-add: introduce --edit (to edit the diff vs. the index)Johannes Schindelin, Jun 5, 2008
  3. Johannes SixtJun 5, 2008
  4. Johannes SchindelinJun 5, 2008
  5. Johannes SixtJun 5, 2008
  6. Johannes SchindelinJun 5, 2008
  7. Johannes SixtJun 5, 2008
  8. Johannes SchindelinJun 5, 2008
  9. Johannes SixtJun 5, 2008
  10. 0/2 git add --editJohannes Schindelin, Jun 5, 2008
  11. 1/2 Allow git-apply to ignore the hunk headersJohannes Schindelin, Jun 5, 2008
  12. Junio C HamanoJun 5, 2008
  13. Johannes SchindelinJun 5, 2008
  14. 0/2 git add --editJohannes Schindelin, Jun 5, 2008
  15. 1/2 Allow git-apply to ignore the hunk headers (AKA recountdiff)Johannes Schindelin, Jun 5, 2008
  16. Junio C HamanoJun 6, 2008
  17. Johannes SchindelinJun 6, 2008
  18. Junio C HamanoJun 6, 2008
  19. Junio C HamanoJun 6, 2008
  20. Johannes SchindelinJun 6, 2008
  21. Junio C HamanoJun 6, 2008
  22. Johannes SchindelinJun 6, 2008
  23. Govind SalinasJun 6, 2008
  24. Johannes SchindelinJun 6, 2008
  25. 2/2 git-add: introduce --edit (to edit the diff vs. the index)Johannes Schindelin, Jun 5, 2008
  26. Olivier MarinJun 6, 2008
  27. Johannes SchindelinJun 6, 2008
  28. Junio C HamanoJun 6, 2008
  29. Johannes SchindelinJun 6, 2008
  30. Junio C HamanoJun 5, 2008
  31. Johannes SchindelinJun 5, 2008
  32. Paolo BonziniJun 6, 2008
  33. Johannes SchindelinJun 6, 2008
  34. Sergei OrganovJun 6, 2008
  35. Johannes SchindelinJun 6, 2008
  36. Junio C HamanoJun 6, 2008
  37. 2/2 git-add: introduce --edit (to edit the diff vs. the index)Johannes Schindelin, Jun 5, 2008
  38. Pieter de BieJun 5, 2008
  39. Junio C HamanoJun 5, 2008

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.