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>

Michael Haggerty committed Apr 22, 2013 at 21:52 UTC 68cf87034402500f0c5dfb8d618b98b4e09895a7
1 file changed +24 -8
refs.c
+24 -8
@@ -1273,32 +1273,48 @@ static int filter_refs(const char *refname, const unsigned char *sha1, int flags
1273 return filter->fn(refname, sha1, flags, filter->cb_data);
1274 }
1275
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 +
1291 /*
1292 * 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.
1297 */
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)
1299 {
1300 struct object *o = lookup_unknown_object(name);
1301
1302 if (o->type == OBJ_NONE) {
1303 int type = sha1_object_info(name, NULL);
1304 if (type < 0)
1289 - return -1;
1305 + return PEEL_INVALID;
1306 o->type = type;
1307 }
1308
1309 if (o->type != OBJ_TAG)
1294 - return -1;
1310 + return PEEL_NON_TAG;
1311
1312 o = deref_tag_noverify(o);
1313 if (!o)
1298 - return -1;
1314 + return PEEL_INVALID;
1315
1316 hashcpy(sha1, o->sha1);
1301 - return 0;
1317 + return PEEL_PEELED;
1318 }
1319
1320 int peel_ref(const char *refname, unsigned char *sha1)