summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Michael Haggerty <mhagger@alum.mit.edu>2013-04-22 21:52:20 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-05-01 15:33:10 -0700
commit68cf87034402500f0c5dfb8d618b98b4e09895a7 (patch)
tree84ea87a8f38b9be0d5b00d12a20a04fc059ef968
parentrefs: extract function peel_object() (diff)
downloadtgif-68cf87034402500f0c5dfb8d618b98b4e09895a7.tar.xz
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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/refs.c b/refs.c
index 9cd5582d38..7405d1c962 100644
--- a/refs.c
+++ b/refs.c
@@ -1273,32 +1273,48 @@ static int filter_refs(const char *refname, const unsigned char *sha1, int flags
return filter->fn(refname, sha1, flags, filter->cb_data);
}
+enum peel_status {
+ /* object was peeled successfully: */
+ PEEL_PEELED = 0,
+
+ /*
+ * object cannot be peeled because the named object (or an
+ * object referred to by a tag in the peel chain), does not
+ * exist.
+ */
+ PEEL_INVALID = -1,
+
+ /* object cannot be peeled because it is not a tag: */
+ PEEL_NON_TAG = -2
+};
+
/*
* Peel the named object; i.e., if the object is a tag, resolve the
- * tag recursively until a non-tag is found. Store the result to sha1
- * and return 0 iff successful. If the object is not a tag or is not
- * valid, return -1 and leave sha1 unchanged.
+ * tag recursively until a non-tag is found. If successful, store the
+ * result to sha1 and return PEEL_PEELED. If the object is not a tag
+ * or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
+ * and leave sha1 unchanged.
*/
-static int peel_object(const unsigned char *name, unsigned char *sha1)
+static enum peel_status peel_object(const unsigned char *name, unsigned char *sha1)
{
struct object *o = lookup_unknown_object(name);
if (o->type == OBJ_NONE) {
int type = sha1_object_info(name, NULL);
if (type < 0)
- return -1;
+ return PEEL_INVALID;
o->type = type;
}
if (o->type != OBJ_TAG)
- return -1;
+ return PEEL_NON_TAG;
o = deref_tag_noverify(o);
if (!o)
- return -1;
+ return PEEL_INVALID;
hashcpy(sha1, o->sha1);
- return 0;
+ return PEEL_PEELED;
}
int peel_ref(const char *refname, unsigned char *sha1)