aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-02-13 13:39:25 -0800
committerJunio C Hamano <gitster@pobox.com>2026-02-13 13:39:25 -0800
commit70cc3bca87abdfbc941e98d1c0d3199f758f0990 (patch)
tree059e3fd5c87ea206059faed65a490c21d33aa469 /builtin
parentf036245819e5981910ee39f72be6122c0ffbea2f (diff)
parent525ef52301be231c73393da5af4a4071f060eb20 (diff)
downloadgit-70cc3bca87abdfbc941e98d1c0d3199f758f0990.tar.xz
Merge branch 'tc/last-modified-not-a-tree'
Giving "git last-modified" a tree (not a commit-ish) died an uncontrolled death, which has been corrected. * tc/last-modified-not-a-tree: last-modified: verify revision argument is a commit-ish last-modified: remove double error message last-modified: fix memory leak when more than one commit is given last-modified: rewrite error message when more than one commit given
Diffstat (limited to 'builtin')
-rw-r--r--builtin/last-modified.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/builtin/last-modified.c b/builtin/last-modified.c
index f7f4c5109c..8900ceece1 100644
--- a/builtin/last-modified.c
+++ b/builtin/last-modified.c
@@ -124,7 +124,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;
/*
@@ -146,16 +146,25 @@ 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 commit at a time"));
+ goto out;
+ }
+
+ if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
+ ret = error(_("revision argument '%s' is a %s, not a commit-ish"), obj->name, type_name(obj->item->type));
+ 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,
@@ -494,7 +503,7 @@ static int last_modified_init(struct last_modified *lm, struct repository *r,
lm->rev.bloom_filter_settings = get_bloom_filter_settings(lm->rev.repo);
if (populate_paths_from_revs(lm) < 0)
- return error(_("unable to setup last-modified"));
+ return -1;
CALLOC_ARRAY(lm->all_paths, hashmap_get_size(&lm->paths));
lm->all_paths_nr = 0;