Move buffer_is_binary() to xdiff-interface.h
[gitweb.git] / builtin-pack-objects.c
index 9f035ba8e645e45547fe3145674efb33cfc9cb23..ccb25f6a9c298bd977c5f55a84dd9a20a1e54e23 100644 (file)
@@ -79,6 +79,7 @@ static int pack_compression_seen;
 
 static unsigned long delta_cache_size = 0;
 static unsigned long max_delta_cache_size = 0;
+static unsigned long cache_max_small_delta_size = 1000;
 
 /*
  * The object names in objects array are hashed with this hashtable,
@@ -409,31 +410,24 @@ static unsigned long write_object(struct sha1file *f,
                z_stream stream;
                unsigned long maxsize;
                void *out;
-               if (entry->delta_data && usable_delta) {
-                       buf = entry->delta_data;
+               if (!usable_delta) {
+                       buf = read_sha1_file(entry->sha1, &obj_type, &size);
+                       if (!buf)
+                               die("unable to read %s", sha1_to_hex(entry->sha1));
+               } else if (entry->delta_data) {
                        size = entry->delta_size;
+                       buf = entry->delta_data;
+                       entry->delta_data = NULL;
                        obj_type = (allow_ofs_delta && entry->delta->offset) ?
                                OBJ_OFS_DELTA : OBJ_REF_DELTA;
                } else {
                        buf = read_sha1_file(entry->sha1, &type, &size);
                        if (!buf)
                                die("unable to read %s", sha1_to_hex(entry->sha1));
-                       if (size != entry->size)
-                               die("object %s size inconsistency (%lu vs %lu)",
-                                   sha1_to_hex(entry->sha1), size, entry->size);
-                       if (usable_delta) {
-                               buf = delta_against(buf, size, entry);
-                               size = entry->delta_size;
-                               obj_type = (allow_ofs_delta && entry->delta->offset) ?
-                                       OBJ_OFS_DELTA : OBJ_REF_DELTA;
-                       } else {
-                               /*
-                                * recover real object type in case
-                                * check_object() wanted to re-use a delta,
-                                * but we couldn't since base was in previous split pack
-                                */
-                               obj_type = type;
-                       }
+                       buf = delta_against(buf, size, entry);
+                       size = entry->delta_size;
+                       obj_type = (allow_ofs_delta && entry->delta->offset) ?
+                               OBJ_OFS_DELTA : OBJ_REF_DELTA;
                }
                /* compress the data to store and put compressed length in datalen */
                memset(&stream, 0, sizeof(stream));
@@ -1403,6 +1397,9 @@ static int delta_cacheable(struct unpacked *trg, struct unpacked *src,
        if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size)
                return 0;
 
+       if (delta_size < cache_max_small_delta_size)
+               return 1;
+
        /* cache delta, if objects are large enough compared to delta size */
        if ((src_size >> 20) + (trg_size >> 21) > (delta_size >> 10))
                return 1;
@@ -1654,6 +1651,10 @@ static int git_pack_config(const char *k, const char *v)
                max_delta_cache_size = git_config_int(k, v);
                return 0;
        }
+       if (!strcmp(k, "pack.deltacachelimit")) {
+               cache_max_small_delta_size = git_config_int(k, v);
+               return 0;
+       }
        return git_default_config(k, v);
 }