diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2011-09-15 23:10:25 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-10-05 13:45:29 -0700 |
commit | 8d9c50105f908b2adde4b7c77537cf95f19cd893 (patch) | |
tree | 91e783b9cca8d2bac7913057b9caf28c948822e1 /builtin | |
parent | Change bad_ref_char() to return a boolean value (diff) | |
download | tgif-8d9c50105f908b2adde4b7c77537cf95f19cd893.tar.xz |
Change check_ref_format() to take a flags argument
Change check_ref_format() to take a flags argument that indicates what
is acceptable in the reference name (analogous to "git
check-ref-format"'s "--allow-onelevel" and "--refspec-pattern"). This
is more convenient for callers and also fixes a failure in the test
suite (and likely elsewhere in the code) by enabling "onelevel" and
"refspec-pattern" to be allowed independently of each other.
Also rename check_ref_format() to check_refname_format() to make it
obvious that it deals with refnames rather than references themselves.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/check-ref-format.c | 21 | ||||
-rw-r--r-- | builtin/checkout.c | 2 | ||||
-rw-r--r-- | builtin/fetch-pack.c | 2 | ||||
-rw-r--r-- | builtin/receive-pack.c | 2 | ||||
-rw-r--r-- | builtin/replace.c | 2 | ||||
-rw-r--r-- | builtin/show-ref.c | 2 | ||||
-rw-r--r-- | builtin/tag.c | 4 |
7 files changed, 8 insertions, 27 deletions
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index 72959547b3..8f416967af 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -53,9 +53,6 @@ static void refname_format_print(const char *arg) printf("%s\n", refname); } -#define REFNAME_ALLOW_ONELEVEL 1 -#define REFNAME_REFSPEC_PATTERN 2 - int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { int i; @@ -83,24 +80,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix) if (! (i == argc - 1)) usage(builtin_check_ref_format_usage); - switch (check_ref_format(argv[i])) { - case CHECK_REF_FORMAT_OK: - break; - case CHECK_REF_FORMAT_ERROR: + if (check_refname_format(argv[i], flags)) return 1; - case CHECK_REF_FORMAT_ONELEVEL: - if (!(flags & REFNAME_ALLOW_ONELEVEL)) - return 1; - else - break; - case CHECK_REF_FORMAT_WILDCARD: - if (!(flags & REFNAME_REFSPEC_PATTERN)) - return 1; - else - break; - default: - die("internal error: unexpected value from check_ref_format()"); - } if (print) refname_format_print(argv[i]); diff --git a/builtin/checkout.c b/builtin/checkout.c index 3bb652591b..574d2b6181 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -882,7 +882,7 @@ static int parse_branchname_arg(int argc, const char **argv, new->name = arg; setup_branch_path(new); - if (check_ref_format(new->path) == CHECK_REF_FORMAT_OK && + if (!check_refname_format(new->path, 0) && resolve_ref(new->path, branch_rev, 1, NULL)) hashcpy(rev, branch_rev); else diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 412bd327b5..b51e47837e 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -544,7 +544,7 @@ static void filter_refs(struct ref **refs, int nr_match, char **match) for (ref = *refs; ref; ref = next) { next = ref->next; if (!memcmp(ref->name, "refs/", 5) && - check_ref_format(ref->name + 5)) + check_refname_format(ref->name + 5, 0)) ; /* trash */ else if (args.fetch_all && (!args.depth || prefixcmp(ref->name, "refs/tags/") )) { diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index ae164da4d5..0600efacd1 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -356,7 +356,7 @@ static const char *update(struct command *cmd) struct ref_lock *lock; /* only refs/... are allowed */ - if (prefixcmp(name, "refs/") || check_ref_format(name + 5)) { + if (prefixcmp(name, "refs/") || check_refname_format(name + 5, 0)) { rp_error("refusing to create funny ref '%s' remotely", name); return "funny refname"; } diff --git a/builtin/replace.c b/builtin/replace.c index fe3a647a36..517fa1031a 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -94,7 +94,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, "refs/replace/%s", sha1_to_hex(object)) > sizeof(ref) - 1) die("replace ref name too long: %.*s...", 50, ref); - if (check_ref_format(ref)) + if (check_refname_format(ref, 0)) die("'%s' is not a valid ref name.", ref); if (!resolve_ref(ref, prev, 1, NULL)) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 45f0340c3e..fafb6dd500 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -145,7 +145,7 @@ static int exclude_existing(const char *match) if (strncmp(ref, match, matchlen)) continue; } - if (check_ref_format(ref)) { + if (check_refname_format(ref, 0)) { warning("ref '%s' ignored", ref); continue; } diff --git a/builtin/tag.c b/builtin/tag.c index 667515e527..48be745678 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -407,12 +407,12 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset) static int strbuf_check_tag_ref(struct strbuf *sb, const char *name) { if (name[0] == '-') - return CHECK_REF_FORMAT_ERROR; + return -1; strbuf_reset(sb); strbuf_addf(sb, "refs/tags/%s", name); - return check_ref_format(sb->buf); + return check_refname_format(sb->buf, 0); } int cmd_tag(int argc, const char **argv, const char *prefix) |