Skip to content

Commit 249d54b

Browse files
committed
Merge branch 'jk/repack-pack-keep-objects'
* jk/repack-pack-keep-objects: repack: add `repack.packKeptObjects` config var
2 parents f4eec8c + ee34a2b commit 249d54b

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,13 @@ repack.usedeltabaseoffset::
21562156
"false" and repack. Access from old Git versions over the
21572157
native protocol are unaffected by this option.
21582158

2159+
repack.packKeptObjects::
2160+
If set to true, makes `git repack` act as if
2161+
`--pack-kept-objects` was passed. See linkgit:git-repack[1] for
2162+
details. Defaults to `false` normally, but `true` if a bitmap
2163+
index is being written (either via `--write-bitmap-index` or
2164+
`pack.writeBitmaps`).
2165+
21592166
rerere.autoupdate::
21602167
When set to true, `git-rerere` updates the index with the
21612168
resulting contents after it cleanly resolves conflicts using

Documentation/git-repack.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ other objects in that pack they already have locally.
117117
must be able to refer to all reachable objects. This option
118118
overrides the setting of `pack.writebitmaps`.
119119

120+
--pack-kept-objects::
121+
Include objects in `.keep` files when repacking. Note that we
122+
still do not delete `.keep` packs after `pack-objects` finishes.
123+
This means that we may duplicate objects, but this makes the
124+
option safe to use when there are concurrent pushes or fetches.
125+
This option is generally only useful if you are writing bitmaps
126+
with `-b` or `pack.writebitmaps`, as it ensures that the
127+
bitmapped packfile has the necessary objects.
120128

121129
Configuration
122130
-------------

builtin/repack.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "argv-array.h"
1010

1111
static int delta_base_offset = 1;
12+
static int pack_kept_objects = -1;
1213
static char *packdir, *packtmp;
1314

1415
static const char *const git_repack_usage[] = {
@@ -22,6 +23,10 @@ static int repack_config(const char *var, const char *value, void *cb)
2223
delta_base_offset = git_config_bool(var, value);
2324
return 0;
2425
}
26+
if (!strcmp(var, "repack.packkeptobjects")) {
27+
pack_kept_objects = git_config_bool(var, value);
28+
return 0;
29+
}
2530
return git_default_config(var, value, cb);
2631
}
2732

@@ -175,6 +180,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
175180
N_("limits the maximum delta depth")),
176181
OPT_STRING(0, "max-pack-size", &max_pack_size, N_("bytes"),
177182
N_("maximum size of each packfile")),
183+
OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
184+
N_("repack objects in packs marked with .keep")),
178185
OPT_END()
179186
};
180187

@@ -183,14 +190,18 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
183190
argc = parse_options(argc, argv, prefix, builtin_repack_options,
184191
git_repack_usage, 0);
185192

193+
if (pack_kept_objects < 0)
194+
pack_kept_objects = write_bitmap;
195+
186196
packdir = mkpathdup("%s/pack", get_object_directory());
187197
packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
188198

189199
sigchain_push_common(remove_pack_on_signal);
190200

191201
argv_array_push(&cmd_args, "pack-objects");
192202
argv_array_push(&cmd_args, "--keep-true-parents");
193-
argv_array_push(&cmd_args, "--honor-pack-keep");
203+
if (!pack_kept_objects)
204+
argv_array_push(&cmd_args, "--honor-pack-keep");
194205
argv_array_push(&cmd_args, "--non-empty");
195206
argv_array_push(&cmd_args, "--all");
196207
argv_array_push(&cmd_args, "--reflog");

t/t7700-repack.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
2121
objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
2222
sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
2323
mv pack-* .git/objects/pack/ &&
24-
git repack -A -d -l &&
24+
git repack --no-pack-kept-objects -A -d -l &&
2525
git prune-packed &&
2626
for p in .git/objects/pack/*.idx; do
2727
idx=$(basename $p)
@@ -35,6 +35,22 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
3535
test -z "$found_duplicate_object"
3636
'
3737

38+
test_expect_success 'writing bitmaps can duplicate .keep objects' '
39+
# build on $objsha1, $packsha1, and .keep state from previous
40+
git repack -Adl &&
41+
test_when_finished "found_duplicate_object=" &&
42+
for p in .git/objects/pack/*.idx; do
43+
idx=$(basename $p)
44+
test "pack-$packsha1.idx" = "$idx" && continue
45+
if git verify-pack -v $p | egrep "^$objsha1"; then
46+
found_duplicate_object=1
47+
echo "DUPLICATE OBJECT FOUND"
48+
break
49+
fi
50+
done &&
51+
test "$found_duplicate_object" = 1
52+
'
53+
3854
test_expect_success 'loose objects in alternate ODB are not repacked' '
3955
mkdir alt_objects &&
4056
echo `pwd`/alt_objects > .git/objects/info/alternates &&

0 commit comments

Comments
 (0)