+/*
+ * 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.
+ */
+static int 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;
+ o->type = type;
+ }
+
+ if (o->type != OBJ_TAG)
+ return -1;
+
+ o = deref_tag_noverify(o);
+ if (!o)
+ return -1;
+
+ hashcpy(sha1, o->sha1);
+ return 0;
+}
+