Skip to content

Commit 5cf2741

Browse files
vmggitster
authored andcommitted
repack: consider bitmaps when performing repacks
Since `pack-objects` will write a `.bitmap` file next to the `.pack` and `.idx` files, this commit teaches `git-repack` to consider the new bitmap indexes (if they exist) when performing repack operations. This implies moving old bitmap indexes out of the way if we are repacking a repository that already has them, and moving the newly generated bitmap indexes into the `objects/pack` directory, next to their corresponding packfiles. Since `git repack` is now capable of handling these `.bitmap` files, a normal `git gc` run on a repository that has `pack.writebitmaps` set to true in its config file will generate bitmap indexes as part of the garbage collection process. Alternatively, `git repack` can be called with the `-b` switch to explicitly generate bitmap indexes if you are experimenting and don't want them on all the time. Signed-off-by: Vicent Marti <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b77fcd1 commit 5cf2741

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Documentation/git-repack.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-repack - Pack unpacked objects in a repository
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [--window=<n>] [--depth=<n>]
12+
'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [--window=<n>] [--depth=<n>]
1313

1414
DESCRIPTION
1515
-----------
@@ -110,6 +110,13 @@ other objects in that pack they already have locally.
110110
The default is unlimited, unless the config variable
111111
`pack.packSizeLimit` is set.
112112

113+
-b::
114+
--write-bitmap-index::
115+
Write a reachability bitmap index as part of the repack. This
116+
only makes sense when used with `-a` or `-A`, as the bitmaps
117+
must be able to refer to all reachable objects. This option
118+
overrides the setting of `pack.writebitmaps`.
119+
113120

114121
Configuration
115122
-------------

builtin/repack.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
9494

9595
static void remove_redundant_pack(const char *dir_name, const char *base_name)
9696
{
97-
const char *exts[] = {".pack", ".idx", ".keep"};
97+
const char *exts[] = {".pack", ".idx", ".keep", ".bitmap"};
9898
int i;
9999
struct strbuf buf = STRBUF_INIT;
100100
size_t plen;
@@ -121,6 +121,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
121121
} exts[] = {
122122
{".pack"},
123123
{".idx"},
124+
{".bitmap", 1},
124125
};
125126
struct child_process cmd;
126127
struct string_list_item *item;
@@ -143,6 +144,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
143144
int no_update_server_info = 0;
144145
int quiet = 0;
145146
int local = 0;
147+
int write_bitmap = -1;
146148

147149
struct option builtin_repack_options[] = {
148150
OPT_BIT('a', NULL, &pack_everything,
@@ -161,6 +163,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
161163
OPT__QUIET(&quiet, N_("be quiet")),
162164
OPT_BOOL('l', "local", &local,
163165
N_("pass --local to git-pack-objects")),
166+
OPT_BOOL('b', "write-bitmap-index", &write_bitmap,
167+
N_("write bitmap index")),
164168
OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
165169
N_("with -A, do not loosen objects older than this")),
166170
OPT_INTEGER(0, "window", &window,
@@ -202,6 +206,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
202206
argv_array_pushf(&cmd_args, "--no-reuse-delta");
203207
if (no_reuse_object)
204208
argv_array_pushf(&cmd_args, "--no-reuse-object");
209+
if (write_bitmap >= 0)
210+
argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
211+
write_bitmap ? "" : "no-");
205212

206213
if (pack_everything & ALL_INTO_ONE) {
207214
get_non_kept_pack_filenames(&existing_packs);

0 commit comments

Comments
 (0)