Skip to content

Commit 823b428

Browse files
committed
Merge branch 'tb/repack-write-midx' into tb/fix-midx-rename-while-mapped
* tb/repack-write-midx: test-read-midx: fix leak of bitmap_index struct builtin/repack.c: pass `--refs-snapshot` when writing bitmaps builtin/repack.c: make largest pack preferred builtin/repack.c: support writing a MIDX while repacking builtin/repack.c: extract showing progress to a variable builtin/repack.c: rename variables that deal with non-kept packs builtin/repack.c: keep track of existing packs unconditionally midx: preliminary support for `--refs-snapshot` builtin/multi-pack-index.c: support `--stdin-packs` mode midx: expose `write_midx_file_only()` publicly
2 parents f443b22 + e861b09 commit 823b428

14 files changed

+723
-56
lines changed

Documentation/git-multi-pack-index.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ write::
4545

4646
--[no-]bitmap::
4747
Control whether or not a multi-pack bitmap is written.
48+
49+
--stdin-packs::
50+
Write a multi-pack index containing only the set of
51+
line-delimited pack index basenames provided over stdin.
52+
53+
--refs-snapshot=<path>::
54+
With `--bitmap`, optionally specify a file which
55+
contains a "refs snapshot" taken prior to repacking.
56+
+
57+
A reference snapshot is composed of line-delimited OIDs corresponding to
58+
the reference tips, usually taken by `git repack` prior to generating a
59+
new pack. A line may optionally start with a `+` character to indicate
60+
that the reference which corresponds to that OID is "preferred" (see
61+
linkgit:git-config[1]'s `pack.preferBitmapTips`.)
62+
+
63+
The file given at `<path>` is expected to be readable, and can contain
64+
duplicates. (If a given OID is given more than once, it is marked as
65+
preferred if at least one instance of it begins with the special `+`
66+
marker).
4867
--
4968

5069
verify::

Documentation/git-repack.txt

Lines changed: 14 additions & 4 deletions
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] [-b] [--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
12+
'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m] [--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>] [--write-midx]
1313

1414
DESCRIPTION
1515
-----------
@@ -128,10 +128,11 @@ depth is 4095.
128128
-b::
129129
--write-bitmap-index::
130130
Write a reachability bitmap index as part of the repack. This
131-
only makes sense when used with `-a` or `-A`, as the bitmaps
131+
only makes sense when used with `-a`, `-A` or `-m`, as the bitmaps
132132
must be able to refer to all reachable objects. This option
133-
overrides the setting of `repack.writeBitmaps`. This option
134-
has no effect if multiple packfiles are created.
133+
overrides the setting of `repack.writeBitmaps`. This option
134+
has no effect if multiple packfiles are created, unless writing a
135+
MIDX (in which case a multi-pack bitmap is created).
135136

136137
--pack-kept-objects::
137138
Include objects in `.keep` files when repacking. Note that we
@@ -189,6 +190,15 @@ this "roll-up", without respect to their reachability. This is subject
189190
to change in the future. This option (implying a drastically different
190191
repack mode) is not guaranteed to work with all other combinations of
191192
option to `git repack`.
193+
+
194+
When writing a multi-pack bitmap, `git repack` selects the largest resulting
195+
pack as the preferred pack for object selection by the MIDX (see
196+
linkgit:git-multi-pack-index[1]).
197+
198+
-m::
199+
--write-midx::
200+
Write a multi-pack index (see linkgit:git-multi-pack-index[1])
201+
containing the non-redundant packs.
192202

193203
CONFIGURATION
194204
-------------

builtin/multi-pack-index.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "object-store.h"
88

99
#define BUILTIN_MIDX_WRITE_USAGE \
10-
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]")
10+
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
11+
"[--refs-snapshot=<path>]")
1112

1213
#define BUILTIN_MIDX_VERIFY_USAGE \
1314
N_("git multi-pack-index [<options>] verify")
@@ -45,8 +46,10 @@ static char const * const builtin_multi_pack_index_usage[] = {
4546
static struct opts_multi_pack_index {
4647
const char *object_dir;
4748
const char *preferred_pack;
49+
const char *refs_snapshot;
4850
unsigned long batch_size;
4951
unsigned flags;
52+
int stdin_packs;
5053
} opts;
5154

5255
static struct option common_opts[] = {
@@ -77,6 +80,16 @@ static int git_multi_pack_index_write_config(const char *var, const char *value,
7780
return 0;
7881
}
7982

83+
static void read_packs_from_stdin(struct string_list *to)
84+
{
85+
struct strbuf buf = STRBUF_INIT;
86+
while (strbuf_getline(&buf, stdin) != EOF)
87+
string_list_append(to, buf.buf);
88+
string_list_sort(to);
89+
90+
strbuf_release(&buf);
91+
}
92+
8093
static int cmd_multi_pack_index_write(int argc, const char **argv)
8194
{
8295
struct option *options;
@@ -88,6 +101,10 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
88101
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
89102
OPT_BIT(0, "progress", &opts.flags,
90103
N_("force progress reporting"), MIDX_PROGRESS),
104+
OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
105+
N_("write multi-pack index containing only given indexes")),
106+
OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
107+
N_("refs snapshot for selecting bitmap commits")),
91108
OPT_END(),
92109
};
93110

@@ -110,8 +127,23 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
110127

111128
FREE_AND_NULL(options);
112129

130+
if (opts.stdin_packs) {
131+
struct string_list packs = STRING_LIST_INIT_DUP;
132+
int ret;
133+
134+
read_packs_from_stdin(&packs);
135+
136+
ret = write_midx_file_only(opts.object_dir, &packs,
137+
opts.preferred_pack,
138+
opts.refs_snapshot, opts.flags);
139+
140+
string_list_clear(&packs, 0);
141+
142+
return ret;
143+
144+
}
113145
return write_midx_file(opts.object_dir, opts.preferred_pack,
114-
opts.flags);
146+
opts.refs_snapshot, opts.flags);
115147
}
116148

117149
static int cmd_multi_pack_index_verify(int argc, const char **argv)

0 commit comments

Comments
 (0)