Skip to content

Commit 105a22c

Browse files
committed
Merge branch 'tb/incremental-midx-part-3.2'
Further work on incremental repacking using MIDX/bitmap * tb/incremental-midx-part-3.2: midx: enable reachability bitmaps during MIDX compaction midx: implement MIDX compaction t/helper/test-read-midx.c: plug memory leak when selecting layer midx-write.c: factor fanout layering from `compute_sorted_entries()` midx-write.c: enumerate `pack_int_id` values directly midx-write.c: extract `fill_pack_from_midx()` midx-write.c: introduce `midx_pack_perm()` helper midx: do not require packs to be sorted in lexicographic order midx-write.c: introduce `struct write_midx_opts` midx-write.c: don't use `pack_perm` when assigning `bitmap_pos` t/t5319-multi-pack-index.sh: fix copy-and-paste error in t5319.39 git-multi-pack-index(1): align SYNOPSIS with 'git multi-pack-index -h' git-multi-pack-index(1): remove non-existent incompatibility builtin/multi-pack-index.c: make '--progress' a common option midx: introduce `midx_get_checksum_hex()` midx: rename `get_midx_checksum()` to `midx_get_checksum_hash()` midx: mark `get_midx_checksum()` arguments as const
2 parents ce74208 + d54da84 commit 105a22c

File tree

13 files changed

+891
-158
lines changed

13 files changed

+891
-158
lines changed

Documentation/git-multi-pack-index.adoc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ git-multi-pack-index - Write and verify multi-pack-indexes
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git multi-pack-index' [--object-dir=<dir>] [--[no-]bitmap] <sub-command>
12+
'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]
13+
[--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]
14+
[--refs-snapshot=<path>]
15+
'git multi-pack-index' [<options>] compact [--[no-]incremental]
16+
[--[no-]bitmap] <from> <to>
17+
'git multi-pack-index' [<options>] verify
18+
'git multi-pack-index' [<options>] expire
19+
'git multi-pack-index' [<options>] repack [--batch-size=<size>]
1320

1421
DESCRIPTION
1522
-----------
@@ -18,6 +25,8 @@ Write or verify a multi-pack-index (MIDX) file.
1825
OPTIONS
1926
-------
2027

28+
The following command-line options are applicable to all sub-commands:
29+
2130
--object-dir=<dir>::
2231
Use given directory for the location of Git objects. We check
2332
`<dir>/packs/multi-pack-index` for the current MIDX file, and
@@ -73,7 +82,21 @@ marker).
7382
Write an incremental MIDX file containing only objects
7483
and packs not present in an existing MIDX layer.
7584
Migrates non-incremental MIDXs to incremental ones when
76-
necessary. Incompatible with `--bitmap`.
85+
necessary.
86+
--
87+
88+
compact::
89+
Write a new MIDX layer containing only objects and packs present
90+
in the range `<from>` to `<to>`, where both arguments are
91+
checksums of existing layers in the MIDX chain.
92+
+
93+
--
94+
--incremental::
95+
Write the result to a MIDX chain instead of writing a
96+
stand-alone MIDX.
97+
98+
--[no-]bitmap::
99+
Control whether or not a multi-pack bitmap is written.
77100
--
78101

79102
verify::

Documentation/gitformat-pack.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ HEADER:
374374
The signature is: {'M', 'I', 'D', 'X'}
375375

376376
1-byte version number:
377-
Git only writes or recognizes version 1.
377+
Git writes the version specified by the "midx.version"
378+
configuration option, which defaults to 2. It recognizes
379+
both versions 1 and 2.
378380

379381
1-byte Object Id Version
380382
We infer the length of object IDs (OIDs) from this value:
@@ -413,7 +415,9 @@ CHUNK DATA:
413415
strings. There is no extra padding between the filenames,
414416
and they are listed in lexicographic order. The chunk itself
415417
is padded at the end with between 0 and 3 NUL bytes to make the
416-
chunk size a multiple of 4 bytes.
418+
chunk size a multiple of 4 bytes. Version 1 MIDXs are required to
419+
list their packs in lexicographic order, but version 2 MIDXs may
420+
list their packs in any arbitrary order.
417421

418422
Bitmapped Packfiles (ID: {'B', 'T', 'M', 'P'})
419423
Stores a table of two 4-byte unsigned integers in network order.

builtin/multi-pack-index.c

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313
#include "repository.h"
1414

1515
#define BUILTIN_MIDX_WRITE_USAGE \
16-
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
17-
"[--refs-snapshot=<path>]")
16+
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \
17+
" [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \
18+
" [--refs-snapshot=<path>]")
19+
20+
#define BUILTIN_MIDX_COMPACT_USAGE \
21+
N_("git multi-pack-index [<options>] compact [--[no-]incremental]\n" \
22+
" [--[no-]bitmap] <from> <to>")
1823

1924
#define BUILTIN_MIDX_VERIFY_USAGE \
2025
N_("git multi-pack-index [<options>] verify")
@@ -29,6 +34,10 @@ static char const * const builtin_multi_pack_index_write_usage[] = {
2934
BUILTIN_MIDX_WRITE_USAGE,
3035
NULL
3136
};
37+
static char const * const builtin_multi_pack_index_compact_usage[] = {
38+
BUILTIN_MIDX_COMPACT_USAGE,
39+
NULL
40+
};
3241
static char const * const builtin_multi_pack_index_verify_usage[] = {
3342
BUILTIN_MIDX_VERIFY_USAGE,
3443
NULL
@@ -43,6 +52,7 @@ static char const * const builtin_multi_pack_index_repack_usage[] = {
4352
};
4453
static char const * const builtin_multi_pack_index_usage[] = {
4554
BUILTIN_MIDX_WRITE_USAGE,
55+
BUILTIN_MIDX_COMPACT_USAGE,
4656
BUILTIN_MIDX_VERIFY_USAGE,
4757
BUILTIN_MIDX_EXPIRE_USAGE,
4858
BUILTIN_MIDX_REPACK_USAGE,
@@ -84,6 +94,8 @@ static struct option common_opts[] = {
8494
N_("directory"),
8595
N_("object directory containing set of packfile and pack-index pairs"),
8696
parse_object_dir),
97+
OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
98+
MIDX_PROGRESS),
8799
OPT_END(),
88100
};
89101

@@ -138,8 +150,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
138150
N_("pack for reuse when computing a multi-pack bitmap")),
139151
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
140152
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
141-
OPT_BIT(0, "progress", &opts.flags,
142-
N_("force progress reporting"), MIDX_PROGRESS),
143153
OPT_BIT(0, "incremental", &opts.flags,
144154
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
145155
OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
@@ -194,14 +204,78 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
194204
return ret;
195205
}
196206

207+
static int cmd_multi_pack_index_compact(int argc, const char **argv,
208+
const char *prefix,
209+
struct repository *repo)
210+
{
211+
struct multi_pack_index *m, *cur;
212+
struct multi_pack_index *from_midx = NULL;
213+
struct multi_pack_index *to_midx = NULL;
214+
struct odb_source *source;
215+
int ret;
216+
217+
struct option *options;
218+
static struct option builtin_multi_pack_index_compact_options[] = {
219+
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
220+
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
221+
OPT_BIT(0, "incremental", &opts.flags,
222+
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
223+
OPT_END(),
224+
};
225+
226+
repo_config(repo, git_multi_pack_index_write_config, NULL);
227+
228+
options = add_common_options(builtin_multi_pack_index_compact_options);
229+
230+
trace2_cmd_mode(argv[0]);
231+
232+
if (isatty(2))
233+
opts.flags |= MIDX_PROGRESS;
234+
argc = parse_options(argc, argv, prefix,
235+
options, builtin_multi_pack_index_compact_usage,
236+
0);
237+
238+
if (argc != 2)
239+
usage_with_options(builtin_multi_pack_index_compact_usage,
240+
options);
241+
source = handle_object_dir_option(the_repository);
242+
243+
FREE_AND_NULL(options);
244+
245+
m = get_multi_pack_index(source);
246+
247+
for (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {
248+
const char *midx_csum = midx_get_checksum_hex(cur);
249+
250+
if (!from_midx && !strcmp(midx_csum, argv[0]))
251+
from_midx = cur;
252+
if (!to_midx && !strcmp(midx_csum, argv[1]))
253+
to_midx = cur;
254+
}
255+
256+
if (!from_midx)
257+
die(_("could not find MIDX: %s"), argv[0]);
258+
if (!to_midx)
259+
die(_("could not find MIDX: %s"), argv[1]);
260+
if (from_midx == to_midx)
261+
die(_("MIDX compaction endpoints must be unique"));
262+
263+
for (m = from_midx; m; m = m->base_midx) {
264+
if (m == to_midx)
265+
die(_("MIDX %s must be an ancestor of %s"), argv[0], argv[1]);
266+
}
267+
268+
ret = write_midx_file_compact(source, from_midx, to_midx, opts.flags);
269+
270+
return ret;
271+
}
272+
197273
static int cmd_multi_pack_index_verify(int argc, const char **argv,
198274
const char *prefix,
199275
struct repository *repo UNUSED)
200276
{
201277
struct option *options;
202278
static struct option builtin_multi_pack_index_verify_options[] = {
203-
OPT_BIT(0, "progress", &opts.flags,
204-
N_("force progress reporting"), MIDX_PROGRESS),
205279
OPT_END(),
206280
};
207281
struct odb_source *source;
@@ -231,8 +305,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
231305
{
232306
struct option *options;
233307
static struct option builtin_multi_pack_index_expire_options[] = {
234-
OPT_BIT(0, "progress", &opts.flags,
235-
N_("force progress reporting"), MIDX_PROGRESS),
236308
OPT_END(),
237309
};
238310
struct odb_source *source;
@@ -264,8 +336,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
264336
static struct option builtin_multi_pack_index_repack_options[] = {
265337
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
266338
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
267-
OPT_BIT(0, "progress", &opts.flags,
268-
N_("force progress reporting"), MIDX_PROGRESS),
269339
OPT_END(),
270340
};
271341
struct odb_source *source;
@@ -300,6 +370,7 @@ int cmd_multi_pack_index(int argc,
300370
struct option builtin_multi_pack_index_options[] = {
301371
OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack),
302372
OPT_SUBCOMMAND("write", &fn, cmd_multi_pack_index_write),
373+
OPT_SUBCOMMAND("compact", &fn, cmd_multi_pack_index_compact),
303374
OPT_SUBCOMMAND("verify", &fn, cmd_multi_pack_index_verify),
304375
OPT_SUBCOMMAND("expire", &fn, cmd_multi_pack_index_expire),
305376
OPT_END(),

0 commit comments

Comments
 (0)