]> git.ipfire.org Git - thirdparty/git.git/commitdiff
make_transient_cache_entry(): optionally alloc from mem_pool
authorMatheus Tavares <matheus.bernardino@usp.br>
Tue, 4 May 2021 16:27:28 +0000 (13:27 -0300)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 May 2021 03:25:25 +0000 (12:25 +0900)
Allow make_transient_cache_entry() to optionally receive a mem_pool
struct in which it should allocate the entry. This will be used in the
following patch, to store some transient entries which should persist
until parallel checkout finishes.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout--worker.c
builtin/checkout.c
builtin/difftool.c
cache.h
read-cache.c
unpack-trees.c

index 31e0de2f7ecfa91151f58e1259259b5f1b3bec78..289a9b8f89d018d9b3a61320b0fd303b8e0bdf73 100644 (file)
@@ -39,7 +39,7 @@ static void packet_to_pc_item(const char *buffer, int len,
        }
 
        memset(pc_item, 0, sizeof(*pc_item));
-       pc_item->ce = make_empty_transient_cache_entry(fixed_portion->name_len);
+       pc_item->ce = make_empty_transient_cache_entry(fixed_portion->name_len, NULL);
        pc_item->ce->ce_namelen = fixed_portion->name_len;
        pc_item->ce->ce_mode = fixed_portion->ce_mode;
        memcpy(pc_item->ce->name, variant, pc_item->ce->ce_namelen);
index 4c696ef4805b73a30c2ba19e7b3319a836b1c169..db667d0267380924c26c4bee71fb0a636cb15cc8 100644 (file)
@@ -291,7 +291,7 @@ static int checkout_merged(int pos, const struct checkout *state, int *nr_checko
        if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
                die(_("Unable to add merge result for '%s'"), path);
        free(result_buf.ptr);
-       ce = make_transient_cache_entry(mode, &oid, path, 2);
+       ce = make_transient_cache_entry(mode, &oid, path, 2, NULL);
        if (!ce)
                die(_("make_cache_entry failed for path '%s'"), path);
        status = checkout_entry(ce, state, NULL, nr_checkouts);
index ef25729d4966fa9ac8361e6c96656fd071c5c97e..afacbcd581857d79c28c72486627f0d29fe923a5 100644 (file)
@@ -323,7 +323,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,
        struct cache_entry *ce;
        int ret;
 
-       ce = make_transient_cache_entry(mode, oid, path, 0);
+       ce = make_transient_cache_entry(mode, oid, path, 0, NULL);
        ret = checkout_entry(ce, state, NULL, NULL);
 
        discard_cache_entry(ce);
diff --git a/cache.h b/cache.h
index 148d9ab5f185d8fd1934e4b24ac7dae9c85933ac..d6dab6c87f36293eb65b3b2a457ed18caba3eee0 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -356,16 +356,20 @@ struct cache_entry *make_empty_cache_entry(struct index_state *istate,
                                           size_t name_len);
 
 /*
- * Create a cache_entry that is not intended to be added to an index.
- * Caller is responsible for discarding the cache_entry
- * with `discard_cache_entry`.
+ * Create a cache_entry that is not intended to be added to an index. If
+ * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
+ * pool. Caller is responsible for discarding "loose" entries with
+ * `discard_cache_entry()` and the memory pool with
+ * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
  */
 struct cache_entry *make_transient_cache_entry(unsigned int mode,
                                               const struct object_id *oid,
                                               const char *path,
-                                              int stage);
+                                              int stage,
+                                              struct mem_pool *ce_mem_pool);
 
-struct cache_entry *make_empty_transient_cache_entry(size_t name_len);
+struct cache_entry *make_empty_transient_cache_entry(size_t len,
+                                                    struct mem_pool *ce_mem_pool);
 
 /*
  * Discard cache entry.
index 5a907af2fb52f53d2e533edeec5f9ed470f8ba31..b46be4abcbe5383a05b9dbcb5b6a966cfeac9930 100644 (file)
@@ -813,8 +813,11 @@ struct cache_entry *make_empty_cache_entry(struct index_state *istate, size_t le
        return mem_pool__ce_calloc(find_mem_pool(istate), len);
 }
 
-struct cache_entry *make_empty_transient_cache_entry(size_t len)
+struct cache_entry *make_empty_transient_cache_entry(size_t len,
+                                                    struct mem_pool *ce_mem_pool)
 {
+       if (ce_mem_pool)
+               return mem_pool__ce_calloc(ce_mem_pool, len);
        return xcalloc(1, cache_entry_size(len));
 }
 
@@ -848,8 +851,11 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
        return ret;
 }
 
-struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct object_id *oid,
-                                              const char *path, int stage)
+struct cache_entry *make_transient_cache_entry(unsigned int mode,
+                                              const struct object_id *oid,
+                                              const char *path,
+                                              int stage,
+                                              struct mem_pool *ce_mem_pool)
 {
        struct cache_entry *ce;
        int len;
@@ -860,7 +866,7 @@ struct cache_entry *make_transient_cache_entry(unsigned int mode, const struct o
        }
 
        len = strlen(path);
-       ce = make_empty_transient_cache_entry(len);
+       ce = make_empty_transient_cache_entry(len, ce_mem_pool);
 
        oidcpy(&ce->oid, oid);
        memcpy(ce->name, path, len);
index 4b77e52c6b9e3e6cf1436daa4d3b9f912d1a2f3e..fa5b7ab7eed848617506ee2a5a425a0e1dab1d5d 100644 (file)
@@ -1034,7 +1034,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info,
        size_t len = traverse_path_len(info, tree_entry_len(n));
        struct cache_entry *ce =
                is_transient ?
-               make_empty_transient_cache_entry(len) :
+               make_empty_transient_cache_entry(len, NULL) :
                make_empty_cache_entry(istate, len);
 
        ce->ce_mode = create_ce_mode(n->mode);