@@ -191,7 +191,7 @@ struct ref_item {
191
191
192
192
struct ref_list {
193
193
struct rev_info revs ;
194
- int index , alloc , maxwidth , verbose ;
194
+ int index , alloc , maxwidth , verbose , abbrev ;
195
195
struct ref_item * list ;
196
196
struct commit_list * with_commit ;
197
197
int kinds ;
@@ -418,15 +418,34 @@ static int calc_maxwidth(struct ref_list *refs)
418
418
return w ;
419
419
}
420
420
421
+
422
+ static void show_detached (struct ref_list * ref_list )
423
+ {
424
+ struct commit * head_commit = lookup_commit_reference_gently (head_sha1 , 1 );
425
+
426
+ if (head_commit && is_descendant_of (head_commit , ref_list -> with_commit )) {
427
+ struct ref_item item ;
428
+ item .name = xstrdup ("(no branch)" );
429
+ item .len = strlen (item .name );
430
+ item .kind = REF_LOCAL_BRANCH ;
431
+ item .dest = NULL ;
432
+ item .commit = head_commit ;
433
+ if (item .len > ref_list -> maxwidth )
434
+ ref_list -> maxwidth = item .len ;
435
+ print_ref_item (& item , ref_list -> maxwidth , ref_list -> verbose , ref_list -> abbrev , 1 , "" );
436
+ free (item .name );
437
+ }
438
+ }
439
+
421
440
static void print_ref_list (int kinds , int detached , int verbose , int abbrev , struct commit_list * with_commit )
422
441
{
423
442
int i ;
424
443
struct ref_list ref_list ;
425
- struct commit * head_commit = lookup_commit_reference_gently (head_sha1 , 1 );
426
444
427
445
memset (& ref_list , 0 , sizeof (ref_list ));
428
446
ref_list .kinds = kinds ;
429
447
ref_list .verbose = verbose ;
448
+ ref_list .abbrev = abbrev ;
430
449
ref_list .with_commit = with_commit ;
431
450
if (merge_filter != NO_FILTER )
432
451
init_revisions (& ref_list .revs , NULL );
@@ -446,19 +465,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
446
465
qsort (ref_list .list , ref_list .index , sizeof (struct ref_item ), ref_cmp );
447
466
448
467
detached = (detached && (kinds & REF_LOCAL_BRANCH ));
449
- if (detached && head_commit &&
450
- is_descendant_of (head_commit , with_commit )) {
451
- struct ref_item item ;
452
- item .name = xstrdup ("(no branch)" );
453
- item .len = strlen (item .name );
454
- item .kind = REF_LOCAL_BRANCH ;
455
- item .dest = NULL ;
456
- item .commit = head_commit ;
457
- if (item .len > ref_list .maxwidth )
458
- ref_list .maxwidth = item .len ;
459
- print_ref_item (& item , ref_list .maxwidth , verbose , abbrev , 1 , "" );
460
- free (item .name );
461
- }
468
+ if (detached )
469
+ show_detached (& ref_list );
462
470
463
471
for (i = 0 ; i < ref_list .index ; i ++ ) {
464
472
int current = !detached &&
0 commit comments