summaryrefslogtreecommitdiff
path: root/builtin-rev-parse.c
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2008-04-26 13:57:23 +0200
committerJunio C Hamano <gitster@pobox.com>2008-04-26 23:22:17 -0700
commitb1b359699a24a89f773cccdf35801bc6fc15ade8 (patch)
treef9205eca69ab884a83345cd9ac7eb2f3432198aa /builtin-rev-parse.c
parent36c79d2bf893b9957688a6c8c13cc0bf0589e596 (diff)
downloadgit-b1b359699a24a89f773cccdf35801bc6fc15ade8.tar.gz
rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet"
Currently "git rev-parse --verify <something>" is often used with its error output redirected to /dev/null. This patch makes it easier to do that. The -q|--quiet option is designed to work the same way as it does for "git symbolic-ref". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-rev-parse.c')
-rw-r--r--builtin-rev-parse.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 0351d54435..9384a991ee 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -365,9 +365,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
return 0;
}
+static void die_no_single_rev(int quiet)
+{
+ if (quiet)
+ exit(1);
+ else
+ die("Needed a single revision");
+}
+
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
- int i, as_is = 0, verify = 0;
+ int i, as_is = 0, verify = 0, quiet = 0;
unsigned char sha1[20];
if (argc > 1 && !strcmp("--parseopt", argv[1]))
@@ -432,6 +440,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
verify = 1;
continue;
}
+ if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
+ quiet = 1;
+ continue;
+ }
if (!strcmp(arg, "--short") ||
!prefixcmp(arg, "--short=")) {
filter &= ~(DO_FLAGS|DO_NOREV);
@@ -549,7 +561,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (show_flag(arg) && verify)
- die("Needed a single revision");
+ die_no_single_rev(quiet);
continue;
}
@@ -568,11 +580,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
if (!show_file(arg))
continue;
if (verify)
- die("Needed a single revision");
+ die_no_single_rev(quiet);
verify_filename(prefix, arg);
}
show_default();
if (verify && revs_count != 1)
- die("Needed a single revision");
+ die_no_single_rev(quiet);
return 0;
}