git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects

From
ACAdithya Chakilam <achakilam@nvidia.com>
Date
Nov 25, 2026, 01:42 UTC
Message-ID
<DS1PR12MB99918707F05716CE2A1F5A72DCC1432@DS1PR12MB999187.namprd12.prod.outlook.com>
In-Reply-To
<xmqqmrrbnpk6.fsf@gitster.g>
Show 20 quoted lines
> > From: Adithya Chakilam <achakilam@nvidia.com>
> >
> > Some external object stores (like key-value) manage and retrieve git
> > objects individually. Although repack's --filter-to option can separate
> > objects from the main object store, it writes them into packs. Using
> > those objects individually then requires an additional unpacking step.
> >
> > Add --filter-to-loose=<dir> to write filtered-out objects directly as
> > loose objects into <dir>, treating it as an object directory. Stream
> > the filtered pack into unpack-objects instead of writing an intermediate
> > pack file to disk.
> >
> > The filtered pack is built with --stdin-packs, so this initially handles
> > only objects already stored in packs. Loose objects in the source
> > repository are left in place.
> 
> I haven't decided whether this new feature makes sense or not, so I
> won't comment on that aspect.  Take the following review comments
> with that in mind (i.e., pretend as if I said "if we assume doing
> this makes sense, then..." before every sentence).

Sure. To add more context, this allows large objects to be offloaded to other repositories (possibly accessed via alternates) and not packed to avoid the delta searching overhead incurred when packing objects. It also makes it easier to upload individual objects to a large-object promisor that does not implement the Git protocol, supporting the offloading workflow described in section II.4 of the large-object-promisors document.

Show 12 quoted lines
> > +--filter-to-loose=<dir>::
> > +     Like `--filter-to`, but treat `<dir>` as an object directory
> > +     and write the filtered out objects there as loose objects
> > +     instead of as a pack. Cannot be combined with `--filter-to`
> > +     or `--max-pack-size`. Objects already present in `<dir>` are
> > +     not rewritten. All objects are written before any existing
> > +     pack is removed.
> 
> We talk about "already present in ...", so presumably we require the
> directory to exist before we run.  Have a test that ensures that
> passing a non-existing directory will make the command error out
> before doing any real work.
Added a check and a test.
Show 20 quoted lines
> > diff --git a/builtin/repack.c b/builtin/repack.c
> > index 21835453c6..140a992f1b 100644
> > --- a/builtin/repack.c
> > +++ b/builtin/repack.c
> > @@ -41,7 +41,7 @@ static const char *const git_repack_usage[] = {
> >       N_("git repack [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]\n"
> >          "[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]\n"
> >          "[--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]\n"
> > -        "[--filter=<filter-spec>] [--drop-filtered [--dry-run]]"),
> > +        "[--filter=<filter-spec> [--filter-to-loose=<dir>]] [--drop-filtered [--dry-run]]"),
> 
> The above documentation and help text consistently tell us that the
> value passed is a directory (do we use the abbreviated <dir> so
> commonly?  If not, it would make sense to spell it out, i.e.,
> <directory>, for clarity).
> 
> > +             OPT_STRING(0, "filter-to-loose", &filter_to_loose, N_("dir"),
> > +                        N_("object directory to write filtered out objects into as loose objects")),
> 
> Here, too.
Changed it to consistently use directory.
Show 14 quoted lines
> This should use OPT_FILENAME so that a "git repack" started from a
> subdirectory with a relative path to the external loose object store
> will find the directory at the correct place, I think.  Have a test
> to validate the combination to see that such a repack that was given
> a relative path to a directory find ...
> 
>         mkdir extra-loose-objects &&
>         mkdir sub/dir &&
>         (
>                 cd sub/dir &&
>                 git repack --filter-to-loose=../../extra-loose-objects ...
>         )
> 
> the directory correct at the right place.
Modified to use OPT_FILENAME and added a test as said.
Show 21 quoted lines
> > diff --git a/repack-filtered.c b/repack-filtered.c
> > index 869b9fc6e3..51c9dfeb13 100644
> > --- a/repack-filtered.c
> > +++ b/repack-filtered.c
> > @@ -29,10 +50,18 @@ int write_filtered_pack(const struct write_pack_opts *opts,
> >               strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
> >
> >       cmd.in = -1;
> > +     if (opts->loose)
> > +             cmd.out = unpack.in;
> >
> >       ret = start_command(&cmd);
> > -     if (ret)
> > +     if (ret) {
> > +             if (opts->loose) {
> > +                     close(unpack.in);
> 
> Please double check that this is not closing the same thing twice.
> IIRC, a failing start_command() would close all file descriptors
> associated with cmd so you may have already closed unpack.in when
> start_command() gave us a failure, which presumably closed cmd.out.
start_command did close. Thanks!
Previous: Junio C HamanoNext: Adithya Chakilam via GitGitGadget
Message 4 of 8 in “repack: write filtered-out objects as loose objects”
  1. 0/2 repack: write filtered-out objects as loose objectsAdithya Chakilam via GitGitGadget, Nov 13, 2026
  2. 1/2 repack: add --filter-to-loose to write filtered-out objects as loose objectsAdithya Chakilam via GitGitGadget, Nov 13, 2026
  3. Junio C HamanoNov 14, 2026
  4. Adithya ChakilamNov 25, 2026
  5. 2/2 repack: also copy loose objects excluded by --filter-to-looseAdithya Chakilam via GitGitGadget, Nov 13, 2026
  6. 0/2 repack: write filtered-out objects as loose objectsAdithya Chakilam via GitGitGadget, Nov 25, 2026
  7. 1/2 repack: add --filter-to-loose to write filtered-out objects as loose objectsAdithya Chakilam via GitGitGadget, Nov 25, 2026
  8. 2/2 repack: also copy loose objects excluded by --filter-to-looseAdithya Chakilam via GitGitGadget, Nov 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.