Skip to content

Commit 2312a79

Browse files
mhaggergitster
authored andcommitted
peel_ref(): fix return value for non-peelable, not-current reference
The old version was inconsistent: when a reference was REF_KNOWS_PEELED but with a null peeled value, it returned non-zero for the current reference but zero for other references. Change the behavior for non-current references to match that of current_ref, which is what callers expect. Document the behavior. Current callers only call peel_ref() from within a for_each_ref-style iteration and only for the current ref; therefore, the buggy code path was never reached. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68cf870 commit 2312a79

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

refs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ struct ref_value {
119119
/*
120120
* If REF_KNOWS_PEELED, then this field holds the peeled value
121121
* of this reference, or null if the reference is known not to
122-
* be peelable.
122+
* be peelable. See the documentation for peel_ref() for an
123+
* exact definition of "peelable".
123124
*/
124125
unsigned char peeled[20];
125126
};
@@ -1340,6 +1341,8 @@ int peel_ref(const char *refname, unsigned char *sha1)
13401341
struct ref_entry *r = get_packed_ref(refname);
13411342

13421343
if (r && (r->flag & REF_KNOWS_PEELED)) {
1344+
if (is_null_sha1(r->u.value.peeled))
1345+
return -1;
13431346
hashcpy(sha1, r->u.value.peeled);
13441347
return 0;
13451348
}

refs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ extern void add_packed_ref(const char *refname, const unsigned char *sha1);
7474

7575
extern int ref_exists(const char *);
7676

77+
/*
78+
* If refname is a non-symbolic reference that refers to a tag object,
79+
* and the tag can be (recursively) dereferenced to a non-tag object,
80+
* store the SHA1 of the referred-to object to sha1 and return 0. If
81+
* any of these conditions are not met, return a non-zero value.
82+
* Symbolic references are considered unpeelable, even if they
83+
* ultimately resolve to a peelable tag.
84+
*/
7785
extern int peel_ref(const char *refname, unsigned char *sha1);
7886

7987
/** Locks a "refs/" ref returning the lock on success and NULL on failure. **/

0 commit comments

Comments
 (0)