@@ -391,6 +391,7 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
391
391
int show_upstream_ref )
392
392
{
393
393
int ours , theirs ;
394
+ char * ref = NULL ;
394
395
struct branch * branch = branch_get (branch_name );
395
396
396
397
if (!stat_tracking_info (branch , & ours , & theirs )) {
@@ -401,16 +402,29 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
401
402
return ;
402
403
}
403
404
404
- strbuf_addch (stat , '[' );
405
405
if (show_upstream_ref )
406
- strbuf_addf (stat , "%s: " ,
407
- shorten_unambiguous_ref (branch -> merge [0 ]-> dst , 0 ));
408
- if (!ours )
409
- strbuf_addf (stat , _ ("behind %d] " ), theirs );
410
- else if (!theirs )
411
- strbuf_addf (stat , _ ("ahead %d] " ), ours );
412
- else
413
- strbuf_addf (stat , _ ("ahead %d, behind %d] " ), ours , theirs );
406
+ ref = shorten_unambiguous_ref (branch -> merge [0 ]-> dst , 0 );
407
+ if (!ours ) {
408
+ if (ref )
409
+ strbuf_addf (stat , _ ("[%s: behind %d]" ), ref , theirs );
410
+ else
411
+ strbuf_addf (stat , _ ("[behind %d]" ), theirs );
412
+
413
+ } else if (!theirs ) {
414
+ if (ref )
415
+ strbuf_addf (stat , _ ("[%s: ahead %d]" ), ref , ours );
416
+ else
417
+ strbuf_addf (stat , _ ("[ahead %d]" ), ours );
418
+ } else {
419
+ if (ref )
420
+ strbuf_addf (stat , _ ("[%s: ahead %d, behind %d]" ),
421
+ ref , ours , theirs );
422
+ else
423
+ strbuf_addf (stat , _ ("[ahead %d, behind %d]" ),
424
+ ours , theirs );
425
+ }
426
+ strbuf_addch (stat , ' ' );
427
+ free (ref );
414
428
}
415
429
416
430
static int matches_merge_filter (struct commit * commit )
0 commit comments