mirror of
https://github.com/git/git.git
synced 2026-01-24 15:57:20 +09:00
Merge branch 'tc/last-modified-not-a-tree' into jch
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 revision is given last-modified: rewrite error message when more than one revision given
This commit is contained in:
commit
772e825405
@ -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,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 revision at a time"));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
|
||||
ret = error(_("revision argument is not a commit-ish"));
|
||||
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,
|
||||
@ -491,7 +500,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;
|
||||
|
||||
@ -8,11 +8,12 @@ test_expect_success 'setup' '
|
||||
test_commit 1 file &&
|
||||
mkdir a &&
|
||||
test_commit 2 a/file &&
|
||||
git tag -mA t2 2 &&
|
||||
mkdir a/b &&
|
||||
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
|
||||
'
|
||||
|
||||
@ -55,6 +56,13 @@ test_expect_success 'last-modified recursive' '
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'last-modified on annotated tag' '
|
||||
check_last_modified t2 <<-\EOF
|
||||
2 a
|
||||
1 file
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'last-modified recursive with show-trees' '
|
||||
check_last_modified -r -t <<-\EOF
|
||||
3 a/b
|
||||
@ -235,4 +243,9 @@ test_expect_success 'last-modified complains about unknown arguments' '
|
||||
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
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user