Merge branch 'jk/cat-file-batch-optim'
authorJunio C Hamano <gitster@pobox.com>
Thu, 25 Jul 2013 02:21:21 +0000 (19:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jul 2013 02:21:21 +0000 (19:21 -0700)
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

1  2 
cache.h
environment.c
sha1_file.c
sha1_name.c
streaming.c

diff --cc cache.h
Simple merge
diff --cc environment.c
Simple merge
diff --cc 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
@@@ -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;
        }
  
diff --cc streaming.c
Simple merge