Skip to content

Commit 68cf870

Browse files
mhaggergitster
authored andcommitted
peel_object(): give more specific information in return value
Instead of just returning a success/failure bit, return an enumeration value that explains the reason for any failure. This will come in handy shortly. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb2ae1c commit 68cf870

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

refs.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,32 +1273,48 @@ static int filter_refs(const char *refname, const unsigned char *sha1, int flags
12731273
return filter->fn(refname, sha1, flags, filter->cb_data);
12741274
}
12751275

1276+
enum peel_status {
1277+
/* object was peeled successfully: */
1278+
PEEL_PEELED = 0,
1279+
1280+
/*
1281+
* object cannot be peeled because the named object (or an
1282+
* object referred to by a tag in the peel chain), does not
1283+
* exist.
1284+
*/
1285+
PEEL_INVALID = -1,
1286+
1287+
/* object cannot be peeled because it is not a tag: */
1288+
PEEL_NON_TAG = -2
1289+
};
1290+
12761291
/*
12771292
* Peel the named object; i.e., if the object is a tag, resolve the
1278-
* tag recursively until a non-tag is found. Store the result to sha1
1279-
* and return 0 iff successful. If the object is not a tag or is not
1280-
* valid, return -1 and leave sha1 unchanged.
1293+
* tag recursively until a non-tag is found. If successful, store the
1294+
* result to sha1 and return PEEL_PEELED. If the object is not a tag
1295+
* or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
1296+
* and leave sha1 unchanged.
12811297
*/
1282-
static int peel_object(const unsigned char *name, unsigned char *sha1)
1298+
static enum peel_status peel_object(const unsigned char *name, unsigned char *sha1)
12831299
{
12841300
struct object *o = lookup_unknown_object(name);
12851301

12861302
if (o->type == OBJ_NONE) {
12871303
int type = sha1_object_info(name, NULL);
12881304
if (type < 0)
1289-
return -1;
1305+
return PEEL_INVALID;
12901306
o->type = type;
12911307
}
12921308

12931309
if (o->type != OBJ_TAG)
1294-
return -1;
1310+
return PEEL_NON_TAG;
12951311

12961312
o = deref_tag_noverify(o);
12971313
if (!o)
1298-
return -1;
1314+
return PEEL_INVALID;
12991315

13001316
hashcpy(sha1, o->sha1);
1301-
return 0;
1317+
return PEEL_PEELED;
13021318
}
13031319

13041320
int peel_ref(const char *refname, unsigned char *sha1)

0 commit comments

Comments
 (0)