From a40e6fb67a4aed2d5ffde5792bf7f1996d9666e1 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 15 Sep 2011 23:10:30 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/check-ref-format.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'builtin') diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index f5df9aad70..28a7320271 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] \n" +"git check-ref-format [--normalize] [options] \n" " or: git check-ref-format --branch "; /* @@ -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; } -- cgit v1.2.3