rev-parse: remove restrictions on some options

The "--local-env-vars" and "--resolve-git-dir" arguments to git-rev-parse are currently only handled if they appear first on the command line (in the case of "--local-env-vars", only if it is the only argument). While it may not make sense to use these options when any others are specified, there is no reason for this restriction and it might confuse users if these arguments appear to be ignored. There is no need for any documentation change here as the restrictions on these options are not documented. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Jul 21, 2013 at 13:49 UTC 68889b416d5b6a5cf7d280a428281d635fe9b292
1 file changed +13 -15
builtin/rev-parse.c
+13 -15
@@ -479,21 +479,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
479 if (argc > 1 && !strcmp("--sq-quote", argv[1]))
480 return cmd_sq_quote(argc - 2, argv + 2);
481
482 - if (argc == 2 && !strcmp("--local-env-vars", argv[1])) {
483 - int i;
484 - for (i = 0; local_repo_env[i]; i++)
485 - printf("%s\n", local_repo_env[i]);
486 - return 0;
487 - }
488 -
489 - if (argc > 2 && !strcmp(argv[1], "--resolve-git-dir")) {
490 - const char *gitdir = resolve_gitdir(argv[2]);
491 - if (!gitdir)
492 - die("not a gitdir '%s'", argv[2]);
493 - puts(gitdir);
494 - return 0;
495 - }
496 -
482 if (argc > 1 && !strcmp("-h", argv[1]))
483 usage(builtin_rev_parse_usage);
484
@@ -647,6 +632,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
632 for_each_remote_ref(show_reference, NULL);
633 continue;
634 }
635 + if (!strcmp(arg, "--local-env-vars")) {
636 + int i;
637 + for (i = 0; local_repo_env[i]; i++)
638 + printf("%s\n", local_repo_env[i]);
639 + continue;
640 + }
641 if (!strcmp(arg, "--show-toplevel")) {
642 const char *work_tree = get_git_work_tree();
643 if (work_tree)
@@ -697,6 +688,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
688 printf("%s%s.git\n", cwd, len && cwd[len-1] != '/' ? "/" : "");
689 continue;
690 }
691 + if (!strcmp(arg, "--resolve-git-dir")) {
692 + const char *gitdir = resolve_gitdir(argv[i+1]);
693 + if (!gitdir)
694 + die("not a gitdir '%s'", argv[i+1]);
695 + puts(gitdir);
696 + continue;
697 + }
698 if (!strcmp(arg, "--is-inside-git-dir")) {
699 printf("%s\n", is_inside_git_dir() ? "true"
700 : "false");