Skip to content

Commit

Permalink
midx: clear midx on repack
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
derrickstolee committed Jul 5, 2018
1 parent 77d13a6 commit d6de454
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "strbuf.h"
#include "string-list.h"
#include "argv-array.h"
#include "midx.h"

static int delta_base_offset = 1;
static int pack_kept_objects = -1;
Expand Down Expand Up @@ -174,6 +175,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
int no_update_server_info = 0;
int quiet = 0;
int local = 0;
int midx_cleared = 0;

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

if (!midx_cleared) {
/* if we move a packfile, it will invalidated the midx */
clear_midx_file(get_object_directory());
midx_cleared = 1;
}

fname_old = mkpathdup("%s/old-%s%s", packdir,
item->string, exts[ext].name);
if (file_exists(fname_old))
Expand Down
12 changes: 12 additions & 0 deletions midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,15 @@ int write_midx_file(const char *object_dir)
free(midx_name);
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 change: 1 addition & 0 deletions midx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,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 write_midx_file(const char *object_dir);
void clear_midx_file(const char *object_dir);

#endif

0 comments on commit d6de454

Please sign in to comment.