All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	Michael Haggerty <mhagger@alum.mit.edu>,
	Junio C Hamano <gitster@pobox.com>,
	"Kyle J. McKay" <mackyle@gmail.com>,
	Ronnie Sahlberg <sahlberg@google.com>
Subject: Re: [PATCH v2 02/16] refs: convert for_each_tag_ref to struct object_id
Date: Thu, 23 Apr 2015 15:27:23 -0400	[thread overview]
Message-ID: <20150423192723.GA29220@peff.net> (raw)
In-Reply-To: <CAGZ79kas9QgJy1ooCjHPR+ZGGuTdMhTxO9zSMxnGpPk8rG5_xQ@mail.gmail.com>

On Thu, Apr 23, 2015 at 11:13:32AM -0700, Stefan Beller wrote:

> On Wed, Apr 22, 2015 at 4:24 PM, brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > To allow piecemeal conversion of the for_each_*_ref functions, introduce
> > an additional typedef for a callback function that takes struct
> > object_id * instead of unsigned char *.  Provide an extra field in
> > struct ref_entry_cb for this callback and ensure at most one is set at a
> > time.  Temporarily suffix these new entries with _oid to distinguish
> > them.  Convert for_each_tag_ref and its callers to use the new _oid
> > functions, introducing temporary wrapper functions to avoid type
> > mismatches.
> >
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> 
> I am currently running this patch series via
> git rebase -i origin/next --exec=make --exec="make test"
> through the compilation and test suite one by one.
> (My current view of origin/next is (c8da2d582, Sync with 2.4.0-rc3)
> and this commit fails in t5312-prune-corruption.sh test 3 5 and 8

It's because of this hunk:

> > @@ -1950,6 +1956,21 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,
> >         data.trim = trim;
> >         data.flags = flags;
> >         data.fn = fn;
> > +       data.fn_oid = NULL;
> > +       data.cb_data = cb_data;
> > +
> > +       return do_for_each_entry(refs, base, do_one_ref, &data);
> > +}
> > +
> > +static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,
> > +                          each_ref_fn_oid fn, int trim, int flags, void *cb_data)
> > +{
> > +       struct ref_entry_cb data;
> > +       data.base = base;
> > +       data.trim = trim;
> > +       data.flags = flags;
> > +       data.fn = NULL;
> > +       data.fn_oid = fn;
> >         data.cb_data = cb_data;
> >
> >         if (ref_paranoia < 0)

The ref_paranoia code gets pushed down into do_for_each_ref_oid, but it
needs called in both do_for_each_ref variants. This is probably an
artifact of rebasing the patches (the ref_paranoia stuff was added
recently).

I think it would make sense to pull the setup of the data struct into a
shared function rather than duplicate it. But we want to avoid having to
update do_for_each_ref callsites, so we'll have to provide a wrapper.

Like this:

diff --git a/refs.c b/refs.c
index 95863f2..ad39d74 100644
--- a/refs.c
+++ b/refs.c
@@ -1948,29 +1948,16 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,
  * value, stop the iteration and return that value; otherwise, return
  * 0.
  */
-static int do_for_each_ref(struct ref_cache *refs, const char *base,
-			   each_ref_fn fn, int trim, int flags, void *cb_data)
+static int do_for_each_ref_generic(struct ref_cache *refs, const char *base,
+				   each_ref_fn fn, each_ref_fn_oid fn_oid,
+				   int trim, int flags, void *cb_data)
 {
 	struct ref_entry_cb data;
 	data.base = base;
 	data.trim = trim;
 	data.flags = flags;
 	data.fn = fn;
-	data.fn_oid = NULL;
-	data.cb_data = cb_data;
-
-	return do_for_each_entry(refs, base, do_one_ref, &data);
-}
-
-static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,
-			   each_ref_fn_oid fn, int trim, int flags, void *cb_data)
-{
-	struct ref_entry_cb data;
-	data.base = base;
-	data.trim = trim;
-	data.flags = flags;
-	data.fn = NULL;
-	data.fn_oid = fn;
+	data.fn_oid = fn_oid;
 	data.cb_data = cb_data;
 
 	if (ref_paranoia < 0)
@@ -1981,6 +1968,18 @@ static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,
 	return do_for_each_entry(refs, base, do_one_ref, &data);
 }
 
+static int do_for_each_ref(struct ref_cache *refs, const char *base,
+			   each_ref_fn fn, int trim, int flags, void *cb_data)
+{
+	return do_for_each_ref_generic(refs, base, fn, NULL, trim, flags, cb_data);
+}
+
+static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,
+			       each_ref_fn_oid fn, int trim, int flags, void *cb_data)
+{
+	return do_for_each_ref_generic(refs, base, NULL, fn, trim, flags, cb_data);
+}
+
 static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
 {
 	unsigned char sha1[20];

You can even dispense with the _oid variant wrapper, and just call into
the generic version directly from the new callsites.

-Peff

  reply	other threads:[~2015-04-23 19:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22 23:24 [PATCH v2 00/16] Convert parts of refs.c to struct object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 01/16] refs: convert struct ref_entry to use " brian m. carlson
2015-04-23  0:52   ` Stefan Beller
2015-04-24 22:36     ` brian m. carlson
2015-04-22 23:24 ` [PATCH v2 02/16] refs: convert for_each_tag_ref to " brian m. carlson
2015-04-23 18:13   ` Stefan Beller
2015-04-23 19:27     ` Jeff King [this message]
2015-04-24 22:37       ` brian m. carlson
2015-04-22 23:24 ` [PATCH v2 03/16] refs: convert remaining users of for_each_ref_in to object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 04/16] refs: convert for_each_ref_in_submodule " brian m. carlson
2015-04-22 23:24 ` [PATCH v2 05/16] refs: convert head_ref to struct object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 06/16] refs: convert for_each_ref_submodule " brian m. carlson
2015-04-22 23:24 ` [PATCH v2 07/16] revision: remove unused _oid helper brian m. carlson
2015-04-22 23:24 ` [PATCH v2 08/16] refs: convert for_each_ref to struct object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 09/16] refs: convert for_each_replace_ref " brian m. carlson
2015-04-22 23:24 ` [PATCH v2 10/16] refs: convert namespaced ref iteration functions to object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 11/16] refs: convert for_each_rawref to struct object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 12/16] refs: rename do_for_each_ref_oid to do_for_each_ref brian m. carlson
2015-04-22 23:24 ` [PATCH v2 13/16] refs: convert for_each_reflog to struct object_id brian m. carlson
2015-04-22 23:24 ` [PATCH v2 14/16] refs: rename each_ref_fn_oid to each_ref_fn brian m. carlson
2015-04-22 23:24 ` [PATCH v2 15/16] Remove unneeded *_oid functions brian m. carlson
2015-04-22 23:24 ` [PATCH v2 16/16] refs: convert struct ref_lock to struct object_id brian m. carlson
2015-04-26 20:26 ` [PATCH v2 00/16] Convert parts of refs.c " Michael Haggerty
2015-05-03 21:45   ` brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150423192723.GA29220@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mackyle@gmail.com \
    --cc=mhagger@alum.mit.edu \
    --cc=sahlberg@google.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.