@@ -224,6 +224,24 @@ static int disambiguate_commit_only(const unsigned char *sha1, void *cb_data_unu
224
224
return kind == OBJ_COMMIT ;
225
225
}
226
226
227
+ static int disambiguate_committish_only (const unsigned char * sha1 , void * cb_data_unused )
228
+ {
229
+ struct object * obj ;
230
+ int kind ;
231
+
232
+ kind = sha1_object_info (sha1 , NULL );
233
+ if (kind == OBJ_COMMIT )
234
+ return 1 ;
235
+ if (kind != OBJ_TAG )
236
+ return 0 ;
237
+
238
+ /* We need to do this the hard way... */
239
+ obj = deref_tag (lookup_object (sha1 ), NULL , 0 );
240
+ if (obj && obj -> type == OBJ_COMMIT )
241
+ return 1 ;
242
+ return 0 ;
243
+ }
244
+
227
245
static int get_short_sha1 (const char * name , int len , unsigned char * sha1 ,
228
246
unsigned flags )
229
247
{
@@ -261,6 +279,8 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
261
279
memset (& ds , 0 , sizeof (ds ));
262
280
if (flags & GET_SHA1_COMMIT )
263
281
ds .fn = disambiguate_commit_only ;
282
+ else if (flags & GET_SHA1_COMMITTISH )
283
+ ds .fn = disambiguate_committish_only ;
264
284
265
285
find_short_object_filename (len , hex_pfx , & ds );
266
286
find_short_packed_object (len , bin_pfx , & ds );
@@ -440,7 +460,7 @@ static int get_parent(const char *name, int len,
440
460
unsigned char * result , int idx )
441
461
{
442
462
unsigned char sha1 [20 ];
443
- int ret = get_sha1_1 (name , len , sha1 , 0 );
463
+ int ret = get_sha1_1 (name , len , sha1 , GET_SHA1_COMMITTISH );
444
464
struct commit * commit ;
445
465
struct commit_list * p ;
446
466
@@ -473,7 +493,7 @@ static int get_nth_ancestor(const char *name, int len,
473
493
struct commit * commit ;
474
494
int ret ;
475
495
476
- ret = get_sha1_1 (name , len , sha1 , 0 );
496
+ ret = get_sha1_1 (name , len , sha1 , GET_SHA1_COMMITTISH );
477
497
if (ret )
478
498
return ret ;
479
499
commit = lookup_commit_reference (sha1 );
@@ -519,6 +539,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
519
539
unsigned char outer [20 ];
520
540
const char * sp ;
521
541
unsigned int expected_type = 0 ;
542
+ unsigned lookup_flags = 0 ;
522
543
struct object * o ;
523
544
524
545
/*
@@ -554,7 +575,10 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
554
575
else
555
576
return -1 ;
556
577
557
- if (get_sha1_1 (name , sp - name - 2 , outer , 0 ))
578
+ if (expected_type == OBJ_COMMIT )
579
+ lookup_flags = GET_SHA1_COMMITTISH ;
580
+
581
+ if (get_sha1_1 (name , sp - name - 2 , outer , lookup_flags ))
558
582
return -1 ;
559
583
560
584
o = parse_object (outer );
@@ -666,7 +690,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
666
690
if (!ret )
667
691
return 0 ;
668
692
669
- return get_short_sha1 (name , len , sha1 , 0 );
693
+ return get_short_sha1 (name , len , sha1 , lookup_flags );
670
694
}
671
695
672
696
/*
0 commit comments