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

[PATCH v6 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish

From
Toon Claes <toon@iotcl.com>
Date
Jan 30, 2026, 14:26 UTC
Message-ID
<20260130-toon-last-modified-tree-v6-0-db827e5df985@iotcl.com>
In-Reply-To
<20260127-toon-last-modified-tree-v5-0-38d18a0956d4@iotcl.com>
Recently there was a bug reported[1] passing a tree OID triggers a BUG:
    $ git last-modified fb06ce04173d47aaaa498385621cba8b8dfd7584
    BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified
    [1]    690163 IOT instruction (core dumped)  git last-modified
    `fb06ce04173d47aaaa498385621cba8b8dfd7584` is the tree commit id of web_src. I
    suppose this should've returned a nice error message or blank output.
Fix this bug by checking the revision argument.
[1]: https://lore.kernel.org/git/03f96860-29fc-42a7-a220-c3ec65eb8516@codeberg.org/
---
Changes in v6:
- Fix CI failure with Meson on Windows.
- Link to v5: https://patch.msgid.link/20260127-toon-last-modified-tree-v5-0-38d18a0956d4@iotcl.com
Changes in v5:
- Use 'commit' instead of 'revision'.
- Small typo fixes.
- Link to v4: https://patch.msgid.link/20260123-toon-last-modified-tree-v4-0-86bf97bad4e2@iotcl.com
Changes in v4:
- Extend the error message when revision is not a tree
- Extend the test to verify the error message when more than one
  revision is given.
- Link to v3: https://patch.msgid.link/20260116-toon-last-modified-tree-v3-0-e6ade4dc35ab@iotcl.com
Changes in v3:
- Split the change to plug the leak into a separate commit.
- Small changes to commit messages.
- Link to v2: https://patch.msgid.link/20260114-toon-last-modified-tree-v2-0-ba3b1860898f@iotcl.com
Changes in v2:
- Prepend the change with a commit that modifies the error message
  when more than one revision is given.
- Prepend another commit that removes double error message.
- Add test to ensure the command works with annotated tags too.
- Link to v1: https://patch.msgid.link/20260112-toon-last-modified-tree-v1-1-ecbc78341f76@iotcl.com
---
Toon Claes (4):
      last-modified: rewrite error message when more than one commit given
      last-modified: fix memory leak when more than one commit is given
      last-modified: remove double error message
      last-modified: verify revision argument is a commit-ish
 builtin/last-modified.c  | 19 ++++++++++++++-----
 t/t8020-last-modified.sh | 26 ++++++++++++++++++++------
 2 files changed, 34 insertions(+), 11 deletions(-)
Range-diff versus v5:
1:  d9f9531e67 = 1:  455e9bc0ca last-modified: rewrite error message when more than one commit given
2:  19ccaa2aae = 2:  2d51b5e381 last-modified: fix memory leak when more than one commit is given
3:  4bff975458 = 3:  68b3acefd7 last-modified: remove double error message
4:  a5d4c74ad7 ! 4:  d66ab6a033 last-modified: verify revision argument is a commit-ish
    @@ Commit message
     
         Fix this error by ensuring that the given revision peels to a commit.
     
    +    This change also adds a test to verify git-last-modified(1) can operate
    +    on an annotated tag. For this an annotated tag is added that points to
    +    the second commit. But this causes ambiguous results when calling
    +    git-name-rev(1) with `--tags`, because now two tags point to the same
    +    commit. To remove this ambiguity, pass `--exclude=<tag>` to
    +    git-name-rev(1) to exclude the new annotated tag.
    +
         Reported-by: Gusted <gusted@codeberg.org>
         Signed-off-by: Toon Claes <toon@iotcl.com>
     
    @@ t/t8020-last-modified.sh: test_expect_success 'setup' '
      	mkdir a/b &&
      	test_commit 3 a/b/file
      '
    +@@ t/t8020-last-modified.sh: check_last_modified() {
    + 
    + 	cat >expect &&
    + 	git ${indir:+-C "$indir"} last-modified "$@" >tmp.1 &&
    +-	git name-rev --annotate-stdin --name-only --tags \
    ++	git name-rev --annotate-stdin --name-only --tags --exclude=t2 \
    + 		<tmp.1 >tmp.2 &&
    + 	tr '\t' ' ' <tmp.2 >actual &&
    + 	test_cmp expect actual
     @@ t/t8020-last-modified.sh: test_expect_success 'last-modified recursive' '
      	EOF
      '
    @@ t/t8020-last-modified.sh: test_expect_success 'last-modified complains about unk
      
     +test_expect_success 'last-modified expects commit-ish' '
     +	test_must_fail git last-modified HEAD^{tree} 2>err &&
    -+	grep "revision argument '"'"'HEAD^{tree}'"'"' is a tree, not a commit-ish" err
    ++	test_grep "revision argument ${SQ}HEAD^{tree}${SQ} is a tree, not a commit-ish" err
     +'
     +
      test_done

--- base-commit: ea717645d199f6f1b66058886475db3e8c9330e9 change-id: 20260112-toon-last-modified-tree-fdd96b2feaf7

Previous: Toon ClaesNext: Toon Claes
Message 48 of 55 in “last-modified: verify revision argument is a commit-ish”
  1. last-modified: verify revision argument is a commit-ishToon Claes, Jan 12, 2026
  2. Junio C HamanoJan 12, 2026
  3. Patrick SteinhardtJan 13, 2026
  4. 0/3 Fix git-last-modified(1) bug triggered when passing a tree-ishToon Claes, Jan 14, 2026
  5. 1/3 last-modified: rewrite error message when more than one revision givenToon Claes, Jan 14, 2026
  6. Patrick SteinhardtJan 14, 2026
  7. Toon ClaesJan 15, 2026
  8. Patrick SteinhardtJan 15, 2026
  9. Kristoffer HaugsbakkJan 15, 2026
  10. Patrick SteinhardtJan 16, 2026
  11. Toon ClaesJan 16, 2026
  12. Junio C HamanoJan 16, 2026
  13. Patrick SteinhardtJan 19, 2026
  14. Kristoffer HaugsbakkJan 25, 2026
  15. Kristoffer HaugsbakkJan 15, 2026
  16. 2/3 last-modified: remove double error messageToon Claes, Jan 14, 2026
  17. Patrick SteinhardtJan 14, 2026
  18. 3/3 last-modified: verify revision argument is a commit-ishToon Claes, Jan 14, 2026
  19. Patrick SteinhardtJan 14, 2026
  20. Kristoffer HaugsbakkJan 15, 2026
  21. Junio C HamanoJan 15, 2026
  22. Toon ClaesJan 16, 2026
  23. 0/4 Fix git-last-modified(1) bug triggered when passing a tree-ishToon Claes, Jan 16, 2026
  24. 1/4 last-modified: rewrite error message when more than one revision givenToon Claes, Jan 16, 2026
  25. Junio C HamanoJan 16, 2026
  26. 2/4 last-modified: fix memory leak when more than one revision is givenToon Claes, Jan 16, 2026
  27. 3/4 last-modified: remove double error messageToon Claes, Jan 16, 2026
  28. Junio C HamanoJan 16, 2026
  29. 4/4 last-modified: verify revision argument is a commit-ishToon Claes, Jan 16, 2026
  30. Junio C HamanoJan 16, 2026
  31. 0/4 Fix git-last-modified(1) bug triggered when passing a tree-ishToon Claes, Jan 23, 2026
  32. 1/4 last-modified: rewrite error message when more than one revision givenToon Claes, Jan 23, 2026
  33. Junio C HamanoJan 23, 2026
  34. 2/4 last-modified: fix memory leak when more than one revision is givenToon Claes, Jan 23, 2026
  35. Junio C HamanoJan 23, 2026
  36. 3/4 last-modified: remove double error messageToon Claes, Jan 23, 2026
  37. Junio C HamanoJan 23, 2026
  38. 4/4 last-modified: verify revision argument is a commit-ishToon Claes, Jan 23, 2026
  39. Junio C HamanoJan 23, 2026
  40. Junio C HamanoJan 23, 2026
  41. 0/4 Fix git-last-modified(1) bug triggered when passing a tree-ishToon Claes, Jan 27, 2026
  42. 1/4 last-modified: rewrite error message when more than one commit givenToon Claes, Jan 27, 2026
  43. 2/4 last-modified: fix memory leak when more than one commit is givenToon Claes, Jan 27, 2026
  44. 3/4 last-modified: remove double error messageToon Claes, Jan 27, 2026
  45. 4/4 last-modified: verify revision argument is a commit-ishToon Claes, Jan 27, 2026
  46. Junio C HamanoJan 27, 2026
  47. Toon ClaesJan 29, 2026
  48. 0/4 Fix git-last-modified(1) bug triggered when passing a tree-ishToon Claes, Jan 30, 2026
  49. 1/4 last-modified: rewrite error message when more than one commit givenToon Claes, Jan 30, 2026
  50. 2/4 last-modified: fix memory leak when more than one commit is givenToon Claes, Jan 30, 2026
  51. 3/4 last-modified: remove double error messageToon Claes, Jan 30, 2026
  52. 4/4 last-modified: verify revision argument is a commit-ishToon Claes, Jan 30, 2026
  53. Patrick SteinhardtFeb 6, 2026
  54. Junio C HamanoJan 30, 2026
  55. Patrick SteinhardtFeb 6, 2026

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.