chiark / gitweb /
use new git-check-ref-format
[version-charset-test.git] / 0002-check-ref-format-Refactor-to-make-branch-code-more-c.patch
diff --git a/0002-check-ref-format-Refactor-to-make-branch-code-more-c.patch b/0002-check-ref-format-Refactor-to-make-branch-code-more-c.patch
new file mode 100644 (file)
index 0000000..a3fbf3d
--- /dev/null
@@ -0,0 +1,73 @@
+From 3caa32b73e206378ad870276cc5feb73b6cf54bb Mon Sep 17 00:00:00 2001
+From: Ian Jackson <ijackson@chiark.greenend.org.uk>
+Date: Fri, 4 Nov 2016 17:45:38 +0000
+Subject: [PATCH 2/5] check-ref-format: Refactor to make --branch code more
+ common
+
+We are going to want to permit other options with --branch.
+
+So, replace the special case with just an entry for --branch in the
+parser for ordinary options, and check for option compatibility at the
+end.
+
+No overall functional change.
+
+Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
+---
+ builtin/check-ref-format.c | 17 +++++++++++++----
+ 1 file changed, 13 insertions(+), 4 deletions(-)
+
+diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
+index 4d56caa..f12c19c 100644
+--- a/builtin/check-ref-format.c
++++ b/builtin/check-ref-format.c
+@@ -49,13 +49,19 @@ static int check_ref_format_branch(const char *arg)
+ }
+ static int normalize = 0;
++static int check_branch = 0;
+ static int flags = 0;
+ static int check_one_ref_format(const char *refname)
+ {
++      int got;
++
+       if (normalize)
+               refname = collapse_slashes(refname);
+-      if (check_refname_format(refname, flags))
++      got = check_branch
++              ? check_ref_format_branch(refname)
++              : check_refname_format(refname, flags);
++      if (got)
+               return 1;
+       if (normalize)
+               printf("%s\n", refname);
+@@ -68,9 +74,6 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage(builtin_check_ref_format_usage);
+-      if (argc == 3 && !strcmp(argv[1], "--branch"))
+-              return check_ref_format_branch(argv[2]);
+-
+       for (i = 1; i < argc && argv[i][0] == '-'; i++) {
+               if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
+                       normalize = 1;
+@@ -80,9 +83,15 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
+                       flags &= ~REFNAME_ALLOW_ONELEVEL;
+               else if (!strcmp(argv[i], "--refspec-pattern"))
+                       flags |= REFNAME_REFSPEC_PATTERN;
++              else if (!strcmp(argv[i], "--branch"))
++                      check_branch = 1;
+               else
+                       usage(builtin_check_ref_format_usage);
+       }
++
++      if (check_branch && (flags || normalize))
++              usage(builtin_check_ref_format_usage);
++
+       if (! (i == argc - 1))
+               usage(builtin_check_ref_format_usage);
+-- 
+2.10.1
+