1 From 3caa32b73e206378ad870276cc5feb73b6cf54bb Mon Sep 17 00:00:00 2001
2 From: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 Date: Fri, 4 Nov 2016 17:45:38 +0000
4 Subject: [PATCH 2/5] check-ref-format: Refactor to make --branch code more
7 We are going to want to permit other options with --branch.
9 So, replace the special case with just an entry for --branch in the
10 parser for ordinary options, and check for option compatibility at the
13 No overall functional change.
15 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
17 builtin/check-ref-format.c | 17 +++++++++++++----
18 1 file changed, 13 insertions(+), 4 deletions(-)
20 diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
21 index 4d56caa..f12c19c 100644
22 --- a/builtin/check-ref-format.c
23 +++ b/builtin/check-ref-format.c
24 @@ -49,13 +49,19 @@ static int check_ref_format_branch(const char *arg)
27 static int normalize = 0;
28 +static int check_branch = 0;
31 static int check_one_ref_format(const char *refname)
36 refname = collapse_slashes(refname);
37 - if (check_refname_format(refname, flags))
39 + ? check_ref_format_branch(refname)
40 + : check_refname_format(refname, flags);
44 printf("%s\n", refname);
45 @@ -68,9 +74,6 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
46 if (argc == 2 && !strcmp(argv[1], "-h"))
47 usage(builtin_check_ref_format_usage);
49 - if (argc == 3 && !strcmp(argv[1], "--branch"))
50 - return check_ref_format_branch(argv[2]);
52 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
53 if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
55 @@ -80,9 +83,15 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
56 flags &= ~REFNAME_ALLOW_ONELEVEL;
57 else if (!strcmp(argv[i], "--refspec-pattern"))
58 flags |= REFNAME_REFSPEC_PATTERN;
59 + else if (!strcmp(argv[i], "--branch"))
62 usage(builtin_check_ref_format_usage);
65 + if (check_branch && (flags || normalize))
66 + usage(builtin_check_ref_format_usage);
68 if (! (i == argc - 1))
69 usage(builtin_check_ref_format_usage);