This function does not contain any backend specific code so we move it
to the common code. This function might be used by other refs backends.

While we are doing so, we improve the comment's grammar and clarify a
safety rule.

Signed-off-by: Ronnie Sahlberg <sahlb...@google.com>
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-be-files.c | 33 ---------------------------------
 refs.c          | 24 ++++++++++++++++++++++++
 refs.h          | 11 +++++++++++
 3 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/refs-be-files.c b/refs-be-files.c
index 156ab4f..0111282 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -196,39 +196,6 @@ static struct ref_dir *get_ref_dir(struct ref_entry *entry)
        return dir;
 }
 
-/*
- * Check if a refname is safe.
- * For refs that start with "refs/" we consider it safe as long they do
- * not try to resolve to outside of refs/.
- *
- * For all other refs we only consider them safe iff they only contain
- * upper case characters and '_' (like "HEAD" AND "MERGE_HEAD", and not like
- * "config").
- */
-static int refname_is_safe(const char *refname)
-{
-       if (starts_with(refname, "refs/")) {
-               char *buf;
-               int result;
-
-               buf = xmalloc(strlen(refname) + 1);
-               /*
-                * Does the refname try to escape refs/?
-                * For example: refs/foo/../bar is safe but refs/foo/../../bar
-                * is not.
-                */
-               result = !normalize_path_copy(buf, refname + strlen("refs/"));
-               free(buf);
-               return result;
-       }
-       while (*refname) {
-               if (!isupper(*refname) && *refname != '_')
-                       return 0;
-               refname++;
-       }
-       return 1;
-}
-
 static struct ref_entry *create_ref_entry(const char *refname,
                                          const unsigned char *sha1, int flag,
                                          int check_name)
diff --git a/refs.c b/refs.c
index 9cafcc9..cd0ab21 100644
--- a/refs.c
+++ b/refs.c
@@ -949,3 +949,27 @@ int ref_transaction_verify(struct ref_transaction 
*transaction,
                                      NULL, old_sha1,
                                      flags, NULL, err);
 }
+
+int refname_is_safe(const char *refname)
+{
+       if (starts_with(refname, "refs/")) {
+               char *buf;
+               int result;
+
+               buf = xmalloc(strlen(refname) + 1);
+               /*
+                * Does the refname try to escape refs/?
+                * For example: refs/foo/../bar is safe but refs/foo/../../bar
+                * is not.
+                */
+               result = !normalize_path_copy(buf, refname + strlen("refs/"));
+               free(buf);
+               return result;
+       }
+       while (*refname) {
+               if (!isupper(*refname) && *refname != '_')
+                       return 0;
+               refname++;
+       }
+       return 1;
+}
diff --git a/refs.h b/refs.h
index 3d24c79..927b64d 100644
--- a/refs.h
+++ b/refs.h
@@ -396,6 +396,17 @@ extern int for_each_reflog(each_ref_fn, void *);
  */
 extern int check_refname_format(const char *refname, int flags);
 
+/*
+ * Check if a refname is safe.
+ * For a ref that starts with "refs/", we consider it safe as long it does
+ * not try to resolve to outside of refs/.
+ *
+ * For all other refs we only consider them safe iff they only consist of
+ * upper case characters and '_' (like "HEAD" AND "MERGE_HEAD", and not like
+ * "config").
+ */
+extern int refname_is_safe(const char *refname);
+
 extern const char *prettify_refname(const char *refname);
 
 extern char *shorten_unambiguous_ref(const char *refname, int strict);
-- 
2.4.2.658.g6d8523e-twtrsrc

--
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