Skip to content

Commit 504131a

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 823b428 commit 504131a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

midx.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,22 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
11071107
return ret;
11081108
}
11091109

1110+
static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
1111+
const char *object_dir)
1112+
{
1113+
struct multi_pack_index *cur;
1114+
1115+
/* Ensure the given object_dir is local, or a known alternate. */
1116+
find_odb(r, object_dir);
1117+
1118+
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
1119+
if (!strcmp(object_dir, cur->object_dir))
1120+
return cur;
1121+
}
1122+
1123+
return NULL;
1124+
}
1125+
11101126
static int write_midx_internal(const char *object_dir,
11111127
struct string_list *packs_to_include,
11121128
struct string_list *packs_to_drop,
@@ -1120,15 +1136,11 @@ static int write_midx_internal(const char *object_dir,
11201136
struct hashfile *f = NULL;
11211137
struct lock_file lk;
11221138
struct write_midx_context ctx = { 0 };
1123-
struct multi_pack_index *cur;
11241139
int pack_name_concat_len = 0;
11251140
int dropped_packs = 0;
11261141
int result = 0;
11271142
struct chunkfile *cf;
11281143

1129-
/* Ensure the given object_dir is local, or a known alternate. */
1130-
find_odb(the_repository, object_dir);
1131-
11321144
midx_name = get_midx_filename(object_dir);
11331145
if (safe_create_leading_directories(midx_name))
11341146
die_errno(_("unable to create leading directories of %s"),
@@ -1140,12 +1152,7 @@ static int write_midx_internal(const char *object_dir,
11401152
* packs to include, since all packs and objects are copied
11411153
* blindly from an existing MIDX if one is present.
11421154
*/
1143-
for (cur = get_multi_pack_index(the_repository); cur; cur = cur->next) {
1144-
if (!strcmp(object_dir, cur->object_dir)) {
1145-
ctx.m = cur;
1146-
break;
1147-
}
1148-
}
1155+
ctx.m = lookup_multi_pack_index(the_repository, object_dir);
11491156
}
11501157

11511158
if (ctx.m && !midx_checksum_valid(ctx.m)) {

0 commit comments

Comments
 (0)