]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pack-objects.c
Merge branch 'km/submodule-doc-use-sm-path' into maint
[thirdparty/git.git] / pack-objects.c
index 92708522e76b4565882177f899612d72a3f6d75a..5e5a3c62d9db8cf11b4c64c196ae0fb830fe5004 100644 (file)
@@ -6,17 +6,17 @@
 #include "config.h"
 
 static uint32_t locate_object_entry_hash(struct packing_data *pdata,
-                                        const unsigned char *sha1,
+                                        const struct object_id *oid,
                                         int *found)
 {
        uint32_t i, mask = (pdata->index_size - 1);
 
-       i = sha1hash(sha1) & mask;
+       i = oidhash(oid) & mask;
 
        while (pdata->index[i] > 0) {
                uint32_t pos = pdata->index[i] - 1;
 
-               if (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) {
+               if (oideq(oid, &pdata->objects[pos].idx.oid)) {
                        *found = 1;
                        return i;
                }
@@ -56,7 +56,7 @@ static void rehash_objects(struct packing_data *pdata)
        for (i = 0; i < pdata->nr_objects; i++) {
                int found;
                uint32_t ix = locate_object_entry_hash(pdata,
-                                                      entry->idx.oid.hash,
+                                                      &entry->idx.oid,
                                                       &found);
 
                if (found)
@@ -68,8 +68,7 @@ static void rehash_objects(struct packing_data *pdata)
 }
 
 struct object_entry *packlist_find(struct packing_data *pdata,
-                                  const unsigned char *sha1,
-                                  uint32_t *index_pos)
+                                  const struct object_id *oid)
 {
        uint32_t i;
        int found;
@@ -77,10 +76,7 @@ struct object_entry *packlist_find(struct packing_data *pdata,
        if (!pdata->index_size)
                return NULL;
 
-       i = locate_object_entry_hash(pdata, sha1, &found);
-
-       if (index_pos)
-               *index_pos = i;
+       i = locate_object_entry_hash(pdata, oid, &found);
 
        if (!found)
                return NULL;
@@ -99,7 +95,7 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
         * (i.e. in_pack_idx also zero) should return NULL.
         */
        mapping[cnt++] = NULL;
-       for (p = get_packed_git(the_repository); p; p = p->next, cnt++) {
+       for (p = get_all_packs(pdata->repo); p; p = p->next, cnt++) {
                if (cnt == nr) {
                        free(mapping);
                        return;
@@ -119,12 +115,14 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
  * this fall back code, just stay simple and fall back to using
  * in_pack[] array.
  */
-void oe_map_new_pack(struct packing_data *pack,
-                    struct packed_git *p)
+void oe_map_new_pack(struct packing_data *pack)
 {
        uint32_t i;
 
-       REALLOC_ARRAY(pack->in_pack, pack->nr_alloc);
+       if (pack->in_pack)
+               BUG("packing_data has already been converted to pack array");
+
+       ALLOC_ARRAY(pack->in_pack, pack->nr_alloc);
 
        for (i = 0; i < pack->nr_objects; i++)
                pack->in_pack[i] = oe_in_pack(pack, pack->objects + i);
@@ -133,8 +131,10 @@ void oe_map_new_pack(struct packing_data *pack,
 }
 
 /* assume pdata is already zero'd by caller */
-void prepare_packing_data(struct packing_data *pdata)
+void prepare_packing_data(struct repository *r, struct packing_data *pdata)
 {
+       pdata->repo = r;
+
        if (git_env_bool("GIT_TEST_FULL_IN_PACK_ARRAY", 0)) {
                /*
                 * do not initialize in_pack_by_idx[] to force the
@@ -146,11 +146,13 @@ void prepare_packing_data(struct packing_data *pdata)
 
        pdata->oe_size_limit = git_env_ulong("GIT_TEST_OE_SIZE",
                                             1U << OE_SIZE_BITS);
+       pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
+                                                  1UL << OE_DELTA_SIZE_BITS);
+       init_recursive_mutex(&pdata->odb_lock);
 }
 
 struct object_entry *packlist_alloc(struct packing_data *pdata,
-                                   const unsigned char *sha1,
-                                   uint32_t index_pos)
+                                   const struct object_id *oid)
 {
        struct object_entry *new_entry;
 
@@ -160,20 +162,60 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
 
                if (!pdata->in_pack_by_idx)
                        REALLOC_ARRAY(pdata->in_pack, pdata->nr_alloc);
+               if (pdata->delta_size)
+                       REALLOC_ARRAY(pdata->delta_size, pdata->nr_alloc);
+
+               if (pdata->tree_depth)
+                       REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc);
+
+               if (pdata->layer)
+                       REALLOC_ARRAY(pdata->layer, pdata->nr_alloc);
        }
 
        new_entry = pdata->objects + pdata->nr_objects++;
 
        memset(new_entry, 0, sizeof(*new_entry));
-       hashcpy(new_entry->idx.oid.hash, sha1);
+       oidcpy(&new_entry->idx.oid, oid);
 
        if (pdata->index_size * 3 <= pdata->nr_objects * 4)
                rehash_objects(pdata);
-       else
-               pdata->index[index_pos] = pdata->nr_objects;
+       else {
+               int found;
+               uint32_t pos = locate_object_entry_hash(pdata,
+                                                       &new_entry->idx.oid,
+                                                       &found);
+               if (found)
+                       BUG("duplicate object inserted into hash");
+               pdata->index[pos] = pdata->nr_objects;
+       }
 
        if (pdata->in_pack)
                pdata->in_pack[pdata->nr_objects - 1] = NULL;
 
+       if (pdata->tree_depth)
+               pdata->tree_depth[pdata->nr_objects - 1] = 0;
+
+       if (pdata->layer)
+               pdata->layer[pdata->nr_objects - 1] = 0;
+
        return new_entry;
 }
+
+void oe_set_delta_ext(struct packing_data *pdata,
+                     struct object_entry *delta,
+                     const unsigned char *sha1)
+{
+       struct object_entry *base;
+
+       ALLOC_GROW(pdata->ext_bases, pdata->nr_ext + 1, pdata->alloc_ext);
+       base = &pdata->ext_bases[pdata->nr_ext++];
+       memset(base, 0, sizeof(*base));
+       hashcpy(base->idx.oid.hash, sha1);
+
+       /* These flags mark that we are not part of the actual pack output. */
+       base->preferred_base = 1;
+       base->filled = 1;
+
+       delta->ext_base = 1;
+       delta->delta_idx = base - pdata->ext_bases + 1;
+}