Skip to content

Commit 6fb22ca

Browse files
ttaylorrgitster
authored andcommitted
builtin/multi-pack-index.c: support --stdin-packs mode
To power a new `--write-midx` mode, `git repack` will want to write a multi-pack index containing a certain set of packs in the repository. This new option will be used by `git repack` to write a MIDX which contains only the packs which will survive after the repack (that is, it will exclude any packs which are about to be deleted). This patch effectively exposes the function implemented in the previous commit via the `git multi-pack-index` builtin. An alternative approach would have been to call that function from the `git repack` builtin directly, but this introduces awkward problems around closing and reopening the object store, so the MIDX will be written out-of-process. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56d863e commit 6fb22ca

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Documentation/git-multi-pack-index.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ 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.
4852
--
4953

5054
verify::

builtin/multi-pack-index.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static struct opts_multi_pack_index {
4747
const char *preferred_pack;
4848
unsigned long batch_size;
4949
unsigned flags;
50+
int stdin_packs;
5051
} opts;
5152

5253
static struct option common_opts[] = {
@@ -61,6 +62,16 @@ static struct option *add_common_options(struct option *prev)
6162
return parse_options_concat(common_opts, prev);
6263
}
6364

65+
static void read_packs_from_stdin(struct string_list *to)
66+
{
67+
struct strbuf buf = STRBUF_INIT;
68+
while (strbuf_getline(&buf, stdin) != EOF)
69+
string_list_append(to, buf.buf);
70+
string_list_sort(to);
71+
72+
strbuf_release(&buf);
73+
}
74+
6475
static int cmd_multi_pack_index_write(int argc, const char **argv)
6576
{
6677
struct option *options;
@@ -70,6 +81,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
7081
N_("pack for reuse when computing a multi-pack bitmap")),
7182
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
7283
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
84+
OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
85+
N_("write multi-pack index containing only given indexes")),
7386
OPT_END(),
7487
};
7588

@@ -86,6 +99,20 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
8699

87100
FREE_AND_NULL(options);
88101

102+
if (opts.stdin_packs) {
103+
struct string_list packs = STRING_LIST_INIT_DUP;
104+
int ret;
105+
106+
read_packs_from_stdin(&packs);
107+
108+
ret = write_midx_file_only(opts.object_dir, &packs,
109+
opts.preferred_pack, opts.flags);
110+
111+
string_list_clear(&packs, 0);
112+
113+
return ret;
114+
115+
}
89116
return write_midx_file(opts.object_dir, opts.preferred_pack,
90117
opts.flags);
91118
}

t/t5319-multi-pack-index.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ test_expect_success 'write midx with two packs' '
168168

169169
compare_results_with_midx "two packs"
170170

171+
test_expect_success 'write midx with --stdin-packs' '
172+
rm -fr $objdir/pack/multi-pack-index &&
173+
174+
idx="$(find $objdir/pack -name "test-2-*.idx")" &&
175+
basename "$idx" >in &&
176+
177+
git multi-pack-index write --stdin-packs <in &&
178+
179+
test-tool read-midx $objdir | grep "\.idx$" >packs &&
180+
181+
test_cmp packs in
182+
'
183+
184+
compare_results_with_midx "mixed mode (one pack + extra)"
185+
171186
test_expect_success 'write progress off for redirected stderr' '
172187
git multi-pack-index --object-dir=$objdir write 2>err &&
173188
test_line_count = 0 err

0 commit comments

Comments
 (0)