From: Toon Claes Date: Wed, 14 Jan 2026 10:24:45 GMT Subject: [PATCH v2 1/3] last-modified: rewrite error message when more than one revision given Message-ID: <20260114-toon-last-modified-tree-v2-1-ba3b1860898f@iotcl.com> In-Reply-To: <20260114-toon-last-modified-tree-v2-0-ba3b1860898f@iotcl.com> When more than one revision is passed to the git-last-modified(1) command, this error message was printed: error: last-modified can only operate on one tree at a time Calling these a "tree" is technically not correct. git-last-modified(1) expects revisions that peel to a commit. Rephrase the error message to: error: last-modified can only operate on one revision at a time While at it, also fix a memory leak that remained uncovered so far. Signed-off-by: Toon Claes --- builtin/last-modified.c | 12 ++++++++---- t/t8020-last-modified.sh | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/builtin/last-modified.c b/builtin/last-modified.c index c80f0535f6..06e3f79aec 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -123,7 +123,7 @@ static void add_path_from_diff(struct diff_queue_struct *q, static int populate_paths_from_revs(struct last_modified *lm) { - int num_interesting = 0; + int num_interesting = 0, ret = 0; struct diff_options diffopt; /* @@ -145,16 +145,20 @@ static int populate_paths_from_revs(struct last_modified *lm) if (obj->item->flags & UNINTERESTING) continue; - if (num_interesting++) - return error(_("last-modified can only operate on one tree at a time")); + if (num_interesting++) { + ret = error(_("last-modified can only operate on one revision at a time")); + goto out; + } diff_tree_oid(lm->rev.repo->hash_algo->empty_tree, &obj->item->oid, "", &diffopt); diff_flush(&diffopt); } + +out: clear_pathspec(&diffopt.pathspec); - return 0; + return ret; } static void last_modified_emit(struct last_modified *lm, diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh index 50f4312f71..1183ae667b 100755 --- a/t/t8020-last-modified.sh +++ b/t/t8020-last-modified.sh @@ -12,7 +12,7 @@ test_expect_success 'setup' ' test_commit 3 a/b/file ' -test_expect_success 'cannot run last-modified on two trees' ' +test_expect_success 'cannot run last-modified on two revision' ' test_must_fail git last-modified HEAD HEAD~1 ' -- 2.52.0