* [PATCH] rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet"
@ 2008-04-26 11:57 Christian Couder
2008-04-27 6:16 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Christian Couder @ 2008-04-26 11:57 UTC (permalink / raw)
To: git
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>
---
Documentation/git-rev-parse.txt | 5 +++++
builtin-rev-parse.c | 20 ++++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
By the way it's strange that for example:
$ git rev-parse --verify <good-rev> <junk>
works whatever <junk> is, as long as <good-rev> can be
parsed.
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 6513c2e..110e7ba 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -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,
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 0351d54..9384a99 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;
}
--
1.5.5.130.g68d41
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet"
2008-04-26 11:57 [PATCH] rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet" Christian Couder
@ 2008-04-27 6:16 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-04-27 6:16 UTC (permalink / raw)
To: Christian Couder; +Cc: git
Christian Couder <chriscool@tuxfamily.org> writes:
> 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>
> ---
> Documentation/git-rev-parse.txt | 5 +++++
> builtin-rev-parse.c | 20 ++++++++++++++++----
> 2 files changed, 21 insertions(+), 4 deletions(-)
>
> By the way it's strange that for example:
>
> $ git rev-parse --verify <good-rev> <junk>
>
> works whatever <junk> is, as long as <good-rev> can be
> parsed.
Very much so. The earlier plumbing programs tend to have this "works if
you give correct input but sometimes ignores bogosity" tendency. They are
loose not by design, and we should be able to tighten without worrying
about breaking existing scripts.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-27 6:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-26 11:57 [PATCH] rev-parse: teach "--verify" to be quiet when using "-q" or "--quiet" Christian Couder
2008-04-27 6:16 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).