diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-08-19 15:34:13 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-19 15:34:14 -0700 |
commit | aeb1b7f55d5db4eda968de5eb27f04d42df9edc1 (patch) | |
tree | fdea1fcbbbb3837bb82b38dc0d578c46020c0c4c | |
parent | d63263a4dee8fc7da9b97bbdedf9c0d1f33024d4 (diff) | |
parent | 5447a76aad4074c31e7c8a6299cc586435f385e9 (diff) | |
download | git-aeb1b7f55d5db4eda968de5eb27f04d42df9edc1.tar.gz |
Merge branch 'rs/pull-signed-tag'
When "git merge-recursive" works on history with many criss-cross
merges in "verbose" mode, the names the command assigns to the
virtual merge bases could have overwritten each other by unintended
reuse of the same piece of memory.
* rs/pull-signed-tag:
commit: use FLEX_ARRAY in struct merge_remote_desc
merge-recursive: fix verbose output for multiple base trees
commit: factor out set_merge_remote_desc()
commit: use xstrdup() in get_merge_parent()
-rw-r--r-- | commit.c | 18 | ||||
-rw-r--r-- | commit.h | 4 | ||||
-rw-r--r-- | merge-recursive.c | 5 | ||||
-rwxr-xr-x | t/t3030-merge-recursive.sh | 18 |
4 files changed, 33 insertions, 12 deletions
@@ -1576,6 +1576,15 @@ int commit_tree_extended(const char *msg, size_t msg_len, return result; } +void set_merge_remote_desc(struct commit *commit, + const char *name, struct object *obj) +{ + struct merge_remote_desc *desc; + FLEX_ALLOC_STR(desc, name, name); + desc->obj = obj; + commit->util = desc; +} + struct commit *get_merge_parent(const char *name) { struct object *obj; @@ -1585,13 +1594,8 @@ struct commit *get_merge_parent(const char *name) return NULL; obj = parse_object(oid.hash); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); - if (commit && !commit->util) { - struct merge_remote_desc *desc; - desc = xmalloc(sizeof(*desc)); - desc->obj = obj; - desc->name = strdup(name); - commit->util = desc; - } + if (commit && !commit->util) + set_merge_remote_desc(commit, name, obj); return commit; } @@ -362,9 +362,11 @@ extern void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void * struct merge_remote_desc { struct object *obj; /* the named object, could be a tag */ - const char *name; + char name[FLEX_ARRAY]; }; #define merge_remote_util(commit) ((struct merge_remote_desc *)((commit)->util)) +extern void set_merge_remote_desc(struct commit *commit, + const char *name, struct object *obj); /* * Given "name" from the command line to merge, find the commit object diff --git a/merge-recursive.c b/merge-recursive.c index e5243c2b76..e34912683c 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -73,12 +73,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, static struct commit *make_virtual_commit(struct tree *tree, const char *comment) { struct commit *commit = alloc_commit_node(); - struct merge_remote_desc *desc = xmalloc(sizeof(*desc)); - desc->name = comment; - desc->obj = (struct object *)commit; + set_merge_remote_desc(commit, comment, (struct object *)commit); commit->tree = tree; - commit->util = desc; commit->object.parsed = 1; return commit; } diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh index f7b0e599f1..470f33466c 100755 --- a/t/t3030-merge-recursive.sh +++ b/t/t3030-merge-recursive.sh @@ -660,4 +660,22 @@ test_expect_success 'merging with triple rename across D/F conflict' ' git merge other ' +test_expect_success 'merge-recursive remembers the names of all base trees' ' + git reset --hard HEAD && + + # more trees than static slots used by oid_to_hex() + for commit in $c0 $c2 $c4 $c5 $c6 $c7 + do + git rev-parse "$commit^{tree}" + done >trees && + + # ignore the return code -- it only fails because the input is weird + test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out && + + # merge-recursive prints in reverse order, but we do not care + sort <trees >expect && + sed -n "s/^virtual //p" out | sort >actual && + test_cmp expect actual +' + test_done |