Skip to content

Commit

Permalink
Merge pull request #143 from derrickstolee/midx-expire/ms
Browse files Browse the repository at this point in the history
Replace `git multi-pack-index expire/repack` with upstream v6
  • Loading branch information
dscho committed Jun 8, 2019
2 parents bbbea4e + 4ab0bc5 commit cf7c42c
Show file tree
Hide file tree
Showing 8 changed files with 602 additions and 119 deletions.
32 changes: 27 additions & 5 deletions Documentation/git-multi-pack-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
SYNOPSIS
--------
[verse]
'git multi-pack-index' [--object-dir=<dir>] <verb>
'git multi-pack-index' [--object-dir=<dir>] <subcommand>

DESCRIPTION
-----------
Expand All @@ -23,13 +23,35 @@ OPTIONS
`<dir>/packs/multi-pack-index` for the current MIDX file, and
`<dir>/packs` for the pack-files to index.

The following subcommands are available:

write::
When given as the verb, write a new MIDX file to
`<dir>/packs/multi-pack-index`.
Write a new MIDX file.

verify::
When given as the verb, verify the contents of the MIDX file
at `<dir>/packs/multi-pack-index`.
Verify the contents of the MIDX file.

expire::
Delete the pack-files that are tracked by the MIDX file, but
have no objects referenced by the MIDX. Rewrite the MIDX file
afterward to remove all references to these pack-files.

repack::
Create a new pack-file containing objects in small pack-files
referenced by the multi-pack-index. If the size given by the
`--batch-size=<size>` argument is zero, then create a pack
containing all objects referenced by the multi-pack-index. For
a non-zero batch size, Select the pack-files by examining packs
from oldest-to-newest, computing the "expected size" by counting
the number of objects in the pack referenced by the
multi-pack-index, then divide by the total number of objects in
the pack and multiply by the pack size. We select packs with
expected size below the batch size until the set of packs have
total expected size at least the batch size. If the total size
does not reach the batch size, then do nothing. If a new pack-
file is created, rewrite the multi-pack-index to reference the
new pack-file. A later run of 'git multi-pack-index expire' will
delete the pack-files that were part of this batch.


EXAMPLES
Expand Down
14 changes: 12 additions & 2 deletions builtin/multi-pack-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include "trace2.h"

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

static struct opts_multi_pack_index {
const char *object_dir;
unsigned long batch_size;
} opts;

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

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

trace2_cmd_mode(argv[0]);

if (!strcmp(argv[0], "repack"))
return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size);
if (opts.batch_size)
die(_("--batch-size option is only for 'repack' subcommand"));

if (!strcmp(argv[0], "write"))
return write_midx_file(opts.object_dir);
if (!strcmp(argv[0], "verify"))
return verify_midx_file(the_repository, opts.object_dir);
if (!strcmp(argv[0], "expire"))
return expire_midx_packs(the_repository, opts.object_dir);

die(_("unrecognized verb: %s"), argv[0]);
die(_("unrecognized subcommand: %s"), argv[0]);
}
14 changes: 2 additions & 12 deletions builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,9 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list,

static void remove_redundant_pack(const char *dir_name, const char *base_name)
{
const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
int i;
struct strbuf buf = STRBUF_INIT;
size_t plen;

strbuf_addf(&buf, "%s/%s", dir_name, base_name);
plen = buf.len;

for (i = 0; i < ARRAY_SIZE(exts); i++) {
strbuf_setlen(&buf, plen);
strbuf_addstr(&buf, exts[i]);
unlink(buf.buf);
}
strbuf_addf(&buf, "%s/%s.pack", dir_name, base_name);
unlink_pack_path(buf.buf, 1);
strbuf_release(&buf);
}

Expand Down
Loading

0 comments on commit cf7c42c

Please sign in to comment.