public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl•com>
To: git@vger•kernel.org
Cc: Patrick Steinhardt <ps@pks•im>,
	 Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail•com>,
	 Toon Claes <toon@iotcl•com>, Gusted <gusted@codeberg•org>
Subject: [PATCH v4 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish
Date: Fri, 23 Jan 2026 15:33:00 +0100	[thread overview]
Message-ID: <20260123-toon-last-modified-tree-v4-0-86bf97bad4e2@iotcl.com> (raw)
In-Reply-To: <20260116-toon-last-modified-tree-v3-0-e6ade4dc35ab@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 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 revision given
      last-modified: fix memory leak when more than one revision 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 | 24 +++++++++++++++++++-----
 2 files changed, 33 insertions(+), 10 deletions(-)

Range-diff versus v3:

1:  8786f5d6a4 ! 1:  1bd4bb7cb8 last-modified: rewrite error message when more than one revision given
    @@ Commit message
     
             error: last-modified can only operate on one revision at a time
     
    +    While at it, ensure modify the test to ensure the correct error message
    +    is printed.
    +
         Signed-off-by: Toon Claes <toon@iotcl•com>
     
      ## builtin/last-modified.c ##
    @@ t/t8020-last-modified.sh: test_expect_success 'setup' '
      '
      
     -test_expect_success 'cannot run last-modified on two trees' '
    +-	test_must_fail git last-modified HEAD HEAD~1
    +-'
    +-
    + check_last_modified() {
    + 	local indir= &&
    + 	while test $# != 0
    +@@ t/t8020-last-modified.sh: test_expect_success 'last-modified merge undoes changes' '
    + 	EOF
    + '
    + 
     +test_expect_success 'cannot run last-modified on two revision' '
    - 	test_must_fail git last-modified HEAD HEAD~1
    ++	test_must_fail git last-modified HEAD HEAD~1 2>err &&
    ++	test_grep "last-modified can only operate on one revision at a time" err
    ++'
    ++
    + test_expect_success 'last-modified complains about unknown arguments' '
    + 	test_must_fail git last-modified --foo 2>err &&
    +-	grep "unknown last-modified argument: --foo" err
    ++	test_grep "unknown last-modified argument: --foo" err
      '
      
    + test_done
2:  78ec93a9e2 = 2:  ed1bd102a2 last-modified: fix memory leak when more than one revision is given
3:  05b4424289 = 3:  7a6e587da1 last-modified: remove double error message
4:  00e29cd6a1 ! 4:  fee3aa92a9 last-modified: verify revision argument is a commit-ish
    @@ builtin/last-modified.c: static int populate_paths_from_revs(struct last_modifie
      		}
      
     +		if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
    -+			ret = error(_("revision argument is not a commit-ish"));
    ++			ret = error(_("revision argument '%s' is a %s, not a commit-ish"), obj->name, type_name(obj->item->type));
     +			goto out;
     +		}
     +
    @@ t/t8020-last-modified.sh: test_expect_success 'last-modified recursive' '
      	check_last_modified -r -t <<-\EOF
      	3 a/b
     @@ t/t8020-last-modified.sh: test_expect_success 'last-modified complains about unknown arguments' '
    - 	grep "unknown last-modified argument: --foo" err
    + 	test_grep "unknown last-modified argument: --foo" err
      '
      
     +test_expect_success 'last-modified expects commit-ish' '
     +	test_must_fail git last-modified HEAD^{tree} 2>err &&
    -+	grep "revision argument is not a commit-ish" err
    ++	grep "revision argument '"'"'HEAD^{tree}'"'"' is a tree, not a commit-ish" err
     +'
     +
      test_done


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


  parent reply	other threads:[~2026-01-23 14:33 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12 16:17 [PATCH] last-modified: verify revision argument is a commit-ish Toon Claes
2026-01-12 20:23 ` Junio C Hamano
2026-01-13  6:54 ` Patrick Steinhardt
2026-01-14 10:24 ` [PATCH v2 0/3] Fix git-last-modified(1) bug triggered when passing a tree-ish Toon Claes
2026-01-14 10:24   ` [PATCH v2 1/3] last-modified: rewrite error message when more than one revision given Toon Claes
2026-01-14 10:56     ` Patrick Steinhardt
2026-01-15 11:33       ` Toon Claes
2026-01-15 11:54         ` Patrick Steinhardt
2026-01-15 14:34           ` Kristoffer Haugsbakk
2026-01-16  7:09             ` Patrick Steinhardt
2026-01-16 12:30               ` Toon Claes
2026-01-16 17:16               ` Junio C Hamano
2026-01-19  6:57                 ` Patrick Steinhardt
2026-01-25 11:26               ` Kristoffer Haugsbakk
2026-01-15 14:34         ` Kristoffer Haugsbakk
2026-01-14 10:24   ` [PATCH v2 2/3] last-modified: remove double error message Toon Claes
2026-01-14 10:56     ` Patrick Steinhardt
2026-01-14 10:24   ` [PATCH v2 3/3] last-modified: verify revision argument is a commit-ish Toon Claes
2026-01-14 10:56     ` Patrick Steinhardt
2026-01-15 16:02     ` Kristoffer Haugsbakk
2026-01-15 16:35       ` Junio C Hamano
2026-01-16 13:11       ` Toon Claes
2026-01-16 13:08   ` [PATCH v3 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish Toon Claes
2026-01-16 13:08     ` [PATCH v3 1/4] last-modified: rewrite error message when more than one revision given Toon Claes
2026-01-16 17:31       ` Junio C Hamano
2026-01-16 13:08     ` [PATCH v3 2/4] last-modified: fix memory leak when more than one revision is given Toon Claes
2026-01-16 13:08     ` [PATCH v3 3/4] last-modified: remove double error message Toon Claes
2026-01-16 18:22       ` Junio C Hamano
2026-01-16 13:08     ` [PATCH v3 4/4] last-modified: verify revision argument is a commit-ish Toon Claes
2026-01-16 18:24       ` Junio C Hamano
2026-01-23 14:33     ` Toon Claes [this message]
2026-01-23 14:33       ` [PATCH v4 1/4] last-modified: rewrite error message when more than one revision given Toon Claes
2026-01-23 17:01         ` Junio C Hamano
2026-01-23 14:33       ` [PATCH v4 2/4] last-modified: fix memory leak when more than one revision is given Toon Claes
2026-01-23 17:04         ` Junio C Hamano
2026-01-23 14:33       ` [PATCH v4 3/4] last-modified: remove double error message Toon Claes
2026-01-23 17:07         ` Junio C Hamano
2026-01-23 14:33       ` [PATCH v4 4/4] last-modified: verify revision argument is a commit-ish Toon Claes
2026-01-23 17:12         ` Junio C Hamano
2026-01-23 17:31         ` Junio C Hamano
2026-01-27 13:26       ` [PATCH v5 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish Toon Claes
2026-01-27 13:26         ` [PATCH v5 1/4] last-modified: rewrite error message when more than one commit given Toon Claes
2026-01-27 13:26         ` [PATCH v5 2/4] last-modified: fix memory leak when more than one commit is given Toon Claes
2026-01-27 13:26         ` [PATCH v5 3/4] last-modified: remove double error message Toon Claes
2026-01-27 13:26         ` [PATCH v5 4/4] last-modified: verify revision argument is a commit-ish Toon Claes
2026-01-27 22:34         ` [PATCH v5 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish Junio C Hamano
2026-01-29 14:59           ` Toon Claes
2026-01-30 14:26         ` [PATCH v6 " Toon Claes
2026-01-30 14:26           ` [PATCH v6 1/4] last-modified: rewrite error message when more than one commit given Toon Claes
2026-01-30 14:26           ` [PATCH v6 2/4] last-modified: fix memory leak when more than one commit is given Toon Claes
2026-01-30 14:26           ` [PATCH v6 3/4] last-modified: remove double error message Toon Claes
2026-01-30 14:26           ` [PATCH v6 4/4] last-modified: verify revision argument is a commit-ish Toon Claes
2026-02-06 15:55             ` Patrick Steinhardt
2026-01-30 17:07           ` [PATCH v6 0/4] Fix git-last-modified(1) bug triggered when passing a tree-ish Junio C Hamano
2026-02-06 15:55             ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260123-toon-last-modified-tree-v4-0-86bf97bad4e2@iotcl.com \
    --to=toon@iotcl$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gusted@codeberg$(echo .)org \
    --cc=kristofferhaugsbakk@fastmail$(echo .)com \
    --cc=ps@pks$(echo .)im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox