File tree Expand file tree Collapse file tree 2 files changed +69
-4
lines changed Expand file tree Collapse file tree 2 files changed +69
-4
lines changed Original file line number Diff line number Diff line change @@ -376,11 +376,25 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
376
376
if (!(c -> object .flags & t -> flag_within ))
377
377
t -> depth ++ ;
378
378
}
379
+ /* Stop if last remaining path already covered by best candidate(s) */
379
380
if (annotated_cnt && !list ) {
380
- if (debug )
381
- fprintf (stderr , _ ("finished search at %s\n" ),
382
- oid_to_hex (& c -> object .oid ));
383
- break ;
381
+ int best_depth = INT_MAX ;
382
+ unsigned best_within = 0 ;
383
+ for (cur_match = 0 ; cur_match < match_cnt ; cur_match ++ ) {
384
+ struct possible_tag * t = & all_matches [cur_match ];
385
+ if (t -> depth < best_depth ) {
386
+ best_depth = t -> depth ;
387
+ best_within = t -> flag_within ;
388
+ } else if (t -> depth == best_depth ) {
389
+ best_within |= t -> flag_within ;
390
+ }
391
+ }
392
+ if ((c -> object .flags & best_within ) == best_within ) {
393
+ if (debug )
394
+ fprintf (stderr , _ ("finished search at %s\n" ),
395
+ oid_to_hex (& c -> object .oid ));
396
+ break ;
397
+ }
384
398
}
385
399
while (parents ) {
386
400
struct commit * p = parents -> item ;
Original file line number Diff line number Diff line change @@ -479,4 +479,55 @@ test_expect_success 'name-rev covers all conditions while looking at parents' '
479
479
)
480
480
'
481
481
482
+ # B
483
+ # o
484
+ # \
485
+ # o-----o---o----x
486
+ # A
487
+ #
488
+ test_expect_success ' describe commits with disjoint bases' '
489
+ git init disjoint1 &&
490
+ (
491
+ cd disjoint1 &&
492
+
493
+ echo o >> file && git add file && git commit -m o &&
494
+ echo A >> file && git add file && git commit -m A &&
495
+ git tag A -a -m A &&
496
+ echo o >> file && git add file && git commit -m o &&
497
+
498
+ git checkout --orphan branch && rm file &&
499
+ echo B > file2 && git add file2 && git commit -m B &&
500
+ git tag B -a -m B &&
501
+ git merge --no-ff --allow-unrelated-histories master -m x &&
502
+
503
+ check_describe "A-3-*" HEAD
504
+ )
505
+ '
506
+
507
+ # B
508
+ # o---o---o------------.
509
+ # \
510
+ # o---o---x
511
+ # A
512
+ #
513
+ test_expect_success ' describe commits with disjoint bases 2' '
514
+ git init disjoint2 &&
515
+ (
516
+ cd disjoint2 &&
517
+
518
+ echo A >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:00" git commit -m A &&
519
+ git tag A -a -m A &&
520
+ echo o >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:01" git commit -m o &&
521
+
522
+ git checkout --orphan branch &&
523
+ echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
524
+ echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
525
+ echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
526
+ git tag B -a -m B &&
527
+ git merge --no-ff --allow-unrelated-histories master -m x &&
528
+
529
+ check_describe "B-3-*" HEAD
530
+ )
531
+ '
532
+
482
533
test_done
You can’t perform that action at this time.
0 commit comments