Skip to content

Commit

Permalink
Merge branch 'jk/repack-pack-keep-objects'
Browse files Browse the repository at this point in the history
Recent updates to "git repack" started to duplicate objects that
are in packfiles marked with .keep flag into the new packfile by
mistake.

* jk/repack-pack-keep-objects:
  repack: s/write_bitmap/&s/ in code
  repack: respect pack.writebitmaps
  repack: do not accidentally pack kept objects by default
  • Loading branch information
Junio C Hamano committed Jun 25, 2014
2 parents 9ce7100 + d078d85 commit b7ce583
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
14 changes: 9 additions & 5 deletions builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

static int delta_base_offset = 1;
static int pack_kept_objects = -1;
static int write_bitmaps = -1;
static char *packdir, *packtmp;

static const char *const git_repack_usage[] = {
Expand All @@ -27,6 +28,10 @@ static int repack_config(const char *var, const char *value, void *cb)
pack_kept_objects = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "pack.writebitmaps")) {
write_bitmaps = git_config_bool(var, value);
return 0;
}
return git_default_config(var, value, cb);
}

Expand Down Expand Up @@ -149,7 +154,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
int no_update_server_info = 0;
int quiet = 0;
int local = 0;
int write_bitmap = -1;

struct option builtin_repack_options[] = {
OPT_BIT('a', NULL, &pack_everything,
Expand All @@ -168,7 +172,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
OPT__QUIET(&quiet, N_("be quiet")),
OPT_BOOL('l', "local", &local,
N_("pass --local to git-pack-objects")),
OPT_BOOL('b', "write-bitmap-index", &write_bitmap,
OPT_BOOL('b', "write-bitmap-index", &write_bitmaps,
N_("write bitmap index")),
OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
N_("with -A, do not loosen objects older than this")),
Expand All @@ -191,7 +195,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
git_repack_usage, 0);

if (pack_kept_objects < 0)
pack_kept_objects = write_bitmap;
pack_kept_objects = write_bitmaps > 0;

packdir = mkpathdup("%s/pack", get_object_directory());
packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
Expand All @@ -217,9 +221,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
argv_array_pushf(&cmd_args, "--no-reuse-delta");
if (no_reuse_object)
argv_array_pushf(&cmd_args, "--no-reuse-object");
if (write_bitmap >= 0)
if (write_bitmaps >= 0)
argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
write_bitmap ? "" : "no-");
write_bitmaps ? "" : "no-");

if (pack_everything & ALL_INTO_ONE) {
get_non_kept_pack_filenames(&existing_packs);
Expand Down
20 changes: 18 additions & 2 deletions t/t7700-repack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,25 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
test -z "$found_duplicate_object"
'

test_expect_success 'writing bitmaps can duplicate .keep objects' '
test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
# build on $objsha1, $packsha1, and .keep state from previous
git repack -Adl &&
git repack -Adbl &&
test_when_finished "found_duplicate_object=" &&
for p in .git/objects/pack/*.idx; do
idx=$(basename $p)
test "pack-$packsha1.idx" = "$idx" && continue
if git verify-pack -v $p | egrep "^$objsha1"; then
found_duplicate_object=1
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test "$found_duplicate_object" = 1
'

test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
# build on $objsha1, $packsha1, and .keep state from previous
git -c pack.writebitmaps=true repack -Adl &&
test_when_finished "found_duplicate_object=" &&
for p in .git/objects/pack/*.idx; do
idx=$(basename $p)
Expand Down

0 comments on commit b7ce583

Please sign in to comment.