@@ -413,7 +413,7 @@ static void finish(struct commit *head_commit,
413413static void merge_name (const char * remote , struct strbuf * msg )
414414{
415415 struct commit * remote_head ;
416- unsigned char branch_head [20 ], buf_sha [ 20 ] ;
416+ unsigned char branch_head [20 ];
417417 struct strbuf buf = STRBUF_INIT ;
418418 struct strbuf bname = STRBUF_INIT ;
419419 const char * ptr ;
@@ -477,7 +477,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
477477 strbuf_addstr (& truname , "refs/heads/" );
478478 strbuf_addstr (& truname , remote );
479479 strbuf_setlen (& truname , truname .len - len );
480- if (resolve_ref (truname .buf , buf_sha , 1 , NULL )) {
480+ if (ref_exists (truname .buf )) {
481481 strbuf_addf (msg ,
482482 "%s\t\tbranch '%s'%s of .\n" ,
483483 sha1_to_hex (remote_head -> object .sha1 ),
@@ -1091,7 +1091,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
10911091 struct commit * head_commit ;
10921092 struct strbuf buf = STRBUF_INIT ;
10931093 const char * head_arg ;
1094- int flag , i ;
1094+ int flag , i , ret = 0 ;
10951095 int best_cnt = -1 , merge_was_ok = 0 , automerge_was_ok = 0 ;
10961096 struct commit_list * common = NULL ;
10971097 const char * best_strategy = NULL , * wt_strategy = NULL ;
@@ -1105,8 +1105,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11051105 * current branch.
11061106 */
11071107 branch = resolve_ref ("HEAD" , head_sha1 , 0 , & flag );
1108- if (branch && !prefixcmp (branch , "refs/heads/" ))
1109- branch += 11 ;
1108+ if (branch ) {
1109+ if (!prefixcmp (branch , "refs/heads/" ))
1110+ branch += 11 ;
1111+ branch = xstrdup (branch );
1112+ }
11101113 if (!branch || is_null_sha1 (head_sha1 ))
11111114 head_commit = NULL ;
11121115 else
@@ -1132,7 +1135,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
11321135 die (_ ("There is no merge to abort (MERGE_HEAD missing)." ));
11331136
11341137 /* Invoke 'git reset --merge' */
1135- return cmd_reset (nargc , nargv , prefix );
1138+ ret = cmd_reset (nargc , nargv , prefix );
1139+ goto done ;
11361140 }
11371141
11381142 if (read_cache_unmerged ())
@@ -1219,7 +1223,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12191223 read_empty (remote_head -> object .sha1 , 0 );
12201224 update_ref ("initial pull" , "HEAD" , remote_head -> object .sha1 ,
12211225 NULL , 0 , DIE_ON_ERR );
1222- return 0 ;
1226+ goto done ;
12231227 } else {
12241228 struct strbuf merge_names = STRBUF_INIT ;
12251229
@@ -1308,7 +1312,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13081312 * but first the most common case of merging one remote.
13091313 */
13101314 finish_up_to_date ("Already up-to-date." );
1311- return 0 ;
1315+ goto done ;
13121316 } else if (allow_fast_forward && !remoteheads -> next &&
13131317 !common -> next &&
13141318 !hashcmp (common -> item -> object .sha1 , head_commit -> object .sha1 )) {
@@ -1329,16 +1333,20 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13291333 strbuf_addstr (& msg ,
13301334 " (no commit created; -m option ignored)" );
13311335 commit = remoteheads -> item ;
1332- if (!commit )
1333- return 1 ;
1336+ if (!commit ) {
1337+ ret = 1 ;
1338+ goto done ;
1339+ }
13341340
13351341 if (checkout_fast_forward (head_commit -> object .sha1 ,
1336- commit -> object .sha1 ))
1337- return 1 ;
1342+ commit -> object .sha1 )) {
1343+ ret = 1 ;
1344+ goto done ;
1345+ }
13381346
13391347 finish (head_commit , commit -> object .sha1 , msg .buf );
13401348 drop_save ();
1341- return 0 ;
1349+ goto done ;
13421350 } else if (!remoteheads -> next && common -> next )
13431351 ;
13441352 /*
@@ -1356,8 +1364,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13561364 git_committer_info (IDENT_ERROR_ON_NO_NAME );
13571365 printf (_ ("Trying really trivial in-index merge...\n" ));
13581366 if (!read_tree_trivial (common -> item -> object .sha1 ,
1359- head_commit -> object .sha1 , remoteheads -> item -> object .sha1 ))
1360- return merge_trivial (head_commit );
1367+ head_commit -> object .sha1 ,
1368+ remoteheads -> item -> object .sha1 )) {
1369+ ret = merge_trivial (head_commit );
1370+ goto done ;
1371+ }
13611372 printf (_ ("Nope.\n" ));
13621373 }
13631374 } else {
@@ -1385,7 +1396,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13851396 }
13861397 if (up_to_date ) {
13871398 finish_up_to_date ("Already up-to-date. Yeeah!" );
1388- return 0 ;
1399+ goto done ;
13891400 }
13901401 }
13911402
@@ -1467,9 +1478,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14671478 * If we have a resulting tree, that means the strategy module
14681479 * auto resolved the merge cleanly.
14691480 */
1470- if (automerge_was_ok )
1471- return finish_automerge (head_commit , common , result_tree ,
1472- wt_strategy );
1481+ if (automerge_was_ok ) {
1482+ ret = finish_automerge (head_commit , common , result_tree ,
1483+ wt_strategy );
1484+ goto done ;
1485+ }
14731486
14741487 /*
14751488 * Pick the result from the best strategy and have the user fix
@@ -1483,7 +1496,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14831496 else
14841497 fprintf (stderr , _ ("Merge with strategy %s failed.\n" ),
14851498 use_strategies [0 ]-> name );
1486- return 2 ;
1499+ ret = 2 ;
1500+ goto done ;
14871501 } else if (best_strategy == wt_strategy )
14881502 ; /* We already have its result in the working tree. */
14891503 else {
@@ -1499,10 +1513,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14991513 else
15001514 write_merge_state ();
15011515
1502- if (merge_was_ok ) {
1516+ if (merge_was_ok )
15031517 fprintf (stderr , _ ("Automatic merge went well; "
15041518 "stopped before committing as requested\n" ));
1505- return 0 ;
1506- } else
1507- return suggest_conflicts (option_renormalize );
1519+ else
1520+ ret = suggest_conflicts (option_renormalize );
1521+
1522+ done :
1523+ free ((char * )branch );
1524+ return ret ;
15081525}
0 commit comments