merge: clarify "pulling into void" special case

Instead of having it as one of the three if/elseif/.. case arms, test the condition and handle this special case upfront. This makes it easier to follow the flow of logic. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 23, 2015 at 13:46 UTC 1faac1cedca475a364c72b063c79da08caee0fe9
1 file changed +18 -17
builtin/merge.c
+18 -17
@@ -1178,23 +1178,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1178 usage_with_options(builtin_merge_usage,
1179 builtin_merge_options);
1180
1181 - /*
1182 - * This could be traditional "merge <msg> HEAD <commit>..." and
1183 - * the way we can tell it is to see if the second token is HEAD,
1184 - * but some people might have misused the interface and used a
1185 - * commit-ish that is the same as HEAD there instead.
1186 - * Traditional format never would have "-m" so it is an
1187 - * additional safety measure to check for it.
1188 - */
1189 -
1190 - if (!have_message && head_commit &&
1191 - is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
1192 - strbuf_addstr(&merge_msg, argv[0]);
1193 - head_arg = argv[1];
1194 - argv += 2;
1195 - argc -= 2;
1196 - remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
1197 - } else if (!head_commit) {
1181 + if (!head_commit) {
1182 struct commit *remote_head;
1183 /*
1184 * If the merged head is a valid one there is no reason
@@ -1217,6 +1201,23 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1201 update_ref("initial pull", "HEAD", remote_head->object.sha1,
1202 NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1203 goto done;
1204 + }
1205 +
1206 + /*
1207 + * This could be traditional "merge <msg> HEAD <commit>..." and
1208 + * the way we can tell it is to see if the second token is HEAD,
1209 + * but some people might have misused the interface and used a
1210 + * commit-ish that is the same as HEAD there instead.
1211 + * Traditional format never would have "-m" so it is an
1212 + * additional safety measure to check for it.
1213 + */
1214 + if (!have_message &&
1215 + is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
1216 + strbuf_addstr(&merge_msg, argv[0]);
1217 + head_arg = argv[1];
1218 + argv += 2;
1219 + argc -= 2;
1220 + remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
1221 } else {
1222 struct strbuf merge_names = STRBUF_INIT;
1223