git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 3/3] rev-parse --verify: do not output anything on error
Date: Sun, 11 May 2008 18:28:25 +0200	[thread overview]
Message-ID: <20080511182825.42bc6ec9.chriscool@tuxfamily.org> (raw)

Before this patch, when "git rev-parse --verify" was passed at least one
good rev and then anything, it would output something for the good rev
even if it would latter exit on error.

With this patch, we only output something if everything is ok.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin-rev-parse.c         |   38 +++++++++++++++++++++++---------------
 t/t1503-rev-parse-verify.sh |   12 +++---------
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 7dbf282..03b5f59 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -28,8 +28,6 @@ static int symbolic;
 static int abbrev;
 static int output_sq;
 
-static int revs_count;
-
 /*
  * Some arguments are relevant "revision" arguments,
  * others are about output format or other details.
@@ -102,7 +100,6 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
 	if (!(filter & DO_REVS))
 		return;
 	def = NULL;
-	revs_count++;
 
 	if (type != show_type)
 		putchar('^');
@@ -150,7 +147,7 @@ static int show_flag(const char *arg)
 	return 0;
 }
 
-static void show_default(void)
+static int show_default(void)
 {
 	const char *s = def;
 
@@ -160,9 +157,10 @@ static void show_default(void)
 		def = NULL;
 		if (!get_sha1(s, sha1)) {
 			show_rev(NORMAL, sha1, s);
-			return;
+			return 1;
 		}
 	}
+	return 0;
 }
 
 static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
@@ -375,8 +373,9 @@ static void die_no_single_rev(int quiet)
 
 int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 {
-	int i, as_is = 0, verify = 0, quiet = 0;
+	int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type;
 	unsigned char sha1[20];
+	const char *name;
 
 	if (argc > 1 && !strcmp("--parseopt", argv[1]))
 		return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -568,12 +567,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 		/* Not a flag argument */
 		if (try_difference(arg))
 			continue;
-		if (!get_sha1(arg, sha1)) {
-			show_rev(NORMAL, sha1, arg);
-			continue;
+		name = arg;
+		type = NORMAL;
+		if (*arg == '^') {
+			name++;
+			type = REVERSED;
 		}
-		if (*arg == '^' && !get_sha1(arg+1, sha1)) {
-			show_rev(REVERSED, sha1, arg+1);
+		if (!get_sha1(name, sha1)) {
+			if (verify)
+				revs_count++;
+			else
+				show_rev(type, sha1, name);
 			continue;
 		}
 		if (verify)
@@ -583,10 +587,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			continue;
 		verify_filename(prefix, arg);
 	}
-	if (verify && revs_count == 1)
-		return 0;
-	show_default();
-	if (verify && revs_count != 1)
+	if (verify) {
+		if (revs_count == 1) {
+			show_rev(type, sha1, name);
+			return 0;
+		} else if (revs_count == 0 && show_default())
+			return 0;
 		die_no_single_rev(quiet);
+	} else
+		show_default();
 	return 0;
 }
diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh
index e93f1b3..95244c9 100755
--- a/t/t1503-rev-parse-verify.sh
+++ b/t/t1503-rev-parse-verify.sh
@@ -83,17 +83,11 @@ test_expect_success 'fails silently when using -q' '
 	test -z "$(cat error)"
 '
 
-test_expect_success '1 no stdout output on error' '
+test_expect_success 'no stdout output on error' '
 	test -z "$(git rev-parse --verify)" &&
 	test -z "$(git rev-parse --verify foo)" &&
-	test -z "$(git rev-parse --verify baz HEAD)"
-'
-
-test_expect_failure '2 no stdout output on error' '
-	test -z "$(git rev-parse --verify HEAD bar)"
-'
-
-test_expect_failure '3 no stdout output on error' '
+	test -z "$(git rev-parse --verify baz HEAD)" &&
+	test -z "$(git rev-parse --verify HEAD bar)" &&
 	test -z "$(git rev-parse --verify $HASH2 HEAD)"
 '
 
-- 
1.5.5.1.347.g779f4

                 reply	other threads:[~2008-05-11 16:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080511182825.42bc6ec9.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).