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

[BUG] incorrect line numbers reported in git am

From
Denton Liu <liu.denton@gmail.com>
Date
Oct 2, 2019, 18:45 UTC
Message-ID
<20191002184546.GA22174@generichostname>
Hello all,

I found a bug where the line numbers in git am are being reported incorrectly in the case where a patch fails to apply cleanly.

The test case for this is pretty simple:
	$ wget https://public-inbox.org/git/20191001185524.18772-1-newren@gmail.com/raw
	$ git am raw
And the output for this is:
	Applying: dir: special case check for the possibility that pathspec is NULL
	error: corrupt patch at line 87
	Patch failed at 0001 dir: special case check for the possibility that pathspec is NULL
	hint: Use 'git am --show-current-patch' to see the failed patch
	When you have resolved this problem, run "git am --continue".
	If you prefer to skip this patch, run "git am --skip" instead.
	To restore the original branch and stop patching, run "git am --abort".

In this case, the path is indeed corrupt. The final hunk header gives 25 lines after instead of 24 lines. As a result, it is erroring out correctly.

However, the line offsets are off. Line 87, as it reports, is the following:

	to avoid a segfault.

which is in the middle of the log message. I expect the line to be reported as something in the range of 198-203, where the end of the hunk actually is.

Indeed, if you take an 87 line offset from the cutoff "---", we can see that it gives us line 201, which appears at the end of the corrupt hunk.

So it appears that the bug is a result of the the apply process not taking into account the number of lines from the mail parsing step.

Thanks,
Denton
Next: Junio C Hamano
Message 1 of 12 in “[BUG] incorrect line numbers reported in git am”
  1. Denton LiuOct 2, 2019
  2. Junio C HamanoOct 2, 2019
  3. Denton LiuOct 2, 2019
  4. Junio C HamanoOct 2, 2019
  5. Denton LiuOct 2, 2019
  6. Junio C HamanoOct 3, 2019
  7. Duy NguyenOct 3, 2019
  8. Junio C HamanoOct 3, 2019
  9. apply: tell user location of corrupted patch fileDenton Liu, Oct 4, 2019
  10. Junio C HamanoOct 5, 2019
  11. Junio C HamanoOct 5, 2019
  12. Junio C HamanoOct 5, 2019

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.