Skip to content

Commit

Permalink
rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christian Couder authored and Junio C Hamano committed Apr 27, 2008
1 parent 36c79d2 commit b1b3596
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Documentation/git-rev-parse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ OPTIONS
The parameter given must be usable as a single, valid
object name. Otherwise barf and abort.

-q, --quiet::
Only meaningful in `--verify` mode. Do not output an error
message if the first argument is not a valid object name;
instead exit with non-zero status silently.

--sq::
Usually the output is made one line per flag and
parameter. This option makes output a single line,
Expand Down
20 changes: 16 additions & 4 deletions builtin-rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

0 comments on commit b1b3596

Please sign in to comment.