git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Han-Wen Nienhuys <hanwenn@gmail.com>,
	Han-Wen Nienhuys <hanwen@google.com>
Subject: [PATCH v2] refs: make explicit that ref_iterator_peel returns boolean
Date: Wed, 19 May 2021 15:31:28 +0000	[thread overview]
Message-ID: <pull.1006.v2.git.git.1621438289354.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1006.git.git.1618484566164.gitgitgadget@gmail.com>

From: Han-Wen Nienhuys <hanwen@google.com>

Use -1 as error return value throughout.

This removes spurious differences in the GIT_TRACE_REFS output, depending on the
ref storage backend active.

Before, the cached ref_iterator (but only that iterator!) would return
peel_object() output directly. No callers relied on the peel_status values
beyond success/failure. All calls to these functions go through
peel_iterated_oid(), which returns peel_object() as a fallback, but also
squashing the error values.

The iteration interface already passes REF_ISSYMREF and REF_ISBROKEN through the
flags argument, so the additional error values in enum peel_status provide no
value.

The ref iteration interface provides a separate peel() function because certain
formats (eg. packed-refs and reftable) can store the peeled object next to the
tag SHA1. Passing the peeled SHA1 as an optional argument to each_ref_fn maps
more naturally to the implementation of ref databases. Changing the code in this
way is left for a future refactoring.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
    refs: ref_iterator_peel returns boolean, rather than peel_status
    
    v2: expand commit message.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1006%2Fhanwen%2Fpeel_return-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1006/hanwen/peel_return-v2
Pull-Request: https://github.com/git/git/pull/1006

Range-diff vs v1:

 1:  241e0ad1954b ! 1:  f1dc6c2d7fea refs: ref_iterator_peel returns boolean, rather than peel_status
     @@ Metadata
      Author: Han-Wen Nienhuys <hanwen@google.com>
      
       ## Commit message ##
     -    refs: ref_iterator_peel returns boolean, rather than peel_status
     +    refs: make explicit that ref_iterator_peel returns boolean
      
     -    Before, the cached ref_iterator would return peel_object() output directly. This
     -    led to spurious differences in the GIT_TRACE_REFS output, depending on the ref
     -    storage backend active.
     +    Use -1 as error return value throughout.
     +
     +    This removes spurious differences in the GIT_TRACE_REFS output, depending on the
     +    ref storage backend active.
     +
     +    Before, the cached ref_iterator (but only that iterator!) would return
     +    peel_object() output directly. No callers relied on the peel_status values
     +    beyond success/failure. All calls to these functions go through
     +    peel_iterated_oid(), which returns peel_object() as a fallback, but also
     +    squashing the error values.
     +
     +    The iteration interface already passes REF_ISSYMREF and REF_ISBROKEN through the
     +    flags argument, so the additional error values in enum peel_status provide no
     +    value.
     +
     +    The ref iteration interface provides a separate peel() function because certain
     +    formats (eg. packed-refs and reftable) can store the peeled object next to the
     +    tag SHA1. Passing the peeled SHA1 as an optional argument to each_ref_fn maps
     +    more naturally to the implementation of ref databases. Changing the code in this
     +    way is left for a future refactoring.
      
          Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
      
     @@ refs.c: int peel_iterated_oid(const struct object_id *base, struct object_id *pe
       		return ref_iterator_peel(current_ref_iter, peeled);
       
      -	return peel_object(base, peeled);
     -+	return !!peel_object(base, peeled);
     ++	return peel_object(base, peeled) ? -1 : 0;
       }
       
       int refs_create_symref(struct ref_store *refs,
      
     + ## refs/packed-backend.c ##
     +@@ refs/packed-backend.c: static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
     + 	} else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) {
     + 		return -1;
     + 	} else {
     +-		return !!peel_object(&iter->oid, peeled);
     ++		return peel_object(&iter->oid, peeled) ? -1 : 0;
     + 	}
     + }
     + 
     +
       ## refs/ref-cache.c ##
      @@ refs/ref-cache.c: static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
       static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
       				   struct object_id *peeled)
       {
      -	return peel_object(ref_iterator->oid, peeled);
     -+	return !!peel_object(ref_iterator->oid, peeled);
     ++	return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
       }
       
       static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
     @@ refs/refs-internal.h: void base_ref_iterator_free(struct ref_iterator *iter);
       typedef int ref_iterator_advance_fn(struct ref_iterator *ref_iterator);
       
      +/*
     -+ * Peels the current ref, returning 0 for success.
     ++ * Peels the current ref, returning 0 for success or -1 for failure.
      + */
       typedef int ref_iterator_peel_fn(struct ref_iterator *ref_iterator,
       				 struct object_id *peeled);


 refs.c                | 2 +-
 refs/packed-backend.c | 2 +-
 refs/ref-cache.c      | 2 +-
 refs/refs-internal.h  | 3 +++
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 8c9490235ea6..8b9f7c3a80a0 100644
--- a/refs.c
+++ b/refs.c
@@ -2010,7 +2010,7 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
 	     oideq(current_ref_iter->oid, base)))
 		return ref_iterator_peel(current_ref_iter, peeled);
 
-	return peel_object(base, peeled);
+	return peel_object(base, peeled) ? -1 : 0;
 }
 
 int refs_create_symref(struct ref_store *refs,
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index dfecdbc1db60..66cb90c79ee0 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -889,7 +889,7 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
 	} else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) {
 		return -1;
 	} else {
-		return !!peel_object(&iter->oid, peeled);
+		return peel_object(&iter->oid, peeled) ? -1 : 0;
 	}
 }
 
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index 46f1e5428433..49d732f6db96 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -491,7 +491,7 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
 static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
 				   struct object_id *peeled)
 {
-	return peel_object(ref_iterator->oid, peeled);
+	return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
 }
 
 static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 467f4b3c936d..3155708345fc 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -453,6 +453,9 @@ void base_ref_iterator_free(struct ref_iterator *iter);
  */
 typedef int ref_iterator_advance_fn(struct ref_iterator *ref_iterator);
 
+/*
+ * Peels the current ref, returning 0 for success or -1 for failure.
+ */
 typedef int ref_iterator_peel_fn(struct ref_iterator *ref_iterator,
 				 struct object_id *peeled);
 

base-commit: bf949ade81106fbda068c1fdb2c6fd1cb1babe7e
-- 
gitgitgadget

  reply	other threads:[~2021-05-19 15:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 11:02 [PATCH] refs: ref_iterator_peel returns boolean, rather than peel_status Han-Wen Nienhuys via GitGitGadget
2021-05-19 15:31 ` Han-Wen Nienhuys via GitGitGadget [this message]
2021-05-19 22:58   ` [PATCH v2] refs: make explicit that ref_iterator_peel returns boolean Junio C Hamano
2021-05-20  9:04     ` Han-Wen Nienhuys
2021-07-06 18:09       ` Han-Wen Nienhuys
2021-07-06 19:54         ` Junio C Hamano

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=pull.1006.v2.git.git.1621438289354.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hanwen@google.com \
    --cc=hanwenn@gmail.com \
    --subject='Re: [PATCH v2] refs: make explicit that ref_iterator_peel returns boolean' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).