]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: make explicit that ref_iterator_peel returns boolean
authorHan-Wen Nienhuys <hanwen@google.com>
Wed, 19 May 2021 15:31:28 +0000 (15:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 May 2021 22:54:12 +0000 (07:54 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs/packed-backend.c
refs/ref-cache.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 261fd82beb98fdfcfc641fa7605d37b86aac2184..87cc64d5629925e3aede61a8b64cac6d8333e48e 100644 (file)
--- 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,
index dfecdbc1db6074aeafb995440fa22901b4997331..66cb90c79ee058f956912857968a4fb765243c7e 100644 (file)
@@ -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;
        }
 }
 
index 46f1e54284339dfce975f9820151c020327b85b7..49d732f6db961c8daa1f0ff0f4589059420f636c 100644 (file)
@@ -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)
index 467f4b3c936df2e65134371c800ea118e03ecd31..3155708345fcbccdd02f69dd4b155f9b6fd1d098 100644 (file)
@@ -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);