Skip to content

Commit d54fd59

Browse files
committed
Merge branch 'tb/fix-midx-rename-while-mapped'
The codepath to write a new version of .midx multi-pack index files has learned to release the mmaped memory holding the current version of .midx before removing them from the disk, as some platforms do not allow removal of a file that still has mapping. * tb/fix-midx-rename-while-mapped: midx.c: guard against commit_lock_file() failures midx.c: lookup MIDX by object directory during repack midx.c: lookup MIDX by object directory during expire midx.c: extract MIDX lookup by object_dir
2 parents 67f310e + ae22e84 commit d54fd59

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

midx.c

Lines changed: 23 additions & 19 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)) {
@@ -1416,7 +1423,8 @@ static int write_midx_internal(const char *object_dir,
14161423
if (ctx.m)
14171424
close_object_store(the_repository->objects);
14181425

1419-
commit_lock_file(&lk);
1426+
if (commit_lock_file(&lk) < 0)
1427+
die_errno(_("could not write multi-pack-index"));
14201428

14211429
clear_midx_files_ext(object_dir, ".bitmap", midx_hash);
14221430
clear_midx_files_ext(object_dir, ".rev", midx_hash);
@@ -1689,7 +1697,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
16891697
{
16901698
uint32_t i, *count, result = 0;
16911699
struct string_list packs_to_drop = STRING_LIST_INIT_DUP;
1692-
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
1700+
struct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);
16931701
struct progress *progress = NULL;
16941702

16951703
if (!m)
@@ -1734,12 +1742,11 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
17341742

17351743
free(count);
17361744

1737-
if (packs_to_drop.nr) {
1745+
if (packs_to_drop.nr)
17381746
result = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags);
1739-
m = NULL;
1740-
}
17411747

17421748
string_list_clear(&packs_to_drop, 0);
1749+
17431750
return result;
17441751
}
17451752

@@ -1855,7 +1862,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
18551862
struct child_process cmd = CHILD_PROCESS_INIT;
18561863
FILE *cmd_in;
18571864
struct strbuf base_name = STRBUF_INIT;
1858-
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
1865+
struct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);
18591866

18601867
/*
18611868
* When updating the default for these configuration
@@ -1927,11 +1934,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
19271934
}
19281935

19291936
result = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags);
1930-
m = NULL;
19311937

19321938
cleanup:
1933-
if (m)
1934-
close_midx(m);
19351939
free(include_pack);
19361940
return result;
19371941
}

0 commit comments

Comments
 (0)