1082
struct commit *head_commit;
1083
struct strbuf buf = STRBUF_INIT;
1084
const char *head_arg;
1085
- int flag, i;
1085
+ int flag, i, ret = 0;
1086
int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
1087
struct commit_list *common = NULL;
1088
const char *best_strategy = NULL, *wt_strategy = NULL;
1096
* current branch.
1097
*/
1098
branch = resolve_ref("HEAD", head_sha1, 0, &flag);
1099
- if (branch && !prefixcmp(branch, "refs/heads/"))
1100
- branch += 11;
1099
+ if (branch) {
1100
+ if (!prefixcmp(branch, "refs/heads/"))
1101
+ branch += 11;
1102
+ branch = xstrdup(branch);
1103
+ }
1104
if (!branch || is_null_sha1(head_sha1))
1105
head_commit = NULL;
1106
else
1124
die(_("There is no merge to abort (MERGE_HEAD missing)."));
1125
1126
/* Invoke 'git reset --merge' */
1124
- return cmd_reset(nargc, nargv, prefix);
1127
+ ret = cmd_reset(nargc, nargv, prefix);
1128
+ goto done;
1129
}
1130
1131
if (read_cache_unmerged())
1209
read_empty(remote_head->sha1, 0);
1210
update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
1211
DIE_ON_ERR);
1208
- return 0;
1212
+ goto done;
1213
} else {
1214
struct strbuf merge_names = STRBUF_INIT;
1215
1296
* but first the most common case of merging one remote.
1297
*/
1298
finish_up_to_date("Already up-to-date.");
1295
- return 0;
1299
+ goto done;
1300
} else if (allow_fast_forward && !remoteheads->next &&
1301
!common->next &&
1302
!hashcmp(common->item->object.sha1, head_commit->object.sha1)) {
1317
strbuf_addstr(&msg,
1318
" (no commit created; -m option ignored)");
1319
o = want_commit(sha1_to_hex(remoteheads->item->object.sha1));
1316
- if (!o)
1317
- return 1;
1320
+ if (!o) {
1321
+ ret = 1;
1322
+ goto done;
1323
+ }
1324
1319
- if (checkout_fast_forward(head_commit->object.sha1, remoteheads->item->object.sha1))
1320
- return 1;
1325
+ if (checkout_fast_forward(head_commit->object.sha1,
1326
+ remoteheads->item->object.sha1)) {
1327
+ ret = 1;
1328
+ goto done;
1329
+ }
1330
1331
finish(head_commit, o->sha1, msg.buf);
1332
drop_save();
1324
- return 0;
1333
+ goto done;
1334
} else if (!remoteheads->next && common->next)
1335
;
1336
/*
1348
git_committer_info(IDENT_ERROR_ON_NO_NAME);
1349
printf(_("Trying really trivial in-index merge...\n"));
1350
if (!read_tree_trivial(common->item->object.sha1,
1342
- head_commit->object.sha1, remoteheads->item->object.sha1))
1343
- return merge_trivial(head_commit);
1351
+ head_commit->object.sha1,
1352
+ remoteheads->item->object.sha1)) {
1353
+ ret = merge_trivial(head_commit);
1354
+ goto done;
1355
+ }
1356
printf(_("Nope.\n"));
1357
}
1358
} else {
1380
}
1381
if (up_to_date) {
1382
finish_up_to_date("Already up-to-date. Yeeah!");
1371
- return 0;
1383
+ goto done;
1384
}
1385
}
1386
1462
* If we have a resulting tree, that means the strategy module
1463
* auto resolved the merge cleanly.
1464
*/
1453
- if (automerge_was_ok)
1454
- return finish_automerge(head_commit, common, result_tree,
1455
- wt_strategy);
1465
+ if (automerge_was_ok) {
1466
+ ret = finish_automerge(head_commit, common, result_tree,
1467
+ wt_strategy);
1468
+ goto done;
1469
+ }
1470
1471
/*
1472
* Pick the result from the best strategy and have the user fix
1480
else
1481
fprintf(stderr, _("Merge with strategy %s failed.\n"),
1482
use_strategies[0]->name);
1469
- return 2;
1483
+ ret = 2;
1484
+ goto done;
1485
} else if (best_strategy == wt_strategy)
1486
; /* We already have its result in the working tree. */
1487
else {
1497
else
1498
write_merge_state();
1499
1485
- if (merge_was_ok) {
1500
+ if (merge_was_ok)
1501
fprintf(stderr, _("Automatic merge went well; "
1502
"stopped before committing as requested\n"));
1488
- return 0;
1489
- } else
1490
- return suggest_conflicts(option_renormalize);
1503
+ else
1504
+ ret = suggest_conflicts(option_renormalize);
1505
+
1506
+done:
1507
+ free((char *)branch);
1508
+ return ret;
1509
}