>From 2e7b5aed771faeff654a447346bb0b57570d9569 Mon Sep 17 00:00:00 2001 From: Sven Brauch <svenbrauch@xxxxxxxxxxxxxx> Date: Tue, 5 Nov 2013 20:06:21 +0100 Subject: [PATCH] git-cat-file: fix output when format string contains no variables When the format string for git-cat-object --batch-check contained no variables, the function would not actually look for the object on disk, but just verify that the hash is correct. Thus it would report no error if asking for objects which did not actually exist on disk if the SHA hash looked ok. Example of buggy behaviour: echo "XYZ" | git hash-object --stdin | git cat-file --batch-check="found" would report "found" although the manpage claims it would report an error. Signed-off-by: Sven Brauch <svenbrauch@xxxxxxxxxxxxxx> --- Notes: This fixes a bug where git-cat-file --batch-check would erroneously tell that objects exist while they did in fact not in case the argument to --batch-check was just a constant strig (i.e. no %(...) variables). The reason was that calling sha1_object_info_extended while requesting no properties of the object would not even verify this object existed, or more exactly, sha1_loose_object_info would not do that. I'm entirely unfamiliar with the git codebase; the suggested fix ensures that always at least one property is requested. If there's a better way to fix this issue, please let me know. builtin/cat-file.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b2ca775..32d0b63 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -238,6 +238,15 @@ static int batch_one_object(const char *obj_name, struct batch_options *opt, return 0; } + if (!data->info.disk_sizep && !data->info.sizep && !data->info.typep) { + /* + * None of the info fields was requested, so we request the cheapest + * one (disk_sizep) to force sha1_object_info_extended to actually + * look for the file. + */ + data->info.disk_sizep = &data->disk_size; + } + if (sha1_object_info_extended(data->sha1, &data->info) < 0) { printf("%s missing\n", obj_name); fflush(stdout); -- 1.8.4.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html