Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2021-10-09 00:46:29 +0300
committerJunio C Hamano <gitster@pobox.com>2021-10-15 23:08:11 +0300
commit504131ac26895d1aaa814785d455c2c7f61c4e16 (patch)
tree2f02c828b2ca7d48437111fdde8aa3ba77c834b7 /midx.c
parent823b4281ca259788f2dc71bfd2b459a1b14e46f6 (diff)
midx.c: extract MIDX lookup by object_dir
The first thing that write_midx_internal() does is load the MIDX corresponding to the given object directory, if one is present. Prepare for other functions in midx.c to do the same thing by extracting that operation out to a small helper function. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/midx.c b/midx.c
index 7e06e85975..cc2ae7e96b 100644
--- a/midx.c
+++ b/midx.c
@@ -1107,6 +1107,22 @@ cleanup:
return ret;
}
+static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
+ const char *object_dir)
+{
+ struct multi_pack_index *cur;
+
+ /* Ensure the given object_dir is local, or a known alternate. */
+ find_odb(r, object_dir);
+
+ for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
+ if (!strcmp(object_dir, cur->object_dir))
+ return cur;
+ }
+
+ return NULL;
+}
+
static int write_midx_internal(const char *object_dir,
struct string_list *packs_to_include,
struct string_list *packs_to_drop,
@@ -1120,15 +1136,11 @@ static int write_midx_internal(const char *object_dir,
struct hashfile *f = NULL;
struct lock_file lk;
struct write_midx_context ctx = { 0 };
- struct multi_pack_index *cur;
int pack_name_concat_len = 0;
int dropped_packs = 0;
int result = 0;
struct chunkfile *cf;
- /* Ensure the given object_dir is local, or a known alternate. */
- find_odb(the_repository, object_dir);
-
midx_name = get_midx_filename(object_dir);
if (safe_create_leading_directories(midx_name))
die_errno(_("unable to create leading directories of %s"),
@@ -1140,12 +1152,7 @@ static int write_midx_internal(const char *object_dir,
* packs to include, since all packs and objects are copied
* blindly from an existing MIDX if one is present.
*/
- for (cur = get_multi_pack_index(the_repository); cur; cur = cur->next) {
- if (!strcmp(object_dir, cur->object_dir)) {
- ctx.m = cur;
- break;
- }
- }
+ ctx.m = lookup_multi_pack_index(the_repository, object_dir);
}
if (ctx.m && !midx_checksum_valid(ctx.m)) {