rev-parse: put all options under the "-" check
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>
Jeff King committed
Nov 10, 2020 at 16:38 UTC
9033addfa6a910325fbe9619dc623c17e989261c
1 file changed
+23
-24
builtin/rev-parse.c
+23
-24
@@ -652,30 +652,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
652
did_repo_setup = 1;
653
}
654
655
- if (!strcmp(arg, "--git-path")) {
656
- if (!argv[i + 1])
657
- die("--git-path requires an argument");
658
- strbuf_reset(&buf);
659
- puts(relative_path(git_path("%s", argv[i + 1]),
660
- prefix, &buf));
661
- i++;
662
- continue;
663
- }
664
- if (!strcmp(arg,"-n")) {
665
- if (++i >= argc)
666
- die("-n requires an argument");
667
- if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
668
- show(arg);
669
- show(argv[i]);
670
- }
671
- continue;
672
- }
673
- if (starts_with(arg, "-n")) {
674
- if ((filter & DO_FLAGS) && (filter & DO_REVS))
675
- show(arg);
676
- continue;
677
- }
678
-
655
if (*arg == '-') {
656
if (!strcmp(arg, "--")) {
657
as_is = 2;
@@ -684,6 +660,29 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
660
show_file(arg, 0);
661
continue;
662
}
663
+ if (!strcmp(arg, "--git-path")) {
664
+ if (!argv[i + 1])
665
+ die("--git-path requires an argument");
666
+ strbuf_reset(&buf);
667
+ puts(relative_path(git_path("%s", argv[i + 1]),
668
+ prefix, &buf));
669
+ i++;
670
+ continue;
671
+ }
672
+ if (!strcmp(arg,"-n")) {
673
+ if (++i >= argc)
674
+ die("-n requires an argument");
675
+ if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
676
+ show(arg);
677
+ show(argv[i]);
678
+ }
679
+ continue;
680
+ }
681
+ if (starts_with(arg, "-n")) {
682
+ if ((filter & DO_FLAGS) && (filter & DO_REVS))
683
+ show(arg);
684
+ continue;
685
+ }
686
if (!strcmp(arg, "--default")) {
687
def = argv[++i];
688
if (!def)