Skip to content

Commit b911170

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

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

Documentation/git-multi-pack-index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]
1414
[--refs-snapshot=<path>]
1515
'git multi-pack-index' [<options>] compact [--[no-]incremental]
16-
[--[no-]bitmap] <from> <to>
16+
[--[no-]bitmap] [--base=<checksum>] <from> <to>
1717
'git multi-pack-index' [<options>] verify
1818
'git multi-pack-index' [<options>] expire
1919
'git multi-pack-index' [<options>] repack [--batch-size=<size>]

builtin/multi-pack-index.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

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

2424
#define BUILTIN_MIDX_VERIFY_USAGE \
2525
N_("git multi-pack-index [<options>] verify")
@@ -62,6 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
6262
static struct opts_multi_pack_index {
6363
char *object_dir;
6464
const char *preferred_pack;
65+
const char *incremental_base;
6566
char *refs_snapshot;
6667
unsigned long batch_size;
6768
unsigned flags;
@@ -216,6 +217,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
216217

217218
struct option *options;
218219
static struct option builtin_multi_pack_index_compact_options[] = {
220+
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
221+
N_("base MIDX for incremental writes")),
219222
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
220223
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
221224
OPT_BIT(0, "incremental", &opts.flags,
@@ -258,7 +261,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
258261
if (!to_midx)
259262
die(_("could not find MIDX 'to': %s"), argv[1]);
260263

261-
ret = write_midx_file_compact(source, from_midx, to_midx, opts.flags);
264+
ret = write_midx_file_compact(source, from_midx, to_midx,
265+
opts.incremental_base, opts.flags);
262266

263267
close_midx(m);
264268

midx-write.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ struct write_midx_opts {
11361136

11371137
const char *preferred_pack_name;
11381138
const char *refs_snapshot;
1139+
const char *incremental_base;
11391140
unsigned flags;
11401141
};
11411142

@@ -1175,6 +1176,9 @@ static int write_midx_internal(struct write_midx_opts *opts)
11751176

11761177
ctx.compact_from = opts->compact_from;
11771178
ctx.compact_to = opts->compact_to;
1179+
} else if (opts->incremental_base) {
1180+
error(_("custom bases are only supported during compaction"));
1181+
goto cleanup;
11781182
}
11791183

11801184
if (ctx.incremental)
@@ -1210,11 +1214,28 @@ static int write_midx_internal(struct write_midx_opts *opts)
12101214

12111215
/*
12121216
* If compacting MIDX layer(s) in the range [from, to], then the
1213-
* compacted MIDX will share the same base MIDX as 'from'.
1217+
* compacted MIDX will share the same base MIDX as 'from',
1218+
* unless a custom --base is specified (see below).
12141219
*/
12151220
if (ctx.compact)
12161221
ctx.base_midx = ctx.compact_from->base_midx;
12171222

1223+
if (opts->incremental_base) {
1224+
while (ctx.base_midx) {
1225+
if (!strcmp(opts->incremental_base,
1226+
get_midx_checksum(ctx.base_midx)))
1227+
break;
1228+
1229+
ctx.base_midx = ctx.base_midx->base_midx;
1230+
}
1231+
1232+
if (!ctx.base_midx) {
1233+
error(_("could not find base MIDX '%s'"),
1234+
opts->incremental_base);
1235+
goto cleanup;
1236+
}
1237+
}
1238+
12181239
ctx.nr = 0;
12191240
ctx.alloc = ctx.m ? ctx.m->num_packs + ctx.m->num_packs_in_base : 16;
12201241
ctx.info = NULL;
@@ -1732,12 +1753,14 @@ int write_midx_file_only(struct odb_source *source,
17321753
int write_midx_file_compact(struct odb_source *source,
17331754
struct multi_pack_index *from,
17341755
struct multi_pack_index *to,
1756+
const char *incremental_base,
17351757
unsigned flags)
17361758
{
17371759
struct write_midx_opts opts = {
17381760
.source = source,
17391761
.compact_from = from,
17401762
.compact_to = to,
1763+
.incremental_base = incremental_base,
17411764
.flags = flags | MIDX_WRITE_COMPACT,
17421765
};
17431766

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ int write_midx_file_only(struct odb_source *source,
134134
int write_midx_file_compact(struct odb_source *source,
135135
struct multi_pack_index *from,
136136
struct multi_pack_index *to,
137+
const char *incremental_base,
137138
unsigned flags);
138139
void clear_midx_file(struct repository *r);
139140
int verify_midx_file(struct odb_source *source, unsigned flags);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,28 @@ test_expect_success 'MIDX compaction with bitmaps (non-trivial)' '
215215
)
216216
'
217217

218+
test_expect_success 'MIDX compaction with --base' '
219+
git init midx-compact-with--base &&
220+
(
221+
cd midx-compact-with--base &&
222+
223+
write_packs A B C D &&
224+
225+
test_line_count = 4 $midx_chain &&
226+
227+
cp "$midx_chain" "$midx_chain".bak &&
228+
229+
git multi-pack-index compact --incremental \
230+
--base="$(nth_line 1 "$midx_chain")" \
231+
"$(nth_line 3 "$midx_chain")" \
232+
"$(nth_line 4 "$midx_chain")" &&
233+
test_line_count = 2 $midx_chain &&
234+
235+
head -n1 "$midx_chain.bak" >actual &&
236+
head -n1 "$midx_chain" >expect &&
237+
238+
test_cmp expect actual
239+
)
240+
'
241+
218242
test_done

0 commit comments

Comments
 (0)