@@ -193,21 +193,6 @@ struct ref_list {
193193 int kinds ;
194194};
195195
196- static int has_commit (struct commit * commit , struct commit_list * with_commit )
197- {
198- if (!with_commit )
199- return 1 ;
200- while (with_commit ) {
201- struct commit * other ;
202-
203- other = with_commit -> item ;
204- with_commit = with_commit -> next ;
205- if (in_merge_bases (other , & commit , 1 ))
206- return 1 ;
207- }
208- return 0 ;
209- }
210-
211196static int append_ref (const char * refname , const unsigned char * sha1 , int flags , void * cb_data )
212197{
213198 struct ref_list * ref_list = (struct ref_list * )(cb_data );
@@ -231,7 +216,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
231216 return error ("branch '%s' does not point at a commit" , refname );
232217
233218 /* Filter with with_commit if specified */
234- if (!has_commit (commit , ref_list -> with_commit ))
219+ if (!is_descendant_of (commit , ref_list -> with_commit ))
235220 return 0 ;
236221
237222 /* Don't add types the caller doesn't want */
@@ -401,7 +386,8 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
401386 qsort (ref_list .list , ref_list .index , sizeof (struct ref_item ), ref_cmp );
402387
403388 detached = (detached && (kinds & REF_LOCAL_BRANCH ));
404- if (detached && head_commit && has_commit (head_commit , with_commit )) {
389+ if (detached && head_commit &&
390+ is_descendant_of (head_commit , with_commit )) {
405391 struct ref_item item ;
406392 item .name = xstrdup ("(no branch)" );
407393 item .kind = REF_LOCAL_BRANCH ;
@@ -466,22 +452,6 @@ static void rename_branch(const char *oldname, const char *newname, int force)
466452 strbuf_release (& newsection );
467453}
468454
469- static int opt_parse_with_commit (const struct option * opt , const char * arg , int unset )
470- {
471- unsigned char sha1 [20 ];
472- struct commit * commit ;
473-
474- if (!arg )
475- return -1 ;
476- if (get_sha1 (arg , sha1 ))
477- die ("malformed object name %s" , arg );
478- commit = lookup_commit_reference (sha1 );
479- if (!commit )
480- die ("no such commit %s" , arg );
481- commit_list_insert (commit , opt -> value );
482- return 0 ;
483- }
484-
485455static int opt_parse_merge_filter (const struct option * opt , const char * arg , int unset )
486456{
487457 merge_filter = ((opt -> long_name [0 ] == 'n' )
@@ -517,13 +487,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
517487 OPTION_CALLBACK , 0 , "contains" , & with_commit , "commit" ,
518488 "print only branches that contain the commit" ,
519489 PARSE_OPT_LASTARG_DEFAULT ,
520- opt_parse_with_commit , (intptr_t )"HEAD" ,
490+ parse_opt_with_commit , (intptr_t )"HEAD" ,
521491 },
522492 {
523493 OPTION_CALLBACK , 0 , "with" , & with_commit , "commit" ,
524494 "print only branches that contain the commit" ,
525495 PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT ,
526- opt_parse_with_commit , (intptr_t ) "HEAD" ,
496+ parse_opt_with_commit , (intptr_t ) "HEAD" ,
527497 },
528498 OPT__ABBREV (& abbrev ),
529499
0 commit comments