Skip to content

Commit 018b3fb

Browse files
committed
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 <[email protected]>
1 parent 34349db commit 018b3fb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

builtin/merge.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12361236
argc -= 2;
12371237
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
12381238
} else {
1239-
struct strbuf merge_names = STRBUF_INIT;
1240-
12411239
/* We are invoked directly as the first-class UI. */
12421240
head_arg = "HEAD";
12431241

@@ -1247,11 +1245,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12471245
* to the given message.
12481246
*/
12491247
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
1250-
for (p = remoteheads; p; p = p->next)
1251-
merge_name(merge_remote_util(p->item)->name, &merge_names);
12521248

12531249
if (!have_message || shortlog_len) {
1250+
struct strbuf merge_names = STRBUF_INIT;
12541251
struct fmt_merge_msg_opts opts;
1252+
1253+
for (p = remoteheads; p; p = p->next)
1254+
merge_name(merge_remote_util(p->item)->name, &merge_names);
1255+
12551256
memset(&opts, 0, sizeof(opts));
12561257
opts.add_title = !have_message;
12571258
opts.shortlog_len = shortlog_len;
@@ -1260,6 +1261,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12601261
fmt_merge_msg(&merge_names, &merge_msg, &opts);
12611262
if (merge_msg.len)
12621263
strbuf_setlen(&merge_msg, merge_msg.len - 1);
1264+
1265+
strbuf_release(&merge_names);
12631266
}
12641267
}
12651268

0 commit comments

Comments
 (0)