Skip to content

Commit 617480d

Browse files
hanwengitster
authored andcommitted
refs: make explicit that ref_iterator_peel returns boolean
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0c09ab commit 617480d

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
20102010
oideq(current_ref_iter->oid, base)))
20112011
return ref_iterator_peel(current_ref_iter, peeled);
20122012

2013-
return peel_object(base, peeled);
2013+
return peel_object(base, peeled) ? -1 : 0;
20142014
}
20152015

20162016
int refs_create_symref(struct ref_store *refs,

refs/packed-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
889889
} else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) {
890890
return -1;
891891
} else {
892-
return !!peel_object(&iter->oid, peeled);
892+
return peel_object(&iter->oid, peeled) ? -1 : 0;
893893
}
894894
}
895895

refs/ref-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
491491
static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator,
492492
struct object_id *peeled)
493493
{
494-
return peel_object(ref_iterator->oid, peeled);
494+
return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
495495
}
496496

497497
static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)

refs/refs-internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ void base_ref_iterator_free(struct ref_iterator *iter);
453453
*/
454454
typedef int ref_iterator_advance_fn(struct ref_iterator *ref_iterator);
455455

456+
/*
457+
* Peels the current ref, returning 0 for success or -1 for failure.
458+
*/
456459
typedef int ref_iterator_peel_fn(struct ref_iterator *ref_iterator,
457460
struct object_id *peeled);
458461

0 commit comments

Comments
 (0)