@@ -352,26 +352,24 @@ static void append_suffix(int depth, const struct object_id *oid, struct strbuf
352
352
repo_find_unique_abbrev (the_repository , oid , abbrev ));
353
353
}
354
354
355
- static void describe_commit (struct object_id * oid , struct strbuf * dst )
355
+ static void describe_commit (struct commit * cmit , struct strbuf * dst )
356
356
{
357
- struct commit * cmit , * gave_up_on = NULL ;
357
+ struct commit * gave_up_on = NULL ;
358
358
struct lazy_queue queue = LAZY_QUEUE_INIT ;
359
359
struct commit_name * n ;
360
360
struct possible_tag all_matches [MAX_TAGS ];
361
361
unsigned int match_cnt = 0 , annotated_cnt = 0 , cur_match ;
362
362
unsigned long seen_commits = 0 ;
363
363
unsigned int unannotated_cnt = 0 ;
364
364
365
- cmit = lookup_commit_reference (the_repository , oid );
366
-
367
365
n = find_commit_name (& cmit -> object .oid );
368
366
if (n && (tags || all || n -> prio == 2 )) {
369
367
/*
370
368
* Exact match to an existing ref.
371
369
*/
372
370
append_name (n , dst );
373
371
if (n -> misnamed || longformat )
374
- append_suffix (0 , n -> tag ? get_tagged_oid (n -> tag ) : oid , dst );
372
+ append_suffix (0 , n -> tag ? get_tagged_oid (n -> tag ) : & cmit -> object . oid , dst );
375
373
if (suffix )
376
374
strbuf_addstr (dst , suffix );
377
375
return ;
@@ -528,39 +526,47 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
528
526
}
529
527
530
528
struct process_commit_data {
531
- struct object_id current_commit ;
532
- struct object_id looking_for ;
529
+ struct commit * current_commit ;
530
+ const struct object_id * looking_for ;
533
531
struct strbuf * dst ;
534
532
struct rev_info * revs ;
535
533
};
536
534
537
535
static void process_commit (struct commit * commit , void * data )
538
536
{
539
537
struct process_commit_data * pcd = data ;
540
- pcd -> current_commit = commit -> object . oid ;
538
+ pcd -> current_commit = commit ;
541
539
}
542
540
543
541
static void process_object (struct object * obj , const char * path , void * data )
544
542
{
545
543
struct process_commit_data * pcd = data ;
546
544
547
- if (oideq (& pcd -> looking_for , & obj -> oid ) && !pcd -> dst -> len ) {
545
+ if (oideq (pcd -> looking_for , & obj -> oid ) && !pcd -> dst -> len ) {
548
546
reset_revision_walk ();
549
- describe_commit (& pcd -> current_commit , pcd -> dst );
550
- strbuf_addf (pcd -> dst , ":%s" , path );
547
+ if (pcd -> current_commit ) {
548
+ describe_commit (pcd -> current_commit , pcd -> dst );
549
+ strbuf_addf (pcd -> dst , ":%s" , path );
550
+ }
551
551
free_commit_list (pcd -> revs -> commits );
552
552
pcd -> revs -> commits = NULL ;
553
553
}
554
554
}
555
555
556
- static void describe_blob (struct object_id oid , struct strbuf * dst )
556
+ static void describe_blob (const struct object_id * oid , struct strbuf * dst )
557
557
{
558
558
struct rev_info revs ;
559
559
struct strvec args = STRVEC_INIT ;
560
- struct process_commit_data pcd = { * null_oid (the_hash_algo ), oid , dst , & revs };
560
+ struct object_id head_oid ;
561
+ struct process_commit_data pcd = { NULL , oid , dst , & revs };
562
+
563
+ if (repo_get_oid (the_repository , "HEAD" , & head_oid ))
564
+ die (_ ("cannot search for blob '%s' on an unborn branch" ),
565
+ oid_to_hex (oid ));
561
566
562
567
strvec_pushl (& args , "internal: The first arg is not parsed" ,
563
- "--objects" , "--in-commit-order" , "--reverse" , "HEAD" ,
568
+ "--objects" , "--in-commit-order" , "--reverse" ,
569
+ oid_to_hex (& head_oid ),
564
570
NULL );
565
571
566
572
repo_init_revisions (the_repository , & revs , NULL );
@@ -574,6 +580,9 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
574
580
reset_revision_walk ();
575
581
release_revisions (& revs );
576
582
strvec_clear (& args );
583
+
584
+ if (!dst -> len )
585
+ die (_ ("blob '%s' not reachable from HEAD" ), oid_to_hex (oid ));
577
586
}
578
587
579
588
static void describe (const char * arg , int last_one )
@@ -590,10 +599,10 @@ static void describe(const char *arg, int last_one)
590
599
cmit = lookup_commit_reference_gently (the_repository , & oid , 1 );
591
600
592
601
if (cmit )
593
- describe_commit (& oid , & sb );
602
+ describe_commit (cmit , & sb );
594
603
else if (odb_read_object_info (the_repository -> objects ,
595
604
& oid , NULL ) == OBJ_BLOB )
596
- describe_blob (oid , & sb );
605
+ describe_blob (& oid , & sb );
597
606
else
598
607
die (_ ("%s is neither a commit nor blob" ), arg );
599
608
0 commit comments