]> Pileus Git - ~andy/git/commitdiff
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
index 4c2365f48f7ce361e009d5f4d9323184f6782d34,452e4647b387799ebed343b100236b1cba9b0104..8e27db1bd2b49f28b235fcd7e18a0dda43a1f045
@@@ -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 543bf9d9eceb81f97107437b30f4f150270b949a,c1957f35c182af9bf91658fa37602cf4071c7c37..0cf0c28a6fb737ccdb2b93c9b7d01570ec018f37
@@@ -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