{"thread":{"id":"63977","subject":"[PATCH 0/2] line-log: small fixes","startedAt":"2025-08-18T11:13:24Z","lastAt":"2025-08-18T19:17:46Z","messageCount":5,"participants":["SZEDER Gábor","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"524341","messageId":"20250818111310.1283932-1-szeder.dev@gmail.com","threadId":"63977","inReplyTo":null,"subject":"[PATCH 0/2] line-log: small fixes","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2025-08-18T11:13:08Z","receivedAt":"2025-08-18T11:13:24Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, May 02, 2024 at 09:29:04PM +0300, Evgeni Chasnovski wrote:\n> Calling `git log` with several `-L` flags can result in an error.\n> \n> Steps to reproduce (on Linux):\n> - Set up repo with a history:\n>     - `mkdir log-line-assert`\n>     - `cd log-line-assert`\n>     - `git init`\n>     - `echo \"Line 1\\nLine 2\" > file`\n>     - `git add .`\n>     - `git commit -m 'Commit 1'`\n>     - `echo \"Line 3\\nLine 4\\nLine 5\" >> file`\n>     - `git add .`\n>     - `git commit -m 'Commit 2'`\n> - Execute the following command: `git log -L2,2:file -L4,4:file`\n> \n> # What did you expect to happen? (Expected behavior)\n> \n> Show log with evolution of lines 2 and 4.\n> \n> # What happened instead? (Actual behavior)\n> \n> An error with the following text:\n> \n> ```\n> git: line-log.c:73: range_set_append: Assertion `rs->nr == 0 ||\n> rs->ranges[rs->nr-1].end <= a' failed.\n> zsh: IOT instruction (core dumped)  git log -L2,2:file -L4,4:file\n> ```\n\nThanks for reporting this issue!\n\nAs it turns out, merely specifying more than one line range is\ninsufficient to trigger this assertion error, we need a rather specific\ninteraction between the line numbers of two line ranges and a diff range.\n\nThe first patch fixes this issue, along with a couple of similar bugs to\nmake that command really work, because once the assertion error was fixed\nwe ended up in an endless loop, and once that was fixed the output was\nwrong...\n\nThe second patch fixes another line-log output issue that I just happened\nto stumble upon while testing the fixes in the first patch.\n\n\nSZEDER Gábor (2):\n  line-log: fix assertion error\n  line-log: show all line ranges touched by the same diff range\n\n line-log.c                               | 15 +++-\n t/t4211-line-log.sh                      |  2 +\n t/t4211/sha1/expect.multiple             |  6 ++\n t/t4211/sha1/expect.no-assertion-error   | 90 ++++++++++++++++++++++++\n t/t4211/sha1/expect.two-ranges           |  6 ++\n t/t4211/sha256/expect.multiple           |  6 ++\n t/t4211/sha256/expect.no-assertion-error | 90 ++++++++++++++++++++++++\n t/t4211/sha256/expect.two-ranges         |  6 ++\n 8 files changed, 218 insertions(+), 3 deletions(-)\n create mode 100644 t/t4211/sha1/expect.no-assertion-error\n create mode 100644 t/t4211/sha256/expect.no-assertion-error\n\n-- \n2.51.0.rc2.346.g6515629ae9\n\n"},{"id":"524342","messageId":"20250818111310.1283932-2-szeder.dev@gmail.com","threadId":"63977","inReplyTo":"20250818111310.1283932-1-szeder.dev@gmail.com","subject":"[PATCH 1/2] line-log: fix assertion error","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2025-08-18T11:13:09Z","receivedAt":"2025-08-18T11:13:25Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When line-level log is invoked with more than one disjoint line range\nin the same file, and one of the commits happens to change that file\nsuch that:\n\n  - the last line of a line range R(n) immediately preceeds the first line\n    modified or added by a hunk H, and\n  - subtracting the number of lines added by hunk H from the start and\n    end of the subsequent line range R(n+1) would result in a range\n    overlapping with line range R(n),\n\nthen git aborts with an assertion error, because those overlapping\nline ranges violate the invariants:\n\n  $ git log --oneline -p\n  73e4e2f (HEAD -> master) Add lines 6 7 8 9 10\n  diff --git a/file b/file\n  index 572d5d9..00935f1 100644\n  --- a/file\n  +++ b/file\n  @@ -3,3 +3,8 @@ Line 2\n   Line 3\n   Line 4\n   Line 5\n  +Line 6\n  +Line 7\n  +Line 8\n  +Line 9\n  +Line 10\n  66e3561 Add lines 1 2 3 4 5\n  diff --git a/file b/file\n  new file mode 100644\n  index 0000000..572d5d9\n  --- /dev/null\n  +++ b/file\n  @@ -0,0 +1,5 @@\n  +Line 1\n  +Line 2\n  +Line 3\n  +Line 4\n  +Line 5\n  $ git log --oneline -L3,5:file -L7,8:file\n  git: line-log.c:73: range_set_append: Assertion `rs->nr == 0 || rs->ranges[rs->nr-1].end <= a' failed.\n  Aborted (core dumped)\n\nThe line-log machinery encodes line and diff ranges internally as\n[start, end) pairs, i.e. include 'start' but exclude 'end', and line\nnumbering starts at 0 (as opposed to the -LX,Y option, where it starts\nat 1, IOW the parameter -L3,5 is represented internally as { start =\n2, end = 5 }).\n\nThe reason for this assertion error and some related issues is that\nthere are a couple of places where 'end' is mistakenly considered to\nbe part of the range:\n\n  - When a commit modifies an interesting path, the line-log machinery\n    first checks which diff range (i.e. hunk) modify any line ranges.\n    This is done in diff_ranges_filter_touched(), where the outer loop\n    iterates over the diff ranges, and in each iteration the inner\n    loop advances the line ranges supposedly until the current line\n    range ends at or after the current diff range starts, and then the\n    current diff and line ranges are checked for overlap.\n\n    For HEAD in the above example the first line range [2, 5) ends\n    just before the diff range [5, 10) starts, so the inner loop\n    should advance, and then the second line range [6, 8) and the diff\n    range should be checked for overlap.\n\n    Unfortunately, the condition of the inner loop mistakenly\n    considers 'end' as part of the line range, and, seeing the diff\n    range starting at 5 and the line range ending at 5, it doesn't\n    skip the first range.  Consequently, the diff range and the first\n    line range are checked for overlap, and after that the outer loop\n    runs out of diff ranges, and then the processing goes on in the\n    false belief that this commit didn't touch any of the interesting\n    line ranges.\n\n    The line-log machinery later shifts the line ranges to account for\n    any added/removed lines in the diff ranges preceeding each line\n    range.  This leaves the first line range intact, but attempts to\n    shift the second line range [6, 8) by 5 lines towards the\n    beginning of the file, resulting in [1, 3), triggering the\n    assertion error, because the two overlapping line ranges violate\n    the invariants.\n\n    Fix that loop condition in diff_ranges_filter_touched() to not\n    treat 'end' as part of the line range.\n\n  - With the above fix the assertion error is gone... but, alas, we\n    now get stuck in an endless loop!\n\n    This happens in range_set_difference(), where a couple of nested\n    loops iterate over the line and diff ranges, and a condition is\n    supposed to break the middle loop when the current line range ends\n    before the current diff range, so processing could continue with\n    the next line range.\n\n    For HEAD in the above example the first line range [2, 5) ends\n    just before the diff range [5, 10) starts, so this condition\n    should trigger and break the middle loop.\n\n    Unfortunately, just like in the case of the assertion error, this\n    conditions mistakenly considers 'end' as part of the line range,\n    and, seeing the line range ending at 5 and the diff range starting\n    at 5, it doesn't break the loop, which will then go on and on.\n\n    Fix this condition in range_set_difference() to not treat 'end' as\n    part of the line range.\n\n  - With the above fix the endless loop is gone... but, alas, the\n    output is now wrong, as it shows both line ranges for HEAD, even\n    though the first line range is not modified by that commit:\n\n      $ git log --oneline -L3,5:file -L7,8:file\n      73e4e2f (HEAD -> master) Add lines 6 7 8 9 10\n\n      diff --git a/file b/file\n      --- a/file\n      +++ b/file\n      @@ -3,3 +3,3 @@\n       Line 3\n       Line 4\n       Line 5\n      @@ -6,0 +7,2 @@\n      +Line 7\n      +Line 8\n      66e3561 Add lines 1 2 3 4 5\n\n      diff --git a/file b/file\n      --- /dev/null\n      +++ b/file\n      @@ -0,0 +3,3 @@\n      +Line 3\n      +Line 4\n      +Line 5\n\n    In dump_diff_hacky_one() a couple of nested loops are responsible\n    for finding and printing the modified line ranges: the big outer\n    loop iterates over all line ranges, and the first inner loop skips\n    over the diff ranges that end before the start of the current line\n    range.  This is followed by a condition checking whether the\n    current diff range starts after the end of the current line range,\n    which, when fulfilled, continues and advances the outer loop to\n    the next line range.\n\n    For HEAD in the above example the first line range [2, 5) ends\n    just before the diff range [5, 10), so this condition should\n    trigger, and the outer loop should advance to the second line\n    range.\n\n    Unfortunately, just like in the previous cases, this condition\n    mistakenly considers 'end' as part of the line range, and, seeing\n    the first line range ending at 5 and the diff range starting at 5,\n    it doesn't continue to advance the outher loop, but goes on to\n    show the (unmodified) first line range.\n\n    Fix this condition to not treat 'end' as part of the line range,\n    just like in the previous cases.\n\nAfter all this the command in the above example finally finishes and\nproduces the right output:\n\n  $ git log --oneline -L3,5:file -L7,8:file\n  73e4e2f (HEAD -> master) Add lines 6 7 8 9 10\n\n  diff --git a/file b/file\n  --- a/file\n  +++ b/file\n  @@ -6,0 +7,2 @@\n  +Line 7\n  +Line 8\n  66e3561 Add lines 1 2 3 4 5\n\n  diff --git a/file b/file\n  --- /dev/null\n  +++ b/file\n  @@ -0,0 +3,3 @@\n  +Line 3\n  +Line 4\n  +Line 5\n\nAdd a canned test similar to the above example, with the line ranges\nadjusted to the test repository's history.\n\nReported-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n line-log.c                               |  6 +-\n t/t4211-line-log.sh                      |  2 +\n t/t4211/sha1/expect.no-assertion-error   | 90 ++++++++++++++++++++++++\n t/t4211/sha256/expect.no-assertion-error | 90 ++++++++++++++++++++++++\n 4 files changed, 185 insertions(+), 3 deletions(-)\n create mode 100644 t/t4211/sha1/expect.no-assertion-error\n create mode 100644 t/t4211/sha256/expect.no-assertion-error\n\ndiff --git a/line-log.c b/line-log.c\nindex 628e3fe3ae..9cb8ea1484 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -201,7 +201,7 @@ static void range_set_difference(struct range_set *out,\n \t\t\t\t * b: ------|\n \t\t\t\t */\n \t\t\t\tj++;\n-\t\t\tif (j >= b->nr || end < b->ranges[j].start) {\n+\t\t\tif (j >= b->nr || end <= b->ranges[j].start) {\n \t\t\t\t/*\n \t\t\t\t * b exhausted, or\n \t\t\t\t * a:  ----|\n@@ -408,7 +408,7 @@ static void diff_ranges_filter_touched(struct diff_ranges *out,\n \tassert(out->target.nr == 0);\n \n \tfor (i = 0; i < diff->target.nr; i++) {\n-\t\twhile (diff->target.ranges[i].start > rs->ranges[j].end) {\n+\t\twhile (diff->target.ranges[i].start >= rs->ranges[j].end) {\n \t\t\tj++;\n \t\t\tif (j == rs->nr)\n \t\t\t\treturn;\n@@ -941,7 +941,7 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n \n \t\twhile (j < diff->target.nr && diff->target.ranges[j].end < t_start)\n \t\t\tj++;\n-\t\tif (j == diff->target.nr || diff->target.ranges[j].start > t_end)\n+\t\tif (j == diff->target.nr || diff->target.ranges[j].start >= t_end)\n \t\t\tcontinue;\n \n \t\t/* Scan ahead to determine the last diff that falls in this range */\ndiff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh\nindex 950451cf6a..0a7c3ca42f 100755\n--- a/t/t4211-line-log.sh\n+++ b/t/t4211-line-log.sh\n@@ -78,6 +78,8 @@ canned_test \"-L :main:a.c -L 4,18:a.c simple\" multiple-overlapping\n canned_test \"-L 4:a.c -L 8,12:a.c simple\" multiple-superset\n canned_test \"-L 8,12:a.c -L 4:a.c simple\" multiple-superset\n \n+canned_test \"-L 10,16:b.c -L 18,26:b.c main\" no-assertion-error\n+\n test_bad_opts \"-L\" \"switch.*requires a value\"\n test_bad_opts \"-L b.c\" \"argument not .start,end:file\"\n test_bad_opts \"-L 1:\" \"argument not .start,end:file\"\ndiff --git a/t/t4211/sha1/expect.no-assertion-error b/t/t4211/sha1/expect.no-assertion-error\nnew file mode 100644\nindex 0000000000..994c37db1e\n--- /dev/null\n+++ b/t/t4211/sha1/expect.no-assertion-error\n@@ -0,0 +1,90 @@\n+commit 0d8dcfc6b968e06a27d5215bad1fdde3de9d6235\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:50:24 2013 +0100\n+\n+    move within the file\n+\n+diff --git a/b.c b/b.c\n+--- a/b.c\n++++ b/b.c\n+@@ -25,0 +18,9 @@\n++long f(long x)\n++{\n++\tint s = 0;\n++\twhile (x) {\n++\t\tx /= 2;\n++\t\ts++;\n++\t}\n++\treturn s;\n++}\n+\n+commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:48:43 2013 +0100\n+\n+    change back to complete line\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -18,5 +18,7 @@\n+ int main ()\n+ {\n+ \tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+-}\n+\\ No newline at end of file\n++}\n++\n++/* incomplete lines are bad! */\n+\n+commit 100b61a6f2f720f812620a9d10afb3a960ccb73c\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:48:10 2013 +0100\n+\n+    change to an incomplete line at end\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -18,5 +18,5 @@\n+ int main ()\n+ {\n+ \tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+-}\n++}\n+\\ No newline at end of file\n+\n+commit a6eb82647d5d67f893da442f8f9375fd89a3b1e2\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:45:16 2013 +0100\n+\n+    touch both functions\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -17,5 +17,5 @@\n+ int main ()\n+ {\n+-\tprintf(\"%d\\n\", f(15));\n++\tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+ }\n+\n+commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:44:48 2013 +0100\n+\n+    initial\n+\n+diff --git a/a.c b/a.c\n+--- /dev/null\n++++ b/a.c\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\ndiff --git a/t/t4211/sha256/expect.no-assertion-error b/t/t4211/sha256/expect.no-assertion-error\nnew file mode 100644\nindex 0000000000..36ed12aa9c\n--- /dev/null\n+++ b/t/t4211/sha256/expect.no-assertion-error\n@@ -0,0 +1,90 @@\n+commit eb871b8aa9aff323e484723039c9a92ab0266e060bc0ef2afb08fadda25c5ace\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:50:24 2013 +0100\n+\n+    move within the file\n+\n+diff --git a/b.c b/b.c\n+--- a/b.c\n++++ b/b.c\n+@@ -25,0 +18,9 @@\n++long f(long x)\n++{\n++\tint s = 0;\n++\twhile (x) {\n++\t\tx /= 2;\n++\t\ts++;\n++\t}\n++\treturn s;\n++}\n+\n+commit 5526ed05c2476b56af8b7be499e8f78bd50f490740733a9ca7e1f55878fa90a9\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:48:43 2013 +0100\n+\n+    change back to complete line\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -18,5 +18,7 @@\n+ int main ()\n+ {\n+ \tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+-}\n+\\ No newline at end of file\n++}\n++\n++/* incomplete lines are bad! */\n+\n+commit 29f32ac3141c48b22803e5c4127b719917b67d0f8ca8c5248bebfa2a19f7da10\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:48:10 2013 +0100\n+\n+    change to an incomplete line at end\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -18,5 +18,5 @@\n+ int main ()\n+ {\n+ \tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+-}\n++}\n+\\ No newline at end of file\n+\n+commit ccf97b9878189c40a981da50b15713bb80a35755326320ec80900caf22ced46f\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:45:16 2013 +0100\n+\n+    touch both functions\n+\n+diff --git a/a.c b/a.c\n+--- a/a.c\n++++ b/a.c\n+@@ -17,5 +17,5 @@\n+ int main ()\n+ {\n+-\tprintf(\"%d\\n\", f(15));\n++\tprintf(\"%ld\\n\", f(15));\n+ \treturn 0;\n+ }\n+\n+commit 1dd7e9b2b1699324b53b341e728653b913bc192a14dfea168c5b51f2b3d03592\n+Author: Thomas Rast <trast@student.ethz.ch>\n+Date:   Thu Feb 28 10:44:48 2013 +0100\n+\n+    initial\n+\n+diff --git a/a.c b/a.c\n+--- /dev/null\n++++ b/a.c\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\n-- \n2.51.0.rc2.346.g6515629ae9\n\n"},{"id":"524343","messageId":"20250818111310.1283932-3-szeder.dev@gmail.com","threadId":"63977","inReplyTo":"20250818111310.1283932-1-szeder.dev@gmail.com","subject":"[PATCH 2/2] line-log: show all line ranges touched by the same diff range","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2025-08-18T11:13:10Z","receivedAt":"2025-08-18T11:13:27Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"When line-level log is invoked with more than one disjoint line range\nin the same file, and one of the commits happens to change that file\nsuch that one diff range modifies more than one line range, then\nchanges to all modified line ranges should be shown, but only the\nchanges in the first modified line range are:\n\n  $ git log --oneline -p\n  80ca903 (HEAD -> master) Initial\n  diff --git a/file b/file\n  new file mode 100644\n  index 0000000..00935f1\n  --- /dev/null\n  +++ b/file\n  @@ -0,0 +1,10 @@\n  +Line 1\n  +Line 2\n  +Line 3\n  +Line 4\n  +Line 5\n  +Line 6\n  +Line 7\n  +Line 8\n  +Line 9\n  +Line 10\n  $ git log --oneline -L1,2:file -L4,5:file -L7,8:file\n  80ca903 (HEAD -> master) Initial\n\n  diff --git a/file b/file\n  --- /dev/null\n  +++ b/file\n  @@ -0,0 +1,2 @@\n  +Line 1\n  +Line 2\n\nThe line-log-specific diff printer is already clever enough to handle\nthe case when one line range covers multiple diff ranges, but the\npossibility of one diff range touching multiple disjoint line ranges\nwas apparently overlooked.\n\nAdd the necessary condition to dump_diff_hacky_one() to handle this case\nas well, and show all modified line ranges:\n\n  $ git log --oneline -L1,2:file -L4,5:file -L7,8:file\n  0f9a5b4 (HEAD -> master) Initial\n\n  diff --git a/file b/file\n  --- /dev/null\n  +++ b/file\n  @@ -0,0 +1,2 @@\n  +Line 1\n  +Line 2\n  @@ -0,0 +4,2 @@\n  +Line 4\n  +Line 5\n  @@ -0,0 +7,2 @@\n  +Line 7\n  +Line 8\n\nThis bug was already present in the initial line-log implementation\nadded in 2da1d1f6f (Implement line-history search (git log -L),\n2013-03-28).  Interestingly, that commit already contained a canned\ntest case covering a similar scenario:\n\n  \"-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple\"\n\nThis test case looks for two line ranges in the same file, and both\ntrace back disjointly to the test repository's inital commit,\ntherefore changes to both line ranges should have been shown for the\ninitial commit, but only changes for the first line range are shown.\nSo this test case should have failed from the very beginning, but it\nnever did, because, unfortunately, the canned expected result is\nincorrect, as it doesn't include changes for the second line range.\n\nA similar test with a similarly incorrect canned expected result was\nadded later in 209618860c (log -L: fix overlapping input ranges,\n2013-04-05).\n\nCorrect these two canned expected results to contain the changes for\nthe second line range for the initial commit as well.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n line-log.c                       | 9 +++++++++\n t/t4211/sha1/expect.multiple     | 6 ++++++\n t/t4211/sha1/expect.two-ranges   | 6 ++++++\n t/t4211/sha256/expect.multiple   | 6 ++++++\n t/t4211/sha256/expect.two-ranges | 6 ++++++\n 5 files changed, 33 insertions(+)\n\ndiff --git a/line-log.c b/line-log.c\nindex 9cb8ea1484..9b75b4ac39 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -939,6 +939,15 @@ static void dump_diff_hacky_one(struct rev_info *rev, struct line_log_data *rang\n \t\tlong t_cur = t_start;\n \t\tunsigned int j_last;\n \n+\t\t/*\n+\t\t * If a diff range touches multiple line ranges, then all\n+\t\t * those line ranges should be shown, so take a step back if\n+\t\t * the current line range is still in the previous diff range\n+\t\t * (even if only partially).\n+\t\t */\n+\t\tif (j > 0 && diff->target.ranges[j-1].end > t_start)\n+\t\t\tj--;\n+\n \t\twhile (j < diff->target.nr && diff->target.ranges[j].end < t_start)\n \t\t\tj++;\n \t\tif (j == diff->target.nr || diff->target.ranges[j].start >= t_end)\ndiff --git a/t/t4211/sha1/expect.multiple b/t/t4211/sha1/expect.multiple\nindex 76ad5b598c..1eee8a7801 100644\n--- a/t/t4211/sha1/expect.multiple\n+++ b/t/t4211/sha1/expect.multiple\n@@ -102,3 +102,9 @@ diff --git a/a.c b/a.c\n +\t\ts++;\n +\t}\n +}\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\ndiff --git a/t/t4211/sha1/expect.two-ranges b/t/t4211/sha1/expect.two-ranges\nindex 6109aa0dce..c5164f3be3 100644\n--- a/t/t4211/sha1/expect.two-ranges\n+++ b/t/t4211/sha1/expect.two-ranges\n@@ -100,3 +100,9 @@ diff --git a/a.c b/a.c\n +\t\ts++;\n +\t}\n +}\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\ndiff --git a/t/t4211/sha256/expect.multiple b/t/t4211/sha256/expect.multiple\nindex ca00409b9a..dbd987b74a 100644\n--- a/t/t4211/sha256/expect.multiple\n+++ b/t/t4211/sha256/expect.multiple\n@@ -102,3 +102,9 @@ diff --git a/a.c b/a.c\n +\t\ts++;\n +\t}\n +}\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\ndiff --git a/t/t4211/sha256/expect.two-ranges b/t/t4211/sha256/expect.two-ranges\nindex af57c8b997..6a94d3b9cb 100644\n--- a/t/t4211/sha256/expect.two-ranges\n+++ b/t/t4211/sha256/expect.two-ranges\n@@ -100,3 +100,9 @@ diff --git a/a.c b/a.c\n +\t\ts++;\n +\t}\n +}\n+@@ -0,0 +16,5 @@\n++int main ()\n++{\n++\tprintf(\"%d\\n\", f(15));\n++\treturn 0;\n++}\n-- \n2.51.0.rc2.346.g6515629ae9\n\n"},{"id":"524344","messageId":"aKMNuxb3Q95RHok1@szeder.dev","threadId":"63977","inReplyTo":"20250818111310.1283932-1-szeder.dev@gmail.com","subject":"Re: [PATCH 0/2] line-log: small fixes","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2025-08-18T11:25:47Z","receivedAt":"2025-08-18T11:25:50Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Aug 18, 2025 at 01:13:08PM +0200, SZEDER Gábor wrote:\n> On Thu, May 02, 2024 at 09:29:04PM +0300, Evgeni Chasnovski wrote:\n> > Calling `git log` with several `-L` flags can result in an error.\n> > \n> > Steps to reproduce (on Linux):\n> > - Set up repo with a history:\n> >     - `mkdir log-line-assert`\n> >     - `cd log-line-assert`\n> >     - `git init`\n> >     - `echo \"Line 1\\nLine 2\" > file`\n> >     - `git add .`\n> >     - `git commit -m 'Commit 1'`\n> >     - `echo \"Line 3\\nLine 4\\nLine 5\" >> file`\n> >     - `git add .`\n> >     - `git commit -m 'Commit 2'`\n> > - Execute the following command: `git log -L2,2:file -L4,4:file`\n> > \n> > # What did you expect to happen? (Expected behavior)\n> > \n> > Show log with evolution of lines 2 and 4.\n> > \n> > # What happened instead? (Actual behavior)\n> > \n> > An error with the following text:\n> > \n> > ```\n> > git: line-log.c:73: range_set_append: Assertion `rs->nr == 0 ||\n> > rs->ranges[rs->nr-1].end <= a' failed.\n> > zsh: IOT instruction (core dumped)  git log -L2,2:file -L4,4:file\n> > ```\n> \n> Thanks for reporting this issue!\n\nThe original bug report is at:\n\n  https://public-inbox.org/git/CAP9Eqm1PsYBdjoVKgomJZe79_ZCOAtP4p7uvprUOerdjrcUjmQ@mail.gmail.com/\n\nIt's been quite a while since I last sent a patch to the list, and\napparently my send-email skills became somewhat rusty...\n\n"},{"id":"524358","messageId":"xmqqjz30igmf.fsf@gitster.g","threadId":"63977","inReplyTo":"20250818111310.1283932-2-szeder.dev@gmail.com","subject":"Re: [PATCH 1/2] line-log: fix assertion error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-18T19:17:44Z","receivedAt":"2025-08-18T19:17:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n>   - When a commit modifies an interesting path, the line-log machinery\n>     first checks which diff range (i.e. hunk) modify any line ranges.\n>     This is done in diff_ranges_filter_touched(), where the outer loop\n>     iterates over the diff ranges, and in each iteration the inner\n>     loop advances the line ranges supposedly until the current line\n>     range ends at or after the current diff range starts, and then the\n>     current diff and line ranges are checked for overlap.\n> ...\n>     Fix that loop condition in diff_ranges_filter_touched() to not\n>     treat 'end' as part of the line range.\n>\n>   - With the above fix the assertion error is gone... but, alas, we\n>     now get stuck in an endless loop!\n> ...\n>     Fix this condition in range_set_difference() to not treat 'end' as\n>     part of the line range.\n>\n>   - With the above fix the endless loop is gone... but, alas, the\n>     output is now wrong, as it shows both line ranges for HEAD, even\n>     though the first line range is not modified by that commit:\n> ...\n>     Fix this condition to not treat 'end' as part of the line range,\n>     just like in the previous cases.\n>\n> After all this the command in the above example finally finishes and\n> produces the right output:\n\nWhat a lengthy journey X-<.\n\nThanks for an amusing description.\n"}]}