]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-parse: put all options under the "-" check
authorJeff King <peff@peff.net>
Tue, 10 Nov 2020 21:38:03 +0000 (16:38 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Nov 2020 21:46:27 +0000 (13:46 -0800)
The option-parsing loop of rev-parse checks whether the first character
of an arg is "-". If so, then it enters a series of conditionals
checking for individual options. But some options are inexplicably
outside of that outer conditional.

This doesn't produce the wrong behavior; the conditional is actually
redundant with the individual option checks, and it's really only its
fallback "continue" that we care about. But we should at least be
consistent.

One obvious alternative is that we could get rid of the conditional
entirely. But we'll be using the extra block it provides in the next
patch.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rev-parse.c

index 293428fa0d21407fe465c1ab2a00ae8f5c336713..79689286d83dbf1b6b254cb823d65e1dc20f70fc 100644 (file)
@@ -652,30 +652,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        did_repo_setup = 1;
                }
 
-               if (!strcmp(arg, "--git-path")) {
-                       if (!argv[i + 1])
-                               die("--git-path requires an argument");
-                       strbuf_reset(&buf);
-                       puts(relative_path(git_path("%s", argv[i + 1]),
-                                          prefix, &buf));
-                       i++;
-                       continue;
-               }
-               if (!strcmp(arg,"-n")) {
-                       if (++i >= argc)
-                               die("-n requires an argument");
-                       if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
-                               show(arg);
-                               show(argv[i]);
-                       }
-                       continue;
-               }
-               if (starts_with(arg, "-n")) {
-                       if ((filter & DO_FLAGS) && (filter & DO_REVS))
-                               show(arg);
-                       continue;
-               }
-
                if (*arg == '-') {
                        if (!strcmp(arg, "--")) {
                                as_is = 2;
@@ -684,6 +660,29 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                        show_file(arg, 0);
                                continue;
                        }
+                       if (!strcmp(arg, "--git-path")) {
+                               if (!argv[i + 1])
+                                       die("--git-path requires an argument");
+                               strbuf_reset(&buf);
+                               puts(relative_path(git_path("%s", argv[i + 1]),
+                                                  prefix, &buf));
+                               i++;
+                               continue;
+                       }
+                       if (!strcmp(arg,"-n")) {
+                               if (++i >= argc)
+                                       die("-n requires an argument");
+                               if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
+                                       show(arg);
+                                       show(argv[i]);
+                               }
+                               continue;
+                       }
+                       if (starts_with(arg, "-n")) {
+                               if ((filter & DO_FLAGS) && (filter & DO_REVS))
+                                       show(arg);
+                               continue;
+                       }
                        if (!strcmp(arg, "--default")) {
                                def = argv[++i];
                                if (!def)