Subject: Re: [PATCH 4/4] builtin/remote: only iterate through refs that are to be renamed

From: Patrick Steinhardt <[email-masked]>
Date: Thu, 31 Jul 2025 10:28:39 +0200

On Wed, Jul 30, 2025 at 09:53:13AM +0200, Karthik Nayak wrote:
> Patrick Steinhardt <[email-masked]> writes:
> 
> [snip]
> 
> > diff --git a/refs.c b/refs.c
> > index b820c3908bd..861a0deb924 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -1840,7 +1840,13 @@ int refs_for_each_namespaced_ref(struct ref_store *refs,
> >
> >  int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
> >  {
> > -	return do_for_each_ref(refs, "", NULL, fn, 0,
> > +	return refs_for_each_rawref_in(refs, "", fn, cb_data);
> > +}
> > +
> > +int refs_for_each_rawref_in(struct ref_store *refs, const char *prefix,
> > +			    each_ref_fn fn, void *cb_data)
> > +{
> > +	return do_for_each_ref(refs, prefix, NULL, fn, 0,
> >  			       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
> >  }
> >
> > diff --git a/refs.h b/refs.h
> > index a39f873b1fe..9decd3126e3 100644
> > --- a/refs.h
> > +++ b/refs.h
> > @@ -428,6 +428,8 @@ int refs_for_each_namespaced_ref(struct ref_store *refs,
> >
> >  /* can be used to learn about broken ref and symref */
> >  int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data);
> > +int refs_for_each_rawref_in(struct ref_store *refs, const char *prefix,
> > +			    each_ref_fn fn, void *cb_data);
> >
> >  /*
> >   * Iterates over all refs including root refs, i.e. pseudorefs and HEAD.
> >
> > --
> > 2.50.1.565.gc32cd1483b.dirty
> 
> Nit: we do expose the reference iterators now with
> 'kn/for-each-ref-skip' (merged to next). We could directly use the
> iterator instead of introducting a specific function like this.

I'll leave this as-is for now. The additional wrapper isn't all that
bad, and I'd rather want to avoid adding another dependency to this
patch series.

Patrick