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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jul 12, 2018 at 15:39 UTC
525e18c04bb38450e6677bb2aa5c65b78254b5c2
4 files changed
+31
builtin/repack.c
+9
@@ -8,6 +8,7 @@
8
#include "strbuf.h"
9
#include "string-list.h"
10
#include "argv-array.h"
11
+#include "midx.h"
12
13
static int delta_base_offset = 1;
14
static int pack_kept_objects = -1;
@@ -174,6 +175,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
175
int no_update_server_info = 0;
176
int quiet = 0;
177
int local = 0;
178
+ int midx_cleared = 0;
179
180
struct option builtin_repack_options[] = {
181
OPT_BIT('a', NULL, &pack_everything,
@@ -333,6 +335,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
335
for_each_string_list_item(item, &names) {
336
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
337
char *fname, *fname_old;
338
+
339
+ if (!midx_cleared) {
340
+ /* if we move a packfile, it will invalidated the midx */
341
+ clear_midx_file(get_object_directory());
342
+ midx_cleared = 1;
343
+ }
344
+
345
fname = mkpathdup("%s/pack-%s%s", packdir,
346
item->string, exts[ext].name);
347
if (!file_exists(fname)) {
midx.c
+12
@@ -904,3 +904,15 @@ cleanup:
904
free(midx_name);
905
return 0;
906
}
907
+
908
+void clear_midx_file(const char *object_dir)
909
+{
910
+ char *midx = get_midx_filename(object_dir);
911
+
912
+ if (remove_path(midx)) {
913
+ UNLEAK(midx);
914
+ die(_("failed to clear multi-pack-index at %s"), midx);
915
+ }
916
+
917
+ free(midx);
918
+}
midx.h
+1
@@ -39,5 +39,6 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
39
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
40
41
int write_midx_file(const char *object_dir);
42
+void clear_midx_file(const char *object_dir);
43
44
#endif
t/t5319-multi-pack-index.sh
+9
@@ -141,6 +141,15 @@ test_expect_success 'write midx with twelve packs' '
141
142
compare_results_with_midx "twelve packs"
143
144
+test_expect_success 'repack removes multi-pack-index' '
145
+ test_path_is_file $objdir/pack/multi-pack-index &&
146
+ git repack -adf &&
147
+ test_path_is_missing $objdir/pack/multi-pack-index
148
+'
149
+
150
+compare_results_with_midx "after repack"
151
+
152
+
153
# usage: corrupt_data <file> <pos> [<data>]
154
corrupt_data () {
155
file=$1