From 5b0864070e1e64683e49464c77a72f3c528c8f71 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 12 Jul 2013 02:34:57 -0400 Subject: sha1_object_info_extended: make type calculation optional Each caller of sha1_object_info_extended sets up an object_info struct to tell the function which elements of the object it wants to get. Until now, getting the type of the object has always been required (and it is returned via the return type rather than a pointer in object_info). This can involve actually opening a loose object file to determine its type, or following delta chains to determine a packed file's base type. These effects produce a measurable slow-down when doing a "cat-file --batch-check" that does not include %(objecttype). This patch adds a "typep" query to struct object_info, so that it can be optionally queried just like size and disk_size. As a result, the return type of the function is no longer the object type, but rather 0/-1 for success/error. As there are only three callers total, we just fix up each caller rather than keep a compatibility wrapper: 1. The simpler sha1_object_info wrapper continues to always ask for and return the type field. 2. The istream_source function wants to know the type, and so always asks for it. 3. The cat-file batch code asks for the type only when %(objecttype) is part of the format string. On linux.git, the best-of-five for running: $ git rev-list --objects --all >objects $ time git cat-file --batch-check='%(objectsize:disk)' on a fully packed repository goes from: real 0m8.680s user 0m8.160s sys 0m0.512s to: real 0m7.205s user 0m6.580s sys 0m0.608s Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- streaming.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'streaming.c') diff --git a/streaming.c b/streaming.c index cac282f06..870657ab5 100644 --- a/streaming.c +++ b/streaming.c @@ -111,11 +111,11 @@ static enum input_source istream_source(const unsigned char *sha1, unsigned long size; int status; + oi->typep = type; oi->sizep = &size; status = sha1_object_info_extended(sha1, oi); if (status < 0) return stream_error; - *type = status; switch (oi->whence) { case OI_LOOSE: -- cgit v1.2.1 From d099b7173dabdeeb1f339151ac2169b3a91bf631 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Thu, 18 Jul 2013 21:25:50 +0100 Subject: Fix some sparse warnings Sparse issues some "Using plain integer as NULL pointer" warnings. Each warning relates to the use of an '{0}' initialiser expression in the declaration of an 'struct object_info'. The first field of this structure has pointer type. Thus, in order to suppress these warnings, we replace the initialiser expression with '{NULL}'. Signed-off-by: Ramsay Jones Acked-by: Jeff King Signed-off-by: Junio C Hamano --- streaming.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'streaming.c') diff --git a/streaming.c b/streaming.c index 870657ab5..acc07a6ff 100644 --- a/streaming.c +++ b/streaming.c @@ -135,7 +135,7 @@ struct git_istream *open_istream(const unsigned char *sha1, struct stream_filter *filter) { struct git_istream *st; - struct object_info oi = {0}; + struct object_info oi = {NULL}; const unsigned char *real = lookup_replace_object(sha1); enum input_source src = istream_source(real, type, &oi); -- cgit v1.2.1