Skip to content

Commit d6de454

Browse files
committed
midx: clear midx on repack
If a 'git repack' command replaces existing packfiles, then we must clear the existing multi-pack-index before moving the packfiles it references. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 77d13a6 commit d6de454

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

builtin/repack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "strbuf.h"
99
#include "string-list.h"
1010
#include "argv-array.h"
11+
#include "midx.h"
1112

1213
static int delta_base_offset = 1;
1314
static int pack_kept_objects = -1;
@@ -174,6 +175,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
174175
int no_update_server_info = 0;
175176
int quiet = 0;
176177
int local = 0;
178+
int midx_cleared = 0;
177179

178180
struct option builtin_repack_options[] = {
179181
OPT_BIT('a', NULL, &pack_everything,
@@ -340,6 +342,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
340342
continue;
341343
}
342344

345+
if (!midx_cleared) {
346+
/* if we move a packfile, it will invalidated the midx */
347+
clear_midx_file(get_object_directory());
348+
midx_cleared = 1;
349+
}
350+
343351
fname_old = mkpathdup("%s/old-%s%s", packdir,
344352
item->string, exts[ext].name);
345353
if (file_exists(fname_old))

midx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,3 +903,15 @@ int write_midx_file(const char *object_dir)
903903
free(midx_name);
904904
return 0;
905905
}
906+
907+
void clear_midx_file(const char *object_dir)
908+
{
909+
char *midx = get_midx_filename(object_dir);
910+
911+
if (remove_path(midx)) {
912+
UNLEAK(midx);
913+
die(_("failed to clear multi-pack-index at %s"), midx);
914+
}
915+
916+
free(midx);
917+
}

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
1515
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
1616

1717
int write_midx_file(const char *object_dir);
18+
void clear_midx_file(const char *object_dir);
1819

1920
#endif

0 commit comments

Comments
 (0)