From: David Turner <dtur...@twopensource.com>

This function does not contain any backend specific code so move it to
the common code.

Signed-off-by: David Turner <dtur...@twopensource.com>
Signed-off-by: Junio C Hamano <gits...@pobox.com>
Signed-off-by: Michael Haggerty <mhag...@alum.mit.edu>
---
 refs/files-backend.c | 53 ----------------------------------------------------
 refs/refs-internal.h | 34 +++++++++++++++++++++++++++++++++
 refs/refs.c          | 23 +++++++++++++++++++++++
 3 files changed, 57 insertions(+), 53 deletions(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4807b32..2073004 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1612,59 +1612,6 @@ const char *resolve_ref_unsafe(const char *refname, int 
resolve_flags,
        return ret;
 }
 
-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,
-
-       /* ref_entry contains no peeled value because it is a symref: */
-       PEEL_IS_SYMREF = -3,
-
-       /*
-        * ref_entry cannot be peeled because it is broken (i.e., the
-        * symbolic reference cannot even be resolved to an object
-        * name):
-        */
-       PEEL_BROKEN = -4
-};
-
-/*
- * Peel the named object; i.e., if the object is a tag, resolve the
- * 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 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 || !object_as_type(o, type, 0))
-                       return PEEL_INVALID;
-       }
-
-       if (o->type != OBJ_TAG)
-               return PEEL_NON_TAG;
-
-       o = deref_tag_noverify(o);
-       if (!o)
-               return PEEL_INVALID;
-
-       hashcpy(sha1, o->sha1);
-       return PEEL_PEELED;
-}
-
 /*
  * Peel the entry (if possible) and return its new peel_status.  If
  * repeel is true, re-peel the entry even if there is an old peeled
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index a1655e3..5b4176e 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -59,6 +59,40 @@ int refname_is_safe(const char *refname);
  * value to ref_update::flags
  */
 
+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,
+
+       /* ref_entry contains no peeled value because it is a symref: */
+       PEEL_IS_SYMREF = -3,
+
+       /*
+        * ref_entry cannot be peeled because it is broken (i.e., the
+        * symbolic reference cannot even be resolved to an object
+        * name):
+        */
+       PEEL_BROKEN = -4
+};
+
+/*
+ * Peel the named object; i.e., if the object is a tag, resolve the
+ * 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.
+ */
+enum peel_status peel_object(const unsigned char *name, unsigned char *sha1);
+
 /**
  * Information needed for a single ref update. Set new_sha1 to the new
  * value or to null_sha1 to delete the ref. To check the old value
diff --git a/refs/refs.c b/refs/refs.c
index 6bf790b..5d95804 100644
--- a/refs/refs.c
+++ b/refs/refs.c
@@ -4,6 +4,8 @@
 #include "../cache.h"
 #include "refs-internal.h"
 #include "../lockfile.h"
+#include "../object.h"
+#include "../tag.h"
 
 static int is_per_worktree_ref(const char *refname)
 {
@@ -994,3 +996,24 @@ int refname_is_safe(const char *refname)
        }
        return 1;
 }
+
+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 || !object_as_type(o, type, 0))
+                       return PEEL_INVALID;
+       }
+
+       if (o->type != OBJ_TAG)
+               return PEEL_NON_TAG;
+
+       o = deref_tag_noverify(o);
+       if (!o)
+               return PEEL_INVALID;
+
+       hashcpy(sha1, o->sha1);
+       return PEEL_PEELED;
+}
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to