diff options
author | René Scharfe <l.s.r@web.de> | 2023-02-10 21:20:30 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-02-10 21:24:12 +0100 |
commit | 93ea118bedf3f6d300520718250bf64d0e09a4ec (patch) | |
tree | d9edbeb8236f6f3b74b4f13873476f89d2442e09 /cache-tree.c | |
parent | Sync with maint-2.38 (diff) | |
download | git-93ea118bedf3f6d300520718250bf64d0e09a4ec.tar.xz git-93ea118bedf3f6d300520718250bf64d0e09a4ec.zip |
cache-tree: fix strbuf growth in prime_cache_tree_rec()
Use size_t to store the original length of the strbuf tree_len, as
that's the correct type.
Don't double the allocated size of the strbuf when adding a subdirectory
name. And the chance of the trailing slash fitting in the slack left by
strbuf_add() is very high, so stop pre-growing the strbuf at all.
Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r-- | cache-tree.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/cache-tree.c b/cache-tree.c index c97111cccf..ab90cb3127 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -760,7 +760,7 @@ static void prime_cache_tree_rec(struct repository *r, struct tree_desc desc; struct name_entry entry; int cnt; - int base_path_len = tree_path->len; + size_t base_path_len = tree_path->len; oidcpy(&it->oid, &tree->object.oid); @@ -785,7 +785,6 @@ static void prime_cache_tree_rec(struct repository *r, */ if (r->index->sparse_index) { strbuf_setlen(tree_path, base_path_len); - strbuf_grow(tree_path, base_path_len + entry.pathlen + 1); strbuf_add(tree_path, entry.path, entry.pathlen); strbuf_addch(tree_path, '/'); } |