aboutsummaryrefslogtreecommitdiff
path: root/builtin/check-ref-format.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2011-09-15 23:10:30 +0200
committerJunio C Hamano <gitster@pobox.com>2011-10-05 13:45:30 -0700
commita40e6fb67a4aed2d5ffde5792bf7f1996d9666e1 (patch)
tree25301632521d5e44177d076b255746679755ba92 /builtin/check-ref-format.c
parenta5e4ec063afea050d09773f0aa5dcb95a82a31ec (diff)
downloadgit-a40e6fb67a4aed2d5ffde5792bf7f1996d9666e1.tar.gz
git-a40e6fb67a4aed2d5ffde5792bf7f1996d9666e1.tar.xz
Change check_refname_format() to reject unnormalized refnames
Since much of the infrastructure does not work correctly with unnormalized refnames, change check_refname_format() to reject them. Similarly, change "git check-ref-format" to reject unnormalized refnames by default. But add an option --normalize, which causes "git check-ref-format" to normalize the refname before checking its format, and print the normalized refname. This is exactly the behavior of the old --print option, which is retained but deprecated. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/check-ref-format.c')
-rw-r--r--builtin/check-ref-format.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index f5df9aad7..28a732027 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -8,7 +8,7 @@
#include "strbuf.h"
static const char builtin_check_ref_format_usage[] =
-"git check-ref-format [--print] [options] <refname>\n"
+"git check-ref-format [--normalize] [options] <refname>\n"
" or: git check-ref-format --branch <branchname-shorthand>";
/*
@@ -51,7 +51,7 @@ static int check_ref_format_branch(const char *arg)
int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
{
int i;
- int print = 0;
+ int normalize = 0;
int flags = 0;
const char *refname;
@@ -62,8 +62,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
return check_ref_format_branch(argv[2]);
for (i = 1; i < argc && argv[i][0] == '-'; i++) {
- if (!strcmp(argv[i], "--print"))
- print = 1;
+ if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
+ normalize = 1;
else if (!strcmp(argv[i], "--allow-onelevel"))
flags |= REFNAME_ALLOW_ONELEVEL;
else if (!strcmp(argv[i], "--no-allow-onelevel"))
@@ -77,13 +77,12 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
usage(builtin_check_ref_format_usage);
refname = argv[i];
+ if (normalize)
+ refname = collapse_slashes(refname);
if (check_refname_format(refname, flags))
return 1;
-
- if (print) {
- refname = collapse_slashes(refname);
+ if (normalize)
printf("%s\n", refname);
- }
return 0;
}