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>
Christian Couder committed
Apr 26, 2008 at 13:57 UTC
b1b359699a24a89f773cccdf35801bc6fc15ade8
2 files changed
+21
-4
Documentation/git-rev-parse.txt
+5
@@ -52,6 +52,11 @@ OPTIONS
52
The parameter given must be usable as a single, valid
53
object name. Otherwise barf and abort.
54
55
+-q, --quiet::
56
+ Only meaningful in `--verify` mode. Do not output an error
57
+ message if the first argument is not a valid object name;
58
+ instead exit with non-zero status silently.
59
+
60
--sq::
61
Usually the output is made one line per flag and
62
parameter. This option makes output a single line,
builtin-rev-parse.c
+16
-4
@@ -365,9 +365,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
365
return 0;
366
}
367
368
+static void die_no_single_rev(int quiet)
369
+{
370
+ if (quiet)
371
+ exit(1);
372
+ else
373
+ die("Needed a single revision");
374
+}
375
+
376
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
377
{
370
- int i, as_is = 0, verify = 0;
378
+ int i, as_is = 0, verify = 0, quiet = 0;
379
unsigned char sha1[20];
380
381
if (argc > 1 && !strcmp("--parseopt", argv[1]))
@@ -432,6 +440,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
440
verify = 1;
441
continue;
442
}
443
+ if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
444
+ quiet = 1;
445
+ continue;
446
+ }
447
if (!strcmp(arg, "--short") ||
448
!prefixcmp(arg, "--short=")) {
449
filter &= ~(DO_FLAGS|DO_NOREV);
@@ -549,7 +561,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
561
continue;
562
}
563
if (show_flag(arg) && verify)
552
- die("Needed a single revision");
564
+ die_no_single_rev(quiet);
565
continue;
566
}
567
@@ -568,11 +580,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
580
if (!show_file(arg))
581
continue;
582
if (verify)
571
- die("Needed a single revision");
583
+ die_no_single_rev(quiet);
584
verify_filename(prefix, arg);
585
}
586
show_default();
587
if (verify && revs_count != 1)
576
- die("Needed a single revision");
588
+ die_no_single_rev(quiet);
589
return 0;
590
}