Skip to content

Commit 6f5a29d

Browse files
committed
WIP
Signed-off-by: Taylor Blau <[email protected]>
1 parent 9fde236 commit 6f5a29d

File tree

6 files changed

+107
-18
lines changed

6 files changed

+107
-18
lines changed

Documentation/git-multi-pack-index.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ SYNOPSIS
1111
[verse]
1212
'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]
1313
[--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]
14-
[--refs-snapshot=<path>]
14+
[--refs-snapshot=<path>] [--[no-]checksum-only]
1515
'git multi-pack-index' [<options>] compact [--[no-]incremental]
16-
[--[no-]bitmap] [--base=<checksum>] <from> <to>
16+
[--[no-]bitmap] [--base=<checksum>] [--[no-]checksum-only]
17+
<from> <to>
1718
'git multi-pack-index' [<options>] verify
1819
'git multi-pack-index' [<options>] expire
1920
'git multi-pack-index' [<options>] repack [--batch-size=<size>]

builtin/multi-pack-index.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
#define BUILTIN_MIDX_WRITE_USAGE \
1616
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \
1717
" [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \
18-
" [--refs-snapshot=<path>]")
18+
" [--refs-snapshot=<path>] [--[no-]checksum-only]")
1919

2020
#define BUILTIN_MIDX_COMPACT_USAGE \
2121
N_("git multi-pack-index [<options>] compact [--[no-]incremental]\n" \
22-
" [--[no-]bitmap] [--base=<checksum>] <from> <to>")
22+
" [--[no-]bitmap] [--base=<checksum>] [--[no-]checksum-only]\n" \
23+
" <from> <to>")
2324

2425
#define BUILTIN_MIDX_VERIFY_USAGE \
2526
N_("git multi-pack-index [<options>] verify")
@@ -153,6 +154,9 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
153154
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
154155
OPT_BIT(0, "incremental", &opts.flags,
155156
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
157+
OPT_BIT(0, "checksum-only", &opts.flags,
158+
N_("write a MIDX layer without updating the MIDX chain"),
159+
MIDX_WRITE_CHECKSUM_ONLY),
156160
OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
157161
N_("write multi-pack index containing only given indexes")),
158162
OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
@@ -178,6 +182,14 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
178182
if (argc)
179183
usage_with_options(builtin_multi_pack_index_write_usage,
180184
options);
185+
186+
if (opts.flags & MIDX_WRITE_CHECKSUM_ONLY &&
187+
!(opts.flags & MIDX_WRITE_INCREMENTAL)) {
188+
error(_("cannot use --checksum-only without --incremental"));
189+
usage_with_options(builtin_multi_pack_index_compact_usage,
190+
options);
191+
}
192+
181193
source = handle_object_dir_option(repo);
182194

183195
FREE_AND_NULL(options);
@@ -222,6 +234,9 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
222234
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
223235
OPT_BIT(0, "incremental", &opts.flags,
224236
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
237+
OPT_BIT(0, "checksum-only", &opts.flags,
238+
N_("write a MIDX layer without updating the MIDX chain"),
239+
MIDX_WRITE_CHECKSUM_ONLY),
225240
OPT_END(),
226241
};
227242

@@ -240,6 +255,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
240255
if (argc != 2)
241256
usage_with_options(builtin_multi_pack_index_compact_usage,
242257
options);
258+
259+
if (opts.flags & MIDX_WRITE_CHECKSUM_ONLY &&
260+
!(opts.flags & MIDX_WRITE_INCREMENTAL)) {
261+
error(_("cannot use --checksum-only without --incremental"));
262+
usage_with_options(builtin_multi_pack_index_compact_usage,
263+
options);
264+
}
265+
243266
source = handle_object_dir_option(the_repository);
244267

245268
FREE_AND_NULL(options);

midx-write.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,14 @@ static int write_midx_internal(struct write_midx_opts *opts)
14881488
}
14891489

14901490
if (ctx.incremental) {
1491-
struct strbuf lock_name = STRBUF_INIT;
1491+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1492+
struct strbuf lock_name = STRBUF_INIT;
14921493

1493-
get_midx_chain_filename(opts->source, &lock_name);
1494-
hold_lock_file_for_update(&lk, lock_name.buf, LOCK_DIE_ON_ERROR);
1495-
strbuf_release(&lock_name);
1494+
get_midx_chain_filename(opts->source, &lock_name);
1495+
hold_lock_file_for_update(&lk, lock_name.buf,
1496+
LOCK_DIE_ON_ERROR);
1497+
strbuf_release(&lock_name);
1498+
}
14961499

14971500
incr = mks_tempfile_m(midx_name.buf, 0444);
14981501
if (!incr) {
@@ -1615,14 +1618,19 @@ static int write_midx_internal(struct write_midx_opts *opts)
16151618
}
16161619
CALLOC_ARRAY(keep_hashes, keep_hashes_nr);
16171620

1621+
if (opts->flags & MIDX_WRITE_CHECKSUM_ONLY)
1622+
printf("%s\n", hash_to_hex_algop(midx_hash, r->hash_algo));
1623+
16181624
if (ctx.incremental) {
1619-
FILE *chainf = fdopen_lock_file(&lk, "w");
16201625
struct strbuf final_midx_name = STRBUF_INIT;
16211626
struct multi_pack_index *m = ctx.base_midx;
16221627

1623-
if (!chainf) {
1624-
error_errno(_("unable to open multi-pack-index chain file"));
1625-
goto cleanup;
1628+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1629+
FILE *chainf = fdopen_lock_file(&lk, "w");
1630+
if (!chainf) {
1631+
error_errno(_("unable to open multi-pack-index chain file"));
1632+
goto cleanup;
1633+
}
16261634
}
16271635

16281636
if (link_midx_to_chain(ctx.base_midx) < 0)
@@ -1678,8 +1686,10 @@ static int write_midx_internal(struct write_midx_opts *opts)
16781686
}
16791687
}
16801688

1681-
for (uint32_t i = 0; i < keep_hashes_nr; i++)
1682-
fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]);
1689+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY))
1690+
for (uint32_t i = 0; i < keep_hashes_nr; i++)
1691+
fprintf(get_lock_file_fp(&lk), "%s\n",
1692+
keep_hashes[i]);
16831693
} else {
16841694
keep_hashes[ctx.num_multi_pack_indexes_before] =
16851695
xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));
@@ -1688,11 +1698,13 @@ static int write_midx_internal(struct write_midx_opts *opts)
16881698
if (ctx.m || ctx.base_midx)
16891699
close_object_store(ctx.repo->objects);
16901700

1691-
if (commit_lock_file(&lk) < 0)
1692-
die_errno(_("could not write multi-pack-index"));
1701+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1702+
if (commit_lock_file(&lk) < 0)
1703+
die_errno(_("could not write multi-pack-index"));
16931704

1694-
clear_midx_files(opts->source, keep_hashes, keep_hashes_nr,
1695-
ctx.incremental);
1705+
clear_midx_files(opts->source, keep_hashes, keep_hashes_nr,
1706+
ctx.incremental);
1707+
}
16961708
result = 0;
16971709

16981710
cleanup:

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct multi_pack_index {
8282
#define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4)
8383
#define MIDX_WRITE_INCREMENTAL (1 << 5)
8484
#define MIDX_WRITE_COMPACT (1 << 6)
85+
#define MIDX_WRITE_CHECKSUM_ONLY (1 << 7)
8586

8687
#define MIDX_EXT_REV "rev"
8788
#define MIDX_EXT_BITMAP "bitmap"

t/t5334-incremental-multi-pack-index.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ test_expect_success 'show object from second pack' '
9595
git cat-file -p 2.2
9696
'
9797

98+
test_expect_success 'write MIDX layer with --checksum-only' '
99+
test_commit checksum-only &&
100+
git repack -d &&
101+
102+
cp "$midx_chain" "$midx_chain.bak" &&
103+
layer="$(git multi-pack-index write --bitmap --incremental \
104+
--checksum-only)" &&
105+
106+
test_cmp "$midx_chain.bak" "$midx_chain" &&
107+
test_path_is_file "$midxdir/multi-pack-index-$layer.midx"
108+
'
109+
110+
test_expect_success 'write non-incremental MIDX layer with --checksum-only' '
111+
test_must_fail git multi-pack-index write --bitmap --checksum-only 2>err &&
112+
test_grep "cannot use --checksum-only without --incremental" err
113+
'
114+
98115
for reuse in false single multi
99116
do
100117
test_expect_success "full clone (pack.allowPackReuse=$reuse)" '

t/t5335-compact-multi-pack-index.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,39 @@ test_expect_success 'MIDX compaction with --base' '
239239
)
240240
'
241241

242+
test_expect_success 'MIDX compaction with --checksum-only' '
243+
git init midx-compact-with--checksum-only &&
244+
(
245+
cd midx-compact-with--checksum-only &&
246+
247+
write_packs A B C D &&
248+
249+
test_line_count = 4 $midx_chain &&
250+
cp "$midx_chain" "$midx_chain".bak &&
251+
252+
layer="$(git multi-pack-index compact --incremental \
253+
--checksum-only \
254+
--base="$(nth_line 1 "$midx_chain")" \
255+
"$(nth_line 2 "$midx_chain")" \
256+
"$(nth_line 3 "$midx_chain")")" &&
257+
258+
test_cmp "$midx_chain.bak" "$midx_chain" &&
259+
260+
# After writing the new layer, insert it into the chain
261+
# manually. This is done in order to make $layer visible
262+
# to the read-midx test helper below, and matches what
263+
# the MIDX command would do without --checksum-only.
264+
{
265+
head -1 "$midx_chain.bak" &&
266+
echo $layer &&
267+
tail -1 "$midx_chain.bak"
268+
} >$midx_chain &&
269+
270+
test-tool read-midx $objdir $layer >midx.data &&
271+
grep "^pack-B-.*\.idx" midx.data &&
272+
grep "^pack-C-.*\.idx" midx.data
273+
274+
)
275+
'
276+
242277
test_done

0 commit comments

Comments
 (0)