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>
This commit is contained in:
parent
17c35c8969
commit
525e18c04b
@ -8,6 +8,7 @@
|
|||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "argv-array.h"
|
#include "argv-array.h"
|
||||||
|
#include "midx.h"
|
||||||
|
|
||||||
static int delta_base_offset = 1;
|
static int delta_base_offset = 1;
|
||||||
static int pack_kept_objects = -1;
|
static int pack_kept_objects = -1;
|
||||||
@ -174,6 +175,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||||||
int no_update_server_info = 0;
|
int no_update_server_info = 0;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
int local = 0;
|
int local = 0;
|
||||||
|
int midx_cleared = 0;
|
||||||
|
|
||||||
struct option builtin_repack_options[] = {
|
struct option builtin_repack_options[] = {
|
||||||
OPT_BIT('a', NULL, &pack_everything,
|
OPT_BIT('a', NULL, &pack_everything,
|
||||||
@ -333,6 +335,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
|||||||
for_each_string_list_item(item, &names) {
|
for_each_string_list_item(item, &names) {
|
||||||
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
|
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
|
||||||
char *fname, *fname_old;
|
char *fname, *fname_old;
|
||||||
|
|
||||||
|
if (!midx_cleared) {
|
||||||
|
/* if we move a packfile, it will invalidated the midx */
|
||||||
|
clear_midx_file(get_object_directory());
|
||||||
|
midx_cleared = 1;
|
||||||
|
}
|
||||||
|
|
||||||
fname = mkpathdup("%s/pack-%s%s", packdir,
|
fname = mkpathdup("%s/pack-%s%s", packdir,
|
||||||
item->string, exts[ext].name);
|
item->string, exts[ext].name);
|
||||||
if (!file_exists(fname)) {
|
if (!file_exists(fname)) {
|
||||||
|
12
midx.c
12
midx.c
@ -904,3 +904,15 @@ cleanup:
|
|||||||
free(midx_name);
|
free(midx_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear_midx_file(const char *object_dir)
|
||||||
|
{
|
||||||
|
char *midx = get_midx_filename(object_dir);
|
||||||
|
|
||||||
|
if (remove_path(midx)) {
|
||||||
|
UNLEAK(midx);
|
||||||
|
die(_("failed to clear multi-pack-index at %s"), midx);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(midx);
|
||||||
|
}
|
||||||
|
1
midx.h
1
midx.h
@ -39,5 +39,6 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
|
|||||||
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
|
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
|
||||||
|
|
||||||
int write_midx_file(const char *object_dir);
|
int write_midx_file(const char *object_dir);
|
||||||
|
void clear_midx_file(const char *object_dir);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -141,6 +141,15 @@ test_expect_success 'write midx with twelve packs' '
|
|||||||
|
|
||||||
compare_results_with_midx "twelve packs"
|
compare_results_with_midx "twelve packs"
|
||||||
|
|
||||||
|
test_expect_success 'repack removes multi-pack-index' '
|
||||||
|
test_path_is_file $objdir/pack/multi-pack-index &&
|
||||||
|
git repack -adf &&
|
||||||
|
test_path_is_missing $objdir/pack/multi-pack-index
|
||||||
|
'
|
||||||
|
|
||||||
|
compare_results_with_midx "after repack"
|
||||||
|
|
||||||
|
|
||||||
# usage: corrupt_data <file> <pos> [<data>]
|
# usage: corrupt_data <file> <pos> [<data>]
|
||||||
corrupt_data () {
|
corrupt_data () {
|
||||||
file=$1
|
file=$1
|
||||||
|
Loading…
Reference in New Issue
Block a user