This function does not contain any backend specific code so we move it to the common code. Signed-off-by: Ronnie Sahlberg <sahlberg@xxxxxxxxxx> Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx> --- refs-be-files.c | 33 --------------------------------- refs.c | 23 +++++++++++++++++++++++ refs.h | 2 ++ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/refs-be-files.c b/refs-be-files.c index dc89289..bb5a3ad 100644 --- a/refs-be-files.c +++ b/refs-be-files.c @@ -231,39 +231,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 c6112ac..aa49db5 100644 --- a/refs.c +++ b/refs.c @@ -901,6 +901,29 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data) return ret; } +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; +} /* backend functions */ struct ref_transaction *ref_transaction_begin(struct strbuf *err) diff --git a/refs.h b/refs.h index 09d140d..2bafa55 100644 --- a/refs.h +++ b/refs.h @@ -326,6 +326,8 @@ extern int for_each_reflog(each_ref_fn, void *); */ extern int check_refname_format(const char *refname, int flags); +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.644.g97b850b-twtrsrc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html