git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cat-file --batch / --batch-check: do not exit if hashes are missing
@ 2008-06-08 23:28 Lea Wiemann
  2008-06-08 23:34 ` Johannes Schindelin
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Lea Wiemann @ 2008-06-08 23:28 UTC (permalink / raw)
  To: git; +Cc: Lea Wiemann

Previously, cat-file --batch / --batch-check would silently exit if it
was passed a non-existent SHA1 on stdin.  Now it prints "<SHA1>
missing" as in all other cases (and as advertised in the
documentation).

Note that cat-file --batch-check (but not --batch) will still output
"error: unable to find <SHA1>" on stderr if a non-existent SHA1 is
passed, but this does not affect parsing its stdout.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
 builtin-cat-file.c  |    7 +++++--
 t/t1006-cat-file.sh |   15 ++++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index f8b3160..112b9db 100644
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
@@ -168,8 +168,11 @@ static int batch_one_object(const char *obj_name, int print_contents)
 	else
 		type = sha1_object_info(sha1, &size);
 
-	if (type <= 0)
-		return 1;
+	if (type <= 0) {
+		printf("%s missing\n", obj_name);
+		fflush(stdout);
+		return 0;
+	}
 
 	printf("%s %s %lu\n", sha1_to_hex(sha1), typename(type), size);
 	fflush(stdout);
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index 973aef7..04c3be0 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -174,9 +174,18 @@ do
     '
 done
 
-test_expect_success "--batch-check for a non-existent object" '
-    test "deadbeef missing" = \
-    "$(echo_without_newline deadbeef | git cat-file --batch-check)"
+test_expect_success "--batch-check for a non-existent named object" '
+    test "foobar42 missing
+foobar84 missing" = \
+    "$(( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+'
+
+test_expect_success "--batch-check for a non-existent hash" '
+    test "0000000000000000000000000000000000000042 missing
+0000000000000000000000000000000000000084 missing" = \
+    "$(( echo 0000000000000000000000000000000000000042;
+         echo_without_newline 0000000000000000000000000000000000000084; ) \
+       | git cat-file --batch-check)"
 '
 
 test_expect_success "--batch-check for an emtpy line" '
-- 
1.5.6.rc1.20.g9e7c7e.dirty

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-06-09 20:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-08 23:28 [PATCH] cat-file --batch / --batch-check: do not exit if hashes are missing Lea Wiemann
2008-06-08 23:34 ` Johannes Schindelin
2008-06-09  0:05   ` Lea Wiemann
2008-06-09  1:02     ` Johannes Schindelin
2008-06-09 10:17       ` Lea Wiemann
2008-06-09 11:07         ` Jakub Narebski
2008-06-09 13:27           ` Lea Wiemann
2008-06-09  0:02 ` [PATCH v2] " Lea Wiemann
2008-06-09 20:37   ` Junio C Hamano
2008-06-09 20:42   ` Junio C Hamano
2008-06-09 14:23 ` [PATCH] " Johannes Sixt
2008-06-09 18:21   ` Lea Wiemann

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).