chiark / gitweb /
use new git-check-ref-format
[version-charset-test.git] / 0002-check-ref-format-Refactor-to-make-branch-code-more-c.patch
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
5  common
6
7 We are going to want to permit other options with --branch.
8
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
11 end.
12
13 No overall functional change.
14
15 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
16 ---
17  builtin/check-ref-format.c | 17 +++++++++++++----
18  1 file changed, 13 insertions(+), 4 deletions(-)
19
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)
25  }
26  
27  static int normalize = 0;
28 +static int check_branch = 0;
29  static int flags = 0;
30  
31  static int check_one_ref_format(const char *refname)
32  {
33 +       int got;
34 +
35         if (normalize)
36                 refname = collapse_slashes(refname);
37 -       if (check_refname_format(refname, flags))
38 +       got = check_branch
39 +               ? check_ref_format_branch(refname)
40 +               : check_refname_format(refname, flags);
41 +       if (got)
42                 return 1;
43         if (normalize)
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);
48  
49 -       if (argc == 3 && !strcmp(argv[1], "--branch"))
50 -               return check_ref_format_branch(argv[2]);
51 -
52         for (i = 1; i < argc && argv[i][0] == '-'; i++) {
53                 if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
54                         normalize = 1;
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"))
60 +                       check_branch = 1;
61                 else
62                         usage(builtin_check_ref_format_usage);
63         }
64 +
65 +       if (check_branch && (flags || normalize))
66 +               usage(builtin_check_ref_format_usage);
67 +
68         if (! (i == argc - 1))
69                 usage(builtin_check_ref_format_usage);
70  
71 -- 
72 2.10.1
73