summaryrefslogtreecommitdiff
path: root/builtin/merge.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-04-25 12:31:57 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-04-29 13:19:21 -0700
commit018b3fbc7e66439786492662b88cb34d7d000621 (patch)
treef9bf4575cc4295f2ec35a49f905a6731e33bb605 /builtin/merge.c
parentmerge: split reduce_parents() out of collect_parents() (diff)
downloadtgif-018b3fbc7e66439786492662b88cb34d7d000621.tar.xz
merge: narrow scope of merge_names
In order to pass the list of parents to fmt_merge_msg(), cmd_merge() uses this strbuf to create something that look like FETCH_HEAD that describes commits that are being merged. This is necessary only when we are creating the merge commit message ourselves, but was done unconditionally. Move the variable and the logic to populate it to confine them in a block that needs them. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge.c')
-rw-r--r--builtin/merge.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 054f0521d8..d853c9d805 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1236,8 +1236,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
argc -= 2;
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
} else {
- struct strbuf merge_names = STRBUF_INIT;
-
/* We are invoked directly as the first-class UI. */
head_arg = "HEAD";
@@ -1247,11 +1245,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* to the given message.
*/
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
- for (p = remoteheads; p; p = p->next)
- merge_name(merge_remote_util(p->item)->name, &merge_names);
if (!have_message || shortlog_len) {
+ struct strbuf merge_names = STRBUF_INIT;
struct fmt_merge_msg_opts opts;
+
+ for (p = remoteheads; p; p = p->next)
+ merge_name(merge_remote_util(p->item)->name, &merge_names);
+
memset(&opts, 0, sizeof(opts));
opts.add_title = !have_message;
opts.shortlog_len = shortlog_len;
@@ -1260,6 +1261,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
fmt_merge_msg(&merge_names, &merge_msg, &opts);
if (merge_msg.len)
strbuf_setlen(&merge_msg, merge_msg.len - 1);
+
+ strbuf_release(&merge_names);
}
}