Skip to content

Commit 9033add

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e05e2ae commit 9033add

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

builtin/rev-parse.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -652,30 +652,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
652652
did_repo_setup = 1;
653653
}
654654

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-
679655
if (*arg == '-') {
680656
if (!strcmp(arg, "--")) {
681657
as_is = 2;
@@ -684,6 +660,29 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
684660
show_file(arg, 0);
685661
continue;
686662
}
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+
}
687686
if (!strcmp(arg, "--default")) {
688687
def = argv[++i];
689688
if (!def)

0 commit comments

Comments
 (0)