From: Adithya Chakilam Date: Wed, 25 Nov 2026 01:42:07 GMT Subject: Re: [PATCH 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects Message-ID: In-Reply-To: > > From: Adithya Chakilam > > > > 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= to write filtered-out objects directly as > > loose objects into , 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. > > +--filter-to-loose=:: > > + Like `--filter-to`, but treat `` 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 `` 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. > > 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=] [--depth=] [--threads=] [--keep-pack=]\n" > > "[--write-midx[=]] [--name-hash-version=] [--path-walk]\n" > > - "[--filter=] [--drop-filtered [--dry-run]]"), > > + "[--filter= [--filter-to-loose=]] [--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 so > commonly? If not, it would make sense to spell it out, i.e., > , 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. > 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. > > 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!