repack: add `--filter=<filter-spec>` option
commit48a9b67b4301083d0820e90afef208ed1436298f
authorChristian Couder <christian.couder@gmail.com>
Mon, 2 Oct 2023 16:55:01 +0000 (2 18:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Oct 2023 21:54:30 +0000 (2 14:54 -0700)
treee9ccde728d847d0b6d1cfd5bb628f1d8feaec4c7
parent0e4747ec8b5558e7106146fd37501649f577bcfa
repack: add `--filter=<filter-spec>` option

This new option puts the objects specified by `<filter-spec>` into a
separate packfile.

This could be useful if, for example, some blobs take up a lot of
precious space on fast storage while they are rarely accessed. It could
make sense to move them into a separate cheaper, though slower, storage.

It's possible to find which new packfile contains the filtered out
objects using one of the following:

  - `git verify-pack -v ...`,
  - `test-tool find-pack ...`, which a previous commit added,
  - `--filter-to=<dir>`, which a following commit will add to specify
    where the pack containing the filtered out objects will be.

This feature is implemented by running `git pack-objects` twice in a
row. The first command is run with `--filter=<filter-spec>`, using the
specified filter. It packs objects while omitting the objects specified
by the filter. Then another `git pack-objects` command is launched using
`--stdin-packs`. We pass it all the previously existing packs into its
stdin, so that it will pack all the objects in the previously existing
packs. But we also pass into its stdin, the pack created by the previous
`git pack-objects --filter=<filter-spec>` command as well as the kept
packs, all prefixed with '^', so that the objects in these packs will be
omitted from the resulting pack. The result is that only the objects
filtered out by the first `git pack-objects` command are in the pack
resulting from the second `git pack-objects` command.

As the interactions with kept packs are a bit tricky, a few related
tests are added.

Helped-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-repack.txt
builtin/repack.c
t/t7700-repack.sh