@@ -403,6 +403,16 @@ static void finish(const unsigned char *new_head, const char *msg)
403
403
strbuf_release (& reflog_message );
404
404
}
405
405
406
+ static struct object * want_commit (const char * name )
407
+ {
408
+ struct object * obj ;
409
+ unsigned char sha1 [20 ];
410
+ if (get_sha1 (name , sha1 ))
411
+ return NULL ;
412
+ obj = parse_object (sha1 );
413
+ return peel_to_type (name , 0 , obj , OBJ_COMMIT );
414
+ }
415
+
406
416
/* Get the name for the merge commit's message. */
407
417
static void merge_name (const char * remote , struct strbuf * msg )
408
418
{
@@ -418,7 +428,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
418
428
remote = bname .buf ;
419
429
420
430
memset (branch_head , 0 , sizeof (branch_head ));
421
- remote_head = peel_to_type (remote , 0 , NULL , OBJ_COMMIT );
431
+ remote_head = want_commit (remote );
422
432
if (!remote_head )
423
433
die (_ ("'%s' does not point to a commit" ), remote );
424
434
@@ -1124,7 +1134,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1124
1134
if (!allow_fast_forward )
1125
1135
die (_ ("Non-fast-forward commit does not make sense into "
1126
1136
"an empty head" ));
1127
- remote_head = peel_to_type (argv [0 ], 0 , NULL , OBJ_COMMIT );
1137
+ remote_head = want_commit (argv [0 ]);
1128
1138
if (!remote_head )
1129
1139
die (_ ("%s - not something we can merge" ), argv [0 ]);
1130
1140
read_empty (remote_head -> sha1 , 0 );
@@ -1170,7 +1180,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1170
1180
struct object * o ;
1171
1181
struct commit * commit ;
1172
1182
1173
- o = peel_to_type (argv [i ], 0 , NULL , OBJ_COMMIT );
1183
+ o = want_commit (argv [i ]);
1174
1184
if (!o )
1175
1185
die (_ ("%s - not something we can merge" ), argv [i ]);
1176
1186
commit = lookup_commit (o -> sha1 );
@@ -1238,8 +1248,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1238
1248
if (have_message )
1239
1249
strbuf_addstr (& msg ,
1240
1250
" (no commit created; -m option ignored)" );
1241
- o = peel_to_type (sha1_to_hex (remoteheads -> item -> object .sha1 ),
1242
- 0 , NULL , OBJ_COMMIT );
1251
+ o = want_commit (sha1_to_hex (remoteheads -> item -> object .sha1 ));
1243
1252
if (!o )
1244
1253
return 1 ;
1245
1254
0 commit comments