From: Junio C Hamano Date: Thu, 25 Jul 2013 02:21:21 +0000 (-0700) Subject: Merge branch 'jk/cat-file-batch-optim' X-Git-Tag: v1.8.4-rc0~7 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/356df9bd8df58eb759fedaee8a8d1a7dc0872f8f Merge branch 'jk/cat-file-batch-optim' If somebody wants to only know on-disk footprint of an object without having to know its type or payload size, we can bypass a lot of code to cheaply learn it. * jk/cat-file-batch-optim: Fix some sparse warnings sha1_object_info_extended: pass object_info to helpers sha1_object_info_extended: make type calculation optional packed_object_info: make type lookup optional packed_object_info: hoist delta type resolution to helper sha1_loose_object_info: make type lookup optional sha1_object_info_extended: rename "status" to "type" cat-file: disable object/refname ambiguity check for batch mode --- 356df9bd8df58eb759fedaee8a8d1a7dc0872f8f diff --cc sha1_file.c index 4c2365f48f,452e4647b3..8e27db1bd2 --- a/sha1_file.c +++ b/sha1_file.c @@@ -2372,11 -2392,25 +2411,25 @@@ static int sha1_loose_object_info(cons git_zstream stream; char hdr[32]; + /* + * If we don't care about type or size, then we don't + * need to look inside the object at all. + */ + if (!oi->typep && !oi->sizep) { + if (oi->disk_sizep) { + struct stat st; + if (stat_sha1_file(sha1, &st) < 0) + return -1; + *oi->disk_sizep = st.st_size; + } + return 0; + } + map = map_sha1_file(sha1, &mapsize); if (!map) - return error("unable to find %s", sha1_to_hex(sha1)); + return -1; - if (disk_sizep) - *disk_sizep = mapsize; + if (oi->disk_sizep) + *oi->disk_sizep = mapsize; if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) status = error("unable to unpack %s header", sha1_to_hex(sha1)); diff --cc sha1_name.c index 543bf9d9ec,c1957f35c1..0cf0c28a6f --- a/sha1_name.c +++ b/sha1_name.c @@@ -449,16 -448,18 +449,18 @@@ static int get_sha1_basic(const char *s unsigned char tmp_sha1[20]; char *real_ref = NULL; int refs_found = 0; - int at, reflog_len; + int at, reflog_len, nth_prior = 0; if (len == 40 && !get_sha1_hex(str, sha1)) { - refs_found = dwim_ref(str, len, tmp_sha1, &real_ref); - if (refs_found > 0 && warn_ambiguous_refs) { - warning(warn_msg, len, str); - if (advice_object_name_warning) - fprintf(stderr, "%s\n", _(object_name_msg)); + if (warn_on_object_refname_ambiguity) { + refs_found = dwim_ref(str, len, tmp_sha1, &real_ref); + if (refs_found > 0 && warn_ambiguous_refs) { + warning(warn_msg, len, str); + if (advice_object_name_warning) + fprintf(stderr, "%s\n", _(object_name_msg)); + } + free(real_ref); } - free(real_ref); return 0; }