@@ -191,7 +191,7 @@ struct ref_item {
191191
192192struct ref_list {
193193 struct rev_info revs ;
194- int index , alloc , maxwidth ;
194+ int index , alloc , maxwidth , verbose , abbrev ;
195195 struct ref_item * list ;
196196 struct commit_list * with_commit ;
197197 int kinds ;
@@ -240,21 +240,24 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
240240 if (ARRAY_SIZE (ref_kind ) <= i )
241241 return 0 ;
242242
243- commit = lookup_commit_reference_gently (sha1 , 1 );
244- if (!commit )
245- return error ("branch '%s' does not point at a commit" , refname );
246-
247- /* Filter with with_commit if specified */
248- if (!is_descendant_of (commit , ref_list -> with_commit ))
249- return 0 ;
250-
251243 /* Don't add types the caller doesn't want */
252244 if ((kind & ref_list -> kinds ) == 0 )
253245 return 0 ;
254246
255- if (merge_filter != NO_FILTER )
256- add_pending_object (& ref_list -> revs ,
257- (struct object * )commit , refname );
247+ commit = NULL ;
248+ if (ref_list -> verbose || ref_list -> with_commit || merge_filter != NO_FILTER ) {
249+ commit = lookup_commit_reference_gently (sha1 , 1 );
250+ if (!commit )
251+ return error ("branch '%s' does not point at a commit" , refname );
252+
253+ /* Filter with with_commit if specified */
254+ if (!is_descendant_of (commit , ref_list -> with_commit ))
255+ return 0 ;
256+
257+ if (merge_filter != NO_FILTER )
258+ add_pending_object (& ref_list -> revs ,
259+ (struct object * )commit , refname );
260+ }
258261
259262 /* Resize buffer */
260263 if (ref_list -> index >= ref_list -> alloc ) {
@@ -415,18 +418,38 @@ static int calc_maxwidth(struct ref_list *refs)
415418 return w ;
416419}
417420
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+
418440static void print_ref_list (int kinds , int detached , int verbose , int abbrev , struct commit_list * with_commit )
419441{
420442 int i ;
421443 struct ref_list ref_list ;
422- struct commit * head_commit = lookup_commit_reference_gently (head_sha1 , 1 );
423444
424445 memset (& ref_list , 0 , sizeof (ref_list ));
425446 ref_list .kinds = kinds ;
447+ ref_list .verbose = verbose ;
448+ ref_list .abbrev = abbrev ;
426449 ref_list .with_commit = with_commit ;
427450 if (merge_filter != NO_FILTER )
428451 init_revisions (& ref_list .revs , NULL );
429- for_each_ref (append_ref , & ref_list );
452+ for_each_rawref (append_ref , & ref_list );
430453 if (merge_filter != NO_FILTER ) {
431454 struct commit * filter ;
432455 filter = lookup_commit_reference_gently (merge_filter_ref , 0 );
@@ -442,19 +465,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
442465 qsort (ref_list .list , ref_list .index , sizeof (struct ref_item ), ref_cmp );
443466
444467 detached = (detached && (kinds & REF_LOCAL_BRANCH ));
445- if (detached && head_commit &&
446- is_descendant_of (head_commit , with_commit )) {
447- struct ref_item item ;
448- item .name = xstrdup ("(no branch)" );
449- item .len = strlen (item .name );
450- item .kind = REF_LOCAL_BRANCH ;
451- item .dest = NULL ;
452- item .commit = head_commit ;
453- if (item .len > ref_list .maxwidth )
454- ref_list .maxwidth = item .len ;
455- print_ref_item (& item , ref_list .maxwidth , verbose , abbrev , 1 , "" );
456- free (item .name );
457- }
468+ if (detached )
469+ show_detached (& ref_list );
458470
459471 for (i = 0 ; i < ref_list .index ; i ++ ) {
460472 int current = !detached &&
0 commit comments