Skip to content

Commit 4308d81

Browse files
committed
Merge branch 'ds/midx-expire-repack'
"git multi-pack-index" learned expire and repack subcommands. * ds/midx-expire-repack: t5319: use 'test-tool path-utils' instead of 'ls -l' t5319-multi-pack-index.sh: test batch size zero midx: add test that 'expire' respects .keep files multi-pack-index: test expire while adding packs midx: implement midx_repack() multi-pack-index: prepare 'repack' subcommand multi-pack-index: implement 'expire' subcommand midx: refactor permutation logic and pack sorting midx: simplify computation of pack name lengths multi-pack-index: prepare for 'expire' subcommand Docs: rearrange subcommands for multi-pack-index repack: refactor pack deletion for future use
2 parents 9d41860 + 3612c23 commit 4308d81

File tree

8 files changed

+602
-119
lines changed

8 files changed

+602
-119
lines changed

Documentation/git-multi-pack-index.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git multi-pack-index' [--object-dir=<dir>] <verb>
12+
'git multi-pack-index' [--object-dir=<dir>] <subcommand>
1313

1414
DESCRIPTION
1515
-----------
@@ -23,13 +23,35 @@ OPTIONS
2323
`<dir>/packs/multi-pack-index` for the current MIDX file, and
2424
`<dir>/packs` for the pack-files to index.
2525

26+
The following subcommands are available:
27+
2628
write::
27-
When given as the verb, write a new MIDX file to
28-
`<dir>/packs/multi-pack-index`.
29+
Write a new MIDX file.
2930

3031
verify::
31-
When given as the verb, verify the contents of the MIDX file
32-
at `<dir>/packs/multi-pack-index`.
32+
Verify the contents of the MIDX file.
33+
34+
expire::
35+
Delete the pack-files that are tracked by the MIDX file, but
36+
have no objects referenced by the MIDX. Rewrite the MIDX file
37+
afterward to remove all references to these pack-files.
38+
39+
repack::
40+
Create a new pack-file containing objects in small pack-files
41+
referenced by the multi-pack-index. If the size given by the
42+
`--batch-size=<size>` argument is zero, then create a pack
43+
containing all objects referenced by the multi-pack-index. For
44+
a non-zero batch size, Select the pack-files by examining packs
45+
from oldest-to-newest, computing the "expected size" by counting
46+
the number of objects in the pack referenced by the
47+
multi-pack-index, then divide by the total number of objects in
48+
the pack and multiply by the pack size. We select packs with
49+
expected size below the batch size until the set of packs have
50+
total expected size at least the batch size. If the total size
51+
does not reach the batch size, then do nothing. If a new pack-
52+
file is created, rewrite the multi-pack-index to reference the
53+
new pack-file. A later run of 'git multi-pack-index expire' will
54+
delete the pack-files that were part of this batch.
3355

3456

3557
EXAMPLES

builtin/multi-pack-index.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
#include "trace2.h"
77

88
static char const * const builtin_multi_pack_index_usage[] = {
9-
N_("git multi-pack-index [--object-dir=<dir>] (write|verify)"),
9+
N_("git multi-pack-index [--object-dir=<dir>] (write|verify|expire|repack --batch-size=<size>)"),
1010
NULL
1111
};
1212

1313
static struct opts_multi_pack_index {
1414
const char *object_dir;
15+
unsigned long batch_size;
1516
} opts;
1617

1718
int cmd_multi_pack_index(int argc, const char **argv,
@@ -20,6 +21,8 @@ int cmd_multi_pack_index(int argc, const char **argv,
2021
static struct option builtin_multi_pack_index_options[] = {
2122
OPT_FILENAME(0, "object-dir", &opts.object_dir,
2223
N_("object directory containing set of packfile and pack-index pairs")),
24+
OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
25+
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
2326
OPT_END(),
2427
};
2528

@@ -43,10 +46,17 @@ int cmd_multi_pack_index(int argc, const char **argv,
4346

4447
trace2_cmd_mode(argv[0]);
4548

49+
if (!strcmp(argv[0], "repack"))
50+
return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size);
51+
if (opts.batch_size)
52+
die(_("--batch-size option is only for 'repack' subcommand"));
53+
4654
if (!strcmp(argv[0], "write"))
4755
return write_midx_file(opts.object_dir);
4856
if (!strcmp(argv[0], "verify"))
4957
return verify_midx_file(the_repository, opts.object_dir);
58+
if (!strcmp(argv[0], "expire"))
59+
return expire_midx_packs(the_repository, opts.object_dir);
5060

51-
die(_("unrecognized verb: %s"), argv[0]);
61+
die(_("unrecognized subcommand: %s"), argv[0]);
5262
}

builtin/repack.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,9 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,
129129

130130
static void remove_redundant_pack(const char *dir_name, const char *base_name)
131131
{
132-
const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
133-
int i;
134132
struct strbuf buf = STRBUF_INIT;
135-
size_t plen;
136-
137-
strbuf_addf(&buf, "%s/%s", dir_name, base_name);
138-
plen = buf.len;
139-
140-
for (i = 0; i < ARRAY_SIZE(exts); i++) {
141-
strbuf_setlen(&buf, plen);
142-
strbuf_addstr(&buf, exts[i]);
143-
unlink(buf.buf);
144-
}
133+
strbuf_addf(&buf, "%s/%s.pack", dir_name, base_name);
134+
unlink_pack_path(buf.buf, 1);
145135
strbuf_release(&buf);
146136
}
147137

0 commit comments

Comments
 (0)