Skip to content

Commit b5798d1

Browse files
committed
WIP
Signed-off-by: Taylor Blau <[email protected]>
1 parent e2a5ab5 commit b5798d1

File tree

5 files changed

+101
-14
lines changed

5 files changed

+101
-14
lines changed

builtin/multi-pack-index.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
151151
N_("force progress reporting"), MIDX_PROGRESS),
152152
OPT_BIT(0, "incremental", &opts.flags,
153153
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
154+
OPT_BIT(0, "checksum-only", &opts.flags,
155+
N_("write a MIDX layer without updating the MIDX chain"),
156+
MIDX_WRITE_CHECKSUM_ONLY),
154157
OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
155158
N_("write multi-pack index containing only given indexes")),
156159
OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
@@ -176,6 +179,14 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
176179
if (argc)
177180
usage_with_options(builtin_multi_pack_index_write_usage,
178181
options);
182+
183+
if (opts.flags & MIDX_WRITE_CHECKSUM_ONLY &&
184+
!(opts.flags & MIDX_WRITE_INCREMENTAL)) {
185+
error(_("cannot use --checksum-only without --incremental"));
186+
usage_with_options(builtin_multi_pack_index_compact_usage,
187+
options);
188+
}
189+
179190
source = handle_object_dir_option(repo);
180191

181192
FREE_AND_NULL(options);
@@ -220,6 +231,9 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
220231
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
221232
OPT_BIT(0, "incremental", &opts.flags,
222233
N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL),
234+
OPT_BIT(0, "checksum-only", &opts.flags,
235+
N_("write a MIDX layer without updating the MIDX chain"),
236+
MIDX_WRITE_CHECKSUM_ONLY),
223237
OPT_BIT(0, "progress", &opts.flags,
224238
N_("force progress reporting"), MIDX_PROGRESS),
225239
OPT_END(),
@@ -240,6 +254,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
240254
if (argc != 2)
241255
usage_with_options(builtin_multi_pack_index_compact_usage,
242256
options);
257+
258+
if (opts.flags & MIDX_WRITE_CHECKSUM_ONLY &&
259+
!(opts.flags & MIDX_WRITE_INCREMENTAL)) {
260+
error(_("cannot use --checksum-only without --incremental"));
261+
usage_with_options(builtin_multi_pack_index_compact_usage,
262+
options);
263+
}
264+
243265
source = handle_object_dir_option(the_repository);
244266

245267
FREE_AND_NULL(options);

midx-write.c

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

15151515
if (ctx.incremental) {
1516-
struct strbuf lock_name = STRBUF_INIT;
1516+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1517+
struct strbuf lock_name = STRBUF_INIT;
15171518

1518-
get_midx_chain_filename(opts->source, &lock_name);
1519-
hold_lock_file_for_update(&lk, lock_name.buf, LOCK_DIE_ON_ERROR);
1520-
strbuf_release(&lock_name);
1519+
get_midx_chain_filename(opts->source, &lock_name);
1520+
hold_lock_file_for_update(&lk, lock_name.buf,
1521+
LOCK_DIE_ON_ERROR);
1522+
strbuf_release(&lock_name);
1523+
}
15211524

15221525
incr = mks_tempfile_m(midx_name.buf, 0444);
15231526
if (!incr) {
@@ -1640,14 +1643,19 @@ static int write_midx_internal(struct write_midx_opts *opts)
16401643
}
16411644
CALLOC_ARRAY(keep_hashes, keep_hashes_nr);
16421645

1646+
if (opts->flags & MIDX_WRITE_CHECKSUM_ONLY)
1647+
printf("%s\n", hash_to_hex_algop(midx_hash, r->hash_algo));
1648+
16431649
if (ctx.incremental) {
1644-
FILE *chainf = fdopen_lock_file(&lk, "w");
16451650
struct strbuf final_midx_name = STRBUF_INIT;
16461651
struct multi_pack_index *m = ctx.base_midx;
16471652

1648-
if (!chainf) {
1649-
error_errno(_("unable to open multi-pack-index chain file"));
1650-
goto cleanup;
1653+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1654+
FILE *chainf = fdopen_lock_file(&lk, "w");
1655+
if (!chainf) {
1656+
error_errno(_("unable to open multi-pack-index chain file"));
1657+
goto cleanup;
1658+
}
16511659
}
16521660

16531661
if (link_midx_to_chain(ctx.base_midx) < 0)
@@ -1703,8 +1711,10 @@ static int write_midx_internal(struct write_midx_opts *opts)
17031711
}
17041712
}
17051713

1706-
for (uint32_t i = 0; i < keep_hashes_nr; i++)
1707-
fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]);
1714+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY))
1715+
for (uint32_t i = 0; i < keep_hashes_nr; i++)
1716+
fprintf(get_lock_file_fp(&lk), "%s\n",
1717+
keep_hashes[i]);
17081718
} else {
17091719
/* TODO(@ttaylorr) */
17101720
keep_hashes[ctx.num_multi_pack_indexes_before] =
@@ -1714,11 +1724,13 @@ static int write_midx_internal(struct write_midx_opts *opts)
17141724
if (ctx.m || ctx.base_midx)
17151725
close_object_store(ctx.repo->objects);
17161726

1717-
if (commit_lock_file(&lk) < 0)
1718-
die_errno(_("could not write multi-pack-index"));
1727+
if (!(opts->flags & MIDX_WRITE_CHECKSUM_ONLY)) {
1728+
if (commit_lock_file(&lk) < 0)
1729+
die_errno(_("could not write multi-pack-index"));
17191730

1720-
clear_midx_files(opts->source, keep_hashes, keep_hashes_nr,
1721-
ctx.incremental);
1731+
clear_midx_files(opts->source, keep_hashes, keep_hashes_nr,
1732+
ctx.incremental);
1733+
}
17221734
result = 0;
17231735

17241736
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
@@ -221,4 +221,39 @@ test_expect_success 'MIDX compaction with --base' '
221221
)
222222
'
223223

224+
test_expect_success 'MIDX compaction with --checksum-only' '
225+
git init midx-compact-with--checksum-only &&
226+
(
227+
cd midx-compact-with--checksum-only &&
228+
229+
write_packs A B C D &&
230+
231+
test_line_count = 4 $midx_chain &&
232+
cp "$midx_chain" "$midx_chain".bak &&
233+
234+
layer="$(git multi-pack-index compact --incremental \
235+
--checksum-only \
236+
--base="$(nth_line 1 "$midx_chain")" \
237+
"$(nth_line 2 "$midx_chain")" \
238+
"$(nth_line 3 "$midx_chain")")" &&
239+
240+
test_cmp "$midx_chain.bak" "$midx_chain" &&
241+
242+
# After writing the new layer, insert it into the chain
243+
# manually. This is done in order to make $layer visible
244+
# to the read-midx test helper below, and matches what
245+
# the MIDX command would do without --checksum-only.
246+
{
247+
head -1 "$midx_chain.bak" &&
248+
echo $layer &&
249+
tail -1 "$midx_chain.bak"
250+
} >$midx_chain &&
251+
252+
test-tool read-midx $objdir $layer >midx.data &&
253+
grep "^pack-B-.*\.idx" midx.data &&
254+
grep "^pack-C-.*\.idx" midx.data
255+
256+
)
257+
'
258+
224259
test_done

0 commit comments

Comments
 (0)