* [PATCH 0/2] repack: write filtered-out objects as loose objects
@ 2026-11-13 22:11 Adithya Chakilam via GitGitGadget
2026-11-13 22:11 ` [PATCH 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-13 22:11 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam
Some key-value object stores manage and retrieve Git objects individually.
The existing --filter-to option writes filtered-out objects into packs, so
using it with such stores requires unpacking the resulting packs before
importing the objects.
This series adds --filter-to-loose=dir to git repack, allowing filtered-out
objects to be written directly as loose objects into another object
directory.
With --filter-to-loose, repack streams the filtered pack into
unpack-objects, avoiding that extra step and the intermediate pack file. For
example:
git repack -a --filter=blob=1m --filter-to-loose=/path/to/objects
The destination is treated as a Git object directory.
The first patch adds the option for objects already stored in packs. The
second extends it to include loose objects excluded by the filter, so the
destination also receives those objects. Objects already present in the
destination are not rewritten. With -d, the source copies of those loose
objects are removed after all objects have been written successfully.
Adithya Chakilam (2):
repack: add --filter-to-loose to write filtered-out objects as loose
objects
repack: also copy loose objects excluded by --filter-to-loose
Documentation/git-repack.adoc | 14 ++-
builtin/repack.c | 32 +++++-
repack-filtered.c | 152 ++++++++++++++++++++++++++-
repack.h | 14 +++
t/t7700-repack.sh | 189 ++++++++++++++++++++++++++++++++++
5 files changed, 394 insertions(+), 7 deletions(-)
base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2314%2Fachakilam-nv%2Ffilter-to-loose-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2314/achakilam-nv/filter-to-loose-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2314
--
gitgitgadget
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
2026-11-13 22:11 [PATCH 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
@ 2026-11-13 22:11 ` Adithya Chakilam via GitGitGadget
2026-11-14 20:08 ` Junio C Hamano
2026-11-13 22:11 ` [PATCH 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2 siblings, 1 reply; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-13 22:11 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam, Adithya Chakilam
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.
Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
---
Documentation/git-repack.adoc | 10 ++-
builtin/repack.c | 21 ++++--
repack-filtered.c | 44 +++++++++++-
repack.h | 1 +
t/t7700-repack.sh | 130 ++++++++++++++++++++++++++++++++++
5 files changed, 199 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
index a1f9e64f66..df1390154f 100644
--- a/Documentation/git-repack.adoc
+++ b/Documentation/git-repack.adoc
@@ -12,7 +12,7 @@ SYNOPSIS
'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]
[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
[--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]
- [--filter=<filter-spec>] [--drop-filtered [--dry-run]]
+ [--filter=<filter-spec> [--filter-to-loose=<dir>]] [--drop-filtered [--dry-run]]
DESCRIPTION
-----------
@@ -183,6 +183,14 @@ depth is 4095.
`objects` and `objects/info/alternates` sections of
linkgit:gitrepository-layout[5].
+--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.
+
--drop-filtered::
Delete the local objects that match the `--filter` specification
instead of keeping them in a separate packfile, reclaiming the
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]]"),
NULL
};
@@ -182,6 +182,7 @@ int cmd_repack(int argc,
const char *cruft_expiration = NULL;
const char *expire_to = NULL;
const char *filter_to = NULL;
+ const char *filter_to_loose = NULL;
const char *opt_window = NULL;
const char *opt_window_memory = NULL;
const char *opt_depth = NULL;
@@ -257,6 +258,8 @@ int cmd_repack(int argc,
N_("pack prefix to store a pack containing pruned objects")),
OPT_STRING(0, "filter-to", &filter_to, N_("dir"),
N_("pack prefix to store a pack containing filtered out objects")),
+ OPT_STRING(0, "filter-to-loose", &filter_to_loose, N_("dir"),
+ N_("object directory to write filtered out objects into as loose objects")),
OPT_BOOL(0, "drop-filtered", &drop_filtered,
N_("delete filtered out objects (requires --filter)")),
OPT_BOOL(0, "dry-run", &dry_run,
@@ -282,8 +285,16 @@ int cmd_repack(int argc,
po_args.depth = xstrdup_or_null(opt_depth);
po_args.threads = xstrdup_or_null(opt_threads);
- die_for_incompatible_opt2(drop_filtered, "--drop-filtered",
- !!filter_to, "--filter-to");
+ die_for_incompatible_opt3(drop_filtered, "--drop-filtered",
+ !!filter_to, "--filter-to",
+ !!filter_to_loose, "--filter-to-loose");
+ die_for_incompatible_opt2(!!filter_to, "--filter-to",
+ !!filter_to_loose, "--filter-to-loose");
+ die_for_incompatible_opt2(!!filter_to_loose, "--filter-to-loose",
+ !!po_args.max_pack_size, "--max-pack-size");
+
+ if (filter_to_loose)
+ filter_to = filter_to_loose;
if (dry_run && !drop_filtered)
die(_("--dry-run only takes effect with --drop-filtered"));
@@ -553,7 +564,8 @@ int cmd_repack(int argc,
strvec_pushf(&cmd.args, "--filter=%s",
expand_list_objects_filter_spec(&po_args.filter_options));
else if (filter_to)
- die(_("option '%s' can only be used along with '%s'"), "--filter-to", "--filter");
+ die(_("option '%s' can only be used along with '%s'"),
+ filter_to_loose ? "--filter-to-loose" : "--filter-to", "--filter");
if (geometry.split_factor)
cmd.in = -1;
@@ -698,6 +710,7 @@ int cmd_repack(int argc,
struct write_pack_opts opts = {
.po_args = &po_args,
.destination = filter_to,
+ .loose = !!filter_to_loose,
.packdir = packdir,
.packtmp = packtmp,
};
diff --git a/repack-filtered.c b/repack-filtered.c
index 869b9fc6e3..51c9dfeb13 100644
--- a/repack-filtered.c
+++ b/repack-filtered.c
@@ -9,19 +9,40 @@
#include "list-objects-filter.h"
#include "odb.h"
#include "promisor-remote.h"
+#include "sigchain.h"
+
+static void start_unpack_objects(struct child_process *unpack,
+ const char *objdir)
+{
+ strvec_push(&unpack->args, "unpack-objects");
+ strvec_push(&unpack->args, "-q");
+ strvec_pushf(&unpack->env, "GIT_OBJECT_DIRECTORY=%s", objdir);
+ strvec_push(&unpack->env, "GIT_ALTERNATE_OBJECT_DIRECTORIES");
+ unpack->git_cmd = 1;
+ unpack->in = -1;
+ if (start_command(unpack))
+ die(_("could not start unpack-objects for '%s'"), objdir);
+}
int write_filtered_pack(const struct write_pack_opts *opts,
struct existing_packs *existing,
struct string_list *names)
{
struct child_process cmd = CHILD_PROCESS_INIT;
+ struct child_process unpack = CHILD_PROCESS_INIT;
struct string_list_item *item;
FILE *in;
int ret;
const char *caret;
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
- prepare_pack_objects(&cmd, opts->po_args, opts->destination);
+ if (opts->loose) {
+ sigchain_push(SIGPIPE, SIG_IGN);
+ start_unpack_objects(&unpack, opts->destination);
+ prepare_pack_objects(&cmd, opts->po_args, "--stdout");
+ } else {
+ prepare_pack_objects(&cmd, opts->po_args, opts->destination);
+ }
strvec_push(&cmd.args, "--stdin-packs");
@@ -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);
+ finish_command(&unpack);
+ sigchain_pop(SIGPIPE);
+ }
return ret;
+ }
/*
* Here 'names' contains only the pack(s) that were just
@@ -52,6 +81,17 @@ int write_filtered_pack(const struct write_pack_opts *opts,
fprintf(in, "%s%s.pack\n", caret, item->string);
fclose(in);
+ if (opts->loose) {
+ ret = finish_command(&cmd);
+ if (finish_command(&unpack))
+ ret = -1;
+ sigchain_pop(SIGPIPE);
+ if (ret)
+ ret = error(_("failed to write filtered out objects to '%s'"),
+ opts->destination);
+ return ret;
+ }
+
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
names);
}
diff --git a/repack.h b/repack.h
index 61e554e4ed..d5528745ec 100644
--- a/repack.h
+++ b/repack.h
@@ -41,6 +41,7 @@ void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
struct write_pack_opts {
struct pack_objects_args *po_args;
const char *destination;
+ bool loose;
const char *packdir;
const char *packtmp;
};
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index f0a390e3c6..5aa4b698f1 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -489,6 +489,136 @@ test_expect_success '--filter-to stores filtered out objects' '
test "$blob_content" = "content1"
'
+test_expect_success '--filter-to-loose writes filtered out objects loose' '
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base file1 content1 &&
+ git clone --bare loose-work loose-src.git &&
+ git -C loose-src.git repack -a -d &&
+
+ blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob) &&
+ find loose-dst.git/objects/pack -name "*.pack" >actual-packs &&
+ test_must_be_empty actual-packs &&
+ test_must_fail git -C loose-src.git cat-file -e $blob &&
+
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ echo content1 >expect &&
+ git -C loose-src.git cat-file blob $blob >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--filter-to-loose writes objects that also exist in the source' '
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base file1 content1 &&
+ git clone --bare loose-work loose-src.git &&
+ git -C loose-src.git repack -a -d &&
+
+ blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob)
+'
+
+# Create loose-work/loose-src.git/loose-dst.git; $big is a 2k blob on
+# refs/heads/big in loose-src.git, packed unless $1 is "loose".
+setup_loose_src () {
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base small small &&
+ git clone --bare loose-work loose-src.git &&
+
+ big=$(test-tool genrandom big 2k | git -C loose-src.git hash-object -w --stdin) &&
+ tree=$(printf "100644 blob %s\tbig\n" $big | git -C loose-src.git mktree) &&
+ commit=$(git -C loose-src.git commit-tree -m big $tree) &&
+ git -C loose-src.git update-ref refs/heads/big $commit &&
+
+ if test "$1" != loose
+ then
+ git -C loose-src.git repack -a -d
+ fi
+}
+
+test_expect_success '--filter-to-loose failure to write leaves the source intact' '
+ setup_loose_src &&
+ >not-a-dir &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
+ --filter-to-loose=../not-a-dir &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-after &&
+ test_cmp packs-before packs-after &&
+
+ find loose-src.git/objects/pack -name ".tmp-*" >tmp-leftovers &&
+ test_must_be_empty tmp-leftovers &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose does not move objects from kept packs' '
+ setup_loose_src &&
+
+ for p in loose-src.git/objects/pack/pack-*.pack
+ do
+ >${p%.pack}.keep || return 1
+ done &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_missing loose-dst.git/objects/$(test_oid_to_path $big) &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose leaves unreachable objects in cruft packs alone' '
+ setup_loose_src loose &&
+ git -C loose-src.git update-ref -d refs/heads/big &&
+ git -C loose-src.git repack --cruft -d &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d --cruft \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_missing loose-dst.git/objects/$(test_oid_to_path $big) &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose output survives gc and prune of the source' '
+ setup_loose_src &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ git -C loose-src.git gc --prune=now &&
+ git -C loose-src.git prune --expire=now &&
+
+ git -C loose-src.git fsck &&
+ git -C loose-src.git cat-file -e $big &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big)
+'
+
+test_expect_success '--filter-to-loose requires --filter, rejects --filter-to and --max-pack-size' '
+ test_must_fail git -C bare.git repack -a --filter-to-loose=../x 2>err &&
+ test_grep "can only be used along with" err &&
+
+ test_must_fail git -C bare.git repack -a --filter=blob:none \
+ --filter-to=../y --filter-to-loose=../x 2>err &&
+ test_grep "cannot be used together" err &&
+
+ test_must_fail git -C bare.git repack -a --filter=blob:none \
+ --filter-to-loose=../x --max-pack-size=1M 2>err &&
+ test_grep "cannot be used together" err
+'
+
test_expect_success '--filter works with --max-pack-size' '
rm -rf filtered.git &&
git init --bare filtered.git &&
--
gitgitgadget
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/2] repack: also copy loose objects excluded by --filter-to-loose
2026-11-13 22:11 [PATCH 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-13 22:11 ` [PATCH 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
@ 2026-11-13 22:11 ` Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2 siblings, 0 replies; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-13 22:11 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam, Adithya Chakilam
From: Adithya Chakilam <achakilam@nvidia.com>
--filter-to-loose only writes objects that were in an existing pack,
because the filtered pack is built with --stdin-packs. Loose objects
that the filter excludes stay behind in the source repository, so the
destination does not get the complete set of filtered-out objects.
Copy such loose objects to the destination as well. An object already
present in the destination is not rewritten. With -d, the source copies
are removed once everything is written.
Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
---
Documentation/git-repack.adoc | 4 ++
builtin/repack.c | 11 ++++
repack-filtered.c | 108 ++++++++++++++++++++++++++++++++++
repack.h | 13 ++++
t/t7700-repack.sh | 59 +++++++++++++++++++
5 files changed, 195 insertions(+)
diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
index df1390154f..e2025c29ee 100644
--- a/Documentation/git-repack.adoc
+++ b/Documentation/git-repack.adoc
@@ -191,6 +191,10 @@ depth is 4095.
not rewritten. All objects are written before any existing
pack is removed.
+ Loose objects in this repository that the filter excludes are
+ copied to `<dir>` as well, and with `-d` the source copies are
+ removed once everything has been written.
+
--drop-filtered::
Delete the local objects that match the `--filter` specification
instead of keeping them in a separate packfile, reclaiming the
diff --git a/builtin/repack.c b/builtin/repack.c
index 140a992f1b..a946ad28a3 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -183,6 +183,7 @@ int cmd_repack(int argc,
const char *expire_to = NULL;
const char *filter_to = NULL;
const char *filter_to_loose = NULL;
+ struct oidset moved_loose = OIDSET_INIT;
const char *opt_window = NULL;
const char *opt_window_memory = NULL;
const char *opt_depth = NULL;
@@ -721,6 +722,14 @@ int cmd_repack(int argc,
ret = write_filtered_pack(&opts, &existing, &names);
if (ret)
goto cleanup;
+
+ if (filter_to_loose) {
+ ret = move_loose_filtered_objects(repo,
+ &po_args.filter_options, filter_to,
+ &moved_loose);
+ if (ret)
+ goto cleanup;
+ }
}
string_list_sort(&names);
@@ -777,6 +786,7 @@ int cmd_repack(int argc,
if (show_progress)
opts |= PRUNE_PACKED_VERBOSE;
prune_packed_objects(repo, opts);
+ remove_moved_loose_objects(repo, &moved_loose);
if (!keep_unreachable &&
(!(pack_everything & LOOSEN_UNREACHABLE) ||
@@ -801,6 +811,7 @@ cleanup:
string_list_clear(&keep_pack_list, 0);
string_list_clear(&names, 1);
oidset_clear(&drop_oids);
+ oidset_clear(&moved_loose);
existing_packs_release(&existing);
pack_geometry_release(&geometry);
pack_objects_args_release(&po_args);
diff --git a/repack-filtered.c b/repack-filtered.c
index 51c9dfeb13..cb1f034f09 100644
--- a/repack-filtered.c
+++ b/repack-filtered.c
@@ -9,6 +9,11 @@
#include "list-objects-filter.h"
#include "odb.h"
#include "promisor-remote.h"
+#include "copy.h"
+#include "object-file.h"
+#include "odb/source-files.h"
+#include "oidset.h"
+#include "path.h"
#include "sigchain.h"
static void start_unpack_objects(struct child_process *unpack,
@@ -171,3 +176,106 @@ cleanup:
oidset_clear(&all_promisor_blobs);
return ret;
}
+
+static int collect_loose_oid(const struct object_id *oid,
+ const char *path UNUSED, void *cb_data)
+{
+ oidset_insert(cb_data, oid);
+ return 0;
+}
+
+static void dest_loose_path(struct strbuf *buf, const char *objdir,
+ const struct object_id *oid)
+{
+ const char *hex = oid_to_hex(oid);
+
+ strbuf_reset(buf);
+ strbuf_addf(buf, "%s/%.2s/%s", objdir, hex, hex + 2);
+}
+
+int move_loose_filtered_objects(struct repository *repo,
+ const struct list_objects_filter_options *filter,
+ const char *dest_objdir,
+ struct oidset *moved)
+{
+ struct odb_source_files *files =
+ odb_source_files_downcast(repo->objects->source);
+ struct oidset loose = OIDSET_INIT;
+ struct oidset omitted = OIDSET_INIT;
+ struct oidset_iter iter;
+ const struct object_id *oid;
+ struct strbuf src = STRBUF_INIT;
+ struct strbuf dst = STRBUF_INIT;
+ struct strbuf tmp = STRBUF_INIT;
+ int ret = 0;
+
+ if (filter->choice != LOFC_BLOB_LIMIT)
+ return 0;
+
+ ret = for_each_loose_file_in_source(&files->dirs->loose->base,
+ collect_loose_oid, NULL, NULL,
+ &loose);
+ if (ret)
+ goto out;
+ ret = list_objects_filter__filter_oidset(repo, filter, &loose,
+ &omitted);
+ if (ret)
+ goto out;
+
+ oidset_iter_init(&omitted, &iter);
+ while ((oid = oidset_iter_next(&iter))) {
+ odb_loose_path(files->dirs->loose, &src, oid);
+ dest_loose_path(&dst, dest_objdir, oid);
+
+ /*
+ * Only the destination decides whether the copy is needed;
+ * the object being present in the source says nothing.
+ */
+ if (!access(dst.buf, F_OK)) {
+ oidset_insert(moved, oid);
+ continue;
+ }
+
+ if (safe_create_leading_directories(repo, dst.buf) < 0) {
+ ret = error_errno(_("unable to create leading directories of '%s'"),
+ dst.buf);
+ goto out;
+ }
+ strbuf_reset(&tmp);
+ strbuf_addf(&tmp, "%s.tmp-%"PRIuMAX, dst.buf,
+ (uintmax_t)getpid());
+ if (copy_file(repo, tmp.buf, src.buf, 0444) ||
+ finalize_object_file(repo, tmp.buf, dst.buf)) {
+ unlink(tmp.buf);
+ ret = error(_("unable to copy loose object '%s' to '%s'"),
+ src.buf, dst.buf);
+ goto out;
+ }
+ oidset_insert(moved, oid);
+ }
+
+out:
+ oidset_clear(&loose);
+ oidset_clear(&omitted);
+ strbuf_release(&src);
+ strbuf_release(&dst);
+ strbuf_release(&tmp);
+ return ret;
+}
+
+void remove_moved_loose_objects(struct repository *repo,
+ const struct oidset *moved)
+{
+ struct odb_source_files *files =
+ odb_source_files_downcast(repo->objects->source);
+ struct strbuf path = STRBUF_INIT;
+ struct oidset_iter iter;
+ const struct object_id *oid;
+
+ oidset_iter_init(moved, &iter);
+ while ((oid = oidset_iter_next(&iter))) {
+ odb_loose_path(files->dirs->loose, &path, oid);
+ unlink(path.buf);
+ }
+ strbuf_release(&path);
+}
diff --git a/repack.h b/repack.h
index d5528745ec..18a0dc6314 100644
--- a/repack.h
+++ b/repack.h
@@ -168,6 +168,19 @@ int write_filtered_pack(const struct write_pack_opts *opts,
struct existing_packs *existing,
struct string_list *names);
+/*
+ * Copy loose objects that the filter excludes into the loose-object store
+ * at `dest_objdir`, recording them in `moved`.
+ */
+int move_loose_filtered_objects(struct repository *repo,
+ const struct list_objects_filter_options *filter,
+ const char *dest_objdir,
+ struct oidset *moved);
+
+/* Delete the source copies of objects copied by move_loose_filtered_objects. */
+void remove_moved_loose_objects(struct repository *repo,
+ const struct oidset *moved);
+
int enumerate_promisor_blobs(struct repository *repo,
const struct list_objects_filter_options *filter,
struct oidset *to_drop);
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 5aa4b698f1..37dc5fdb13 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -547,6 +547,44 @@ setup_loose_src () {
fi
}
+test_expect_success '--filter-to-loose copies loose filtered out blobs, and -d removes the source copy' '
+ setup_loose_src loose &&
+ test_path_is_file loose-src.git/objects/$(test_oid_to_path $big) &&
+
+ # without -d the source copy is left alone
+ git -C loose-src.git -c repack.writebitmaps=false repack -a \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_file loose-src.git/objects/$(test_oid_to_path $big) &&
+
+ # with -d it is removed from the source after being copied
+ rm -rf loose-dst.git/objects/$(dirname $(test_oid_to_path $big)) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_missing loose-src.git/objects/$(test_oid_to_path $big) &&
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose leaves an identical existing destination object alone' '
+ setup_loose_src &&
+
+ test-tool genrandom big 2k |
+ GIT_OBJECT_DIRECTORY=loose-dst.git/objects git hash-object -w --stdin &&
+
+ path=loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_file $path &&
+
+ ls -i $path >before &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ ls -i $path >after &&
+ test_cmp before after &&
+ git -C loose-dst.git fsck
+'
+
test_expect_success '--filter-to-loose failure to write leaves the source intact' '
setup_loose_src &&
>not-a-dir &&
@@ -564,6 +602,27 @@ test_expect_success '--filter-to-loose failure to write leaves the source intact
git -C loose-src.git cat-file -e $big
'
+test_expect_success '--filter-to-loose failure to copy a loose object leaves the source intact' '
+ setup_loose_src loose &&
+ path=$(test_oid_to_path $big) &&
+ >loose-dst.git/objects/$(dirname $path) &&
+
+ find loose-src.git/objects/pack -name "*.pack" | sort >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
+ --filter-to-loose=../loose-dst.git/objects 2>err &&
+
+ test_grep "unable to create leading directories" err &&
+ find loose-src.git/objects/pack -name "*.pack" | sort >packs-after &&
+ test_cmp packs-before packs-after &&
+
+ find loose-src.git/objects/pack -name ".tmp-*" >tmp-leftovers &&
+ test_must_be_empty tmp-leftovers &&
+
+ test_path_is_file loose-src.git/objects/$path &&
+ git -C loose-src.git cat-file -e $big
+'
+
test_expect_success '--filter-to-loose does not move objects from kept packs' '
setup_loose_src &&
--
gitgitgadget
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
2026-11-13 22:11 ` [PATCH 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
@ 2026-11-14 20:08 ` Junio C Hamano
2026-11-25 1:42 ` Adithya Chakilam
0 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2026-11-14 20:08 UTC (permalink / raw)
To: Adithya Chakilam via GitGitGadget
Cc: git, Martin Fick, Christian Couder, Adithya Chakilam
"Adithya Chakilam via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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).
> +--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.
> 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.
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.
> 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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
2026-11-14 20:08 ` Junio C Hamano
@ 2026-11-25 1:42 ` Adithya Chakilam
0 siblings, 0 replies; 13+ messages in thread
From: Adithya Chakilam @ 2026-11-25 1:42 UTC (permalink / raw)
To: Junio C Hamano, Adithya Chakilam via GitGitGadget
Cc: git@vger.kernel.org, Martin Fick, Christian Couder
> > 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.
> > +--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.
> > 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.
> 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!
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 0/2] repack: write filtered-out objects as loose objects
2026-11-13 22:11 [PATCH 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-13 22:11 ` [PATCH 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
2026-11-13 22:11 ` [PATCH 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
@ 2026-11-25 1:44 ` Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
` (3 more replies)
2 siblings, 4 replies; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-25 1:44 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam
Some key-value object stores manage and retrieve Git objects individually.
The existing --filter-to option writes filtered-out objects into packs, so
using it with such stores requires unpacking the resulting packs before
importing the objects.
This series adds --filter-to-loose=dir to git repack, allowing filtered-out
objects to be written directly as loose objects into another object
directory.
With --filter-to-loose, repack streams the filtered pack into
unpack-objects, avoiding that extra step and the intermediate pack file. For
example:
git repack -a --filter=blob=1m --filter-to-loose=/path/to/objects
The destination is treated as a Git object directory.
The first patch adds the option for objects already stored in packs. The
second extends it to include loose objects excluded by the filter, so the
destination also receives those objects. Objects already present in the
destination are not rewritten. With -d, the source copies of those loose
objects are removed after all objects have been written successfully.
Adithya Chakilam (2):
repack: add --filter-to-loose to write filtered-out objects as loose
objects
repack: also copy loose objects excluded by --filter-to-loose
Documentation/git-repack.adoc | 15 ++-
builtin/repack.c | 36 +++++-
repack-filtered.c | 152 +++++++++++++++++++++-
repack.h | 14 +++
t/t7700-repack.sh | 231 ++++++++++++++++++++++++++++++++++
5 files changed, 441 insertions(+), 7 deletions(-)
base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2314%2Fachakilam-nv%2Ffilter-to-loose-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2314/achakilam-nv/filter-to-loose-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2314
Range-diff vs v1:
1: 4488a1534e ! 1: 4157ce33a1 repack: add --filter-to-loose to write filtered-out objects as loose objects
@@ Documentation/git-repack.adoc: SYNOPSIS
[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
[--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]
- [--filter=<filter-spec>] [--drop-filtered [--dry-run]]
-+ [--filter=<filter-spec> [--filter-to-loose=<dir>]] [--drop-filtered [--dry-run]]
++ [--filter=<filter-spec> [--filter-to-loose=<directory>]] [--drop-filtered [--dry-run]]
DESCRIPTION
-----------
@@ Documentation/git-repack.adoc: depth is 4095.
`objects` and `objects/info/alternates` sections of
linkgit:gitrepository-layout[5].
-+--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
++--filter-to-loose=<directory>::
++ Like `--filter-to`, but treat `<directory>` as an object
++ directory and write the filtered out objects there as loose
++ objects instead of as a pack. The directory must already
++ exist. Cannot be combined with `--filter-to` or
++ `--max-pack-size`. Objects already present in `<directory>` are
+ not rewritten. All objects are written before any existing
+ pack is removed.
+
@@ Documentation/git-repack.adoc: depth is 4095.
instead of keeping them in a separate packfile, reclaiming the
## builtin/repack.c ##
+@@
+ #define DISABLE_SIGN_COMPARE_WARNINGS
+
+ #include "builtin.h"
++#include "abspath.h"
+ #include "config.h"
+ #include "environment.h"
+ #include "parse-options.h"
@@ builtin/repack.c: 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]]"),
++ "[--filter=<filter-spec> [--filter-to-loose=<directory>]] [--drop-filtered [--dry-run]]"),
NULL
};
@@ builtin/repack.c: int cmd_repack(int argc,
N_("pack prefix to store a pack containing pruned objects")),
OPT_STRING(0, "filter-to", &filter_to, N_("dir"),
N_("pack prefix to store a pack containing filtered out objects")),
-+ OPT_STRING(0, "filter-to-loose", &filter_to_loose, N_("dir"),
++ OPT_FILENAME(0, "filter-to-loose", &filter_to_loose,
+ N_("object directory to write filtered out objects into as loose objects")),
OPT_BOOL(0, "drop-filtered", &drop_filtered,
N_("delete filtered out objects (requires --filter)")),
@@ builtin/repack.c: int cmd_repack(int argc,
+ die_for_incompatible_opt2(!!filter_to_loose, "--filter-to-loose",
+ !!po_args.max_pack_size, "--max-pack-size");
+
-+ if (filter_to_loose)
++ if (filter_to_loose) {
++ if (!is_directory(filter_to_loose))
++ die(_("'%s' is not a directory"), filter_to_loose);
+ filter_to = filter_to_loose;
++ }
if (dry_run && !drop_filtered)
die(_("--dry-run only takes effect with --drop-filtered"));
@@ repack-filtered.c: int write_filtered_pack(const struct write_pack_opts *opts,
- if (ret)
+ if (ret) {
+ if (opts->loose) {
-+ close(unpack.in);
++ /* start_command() already closed cmd.out, i.e. unpack.in */
+ finish_command(&unpack);
+ sigchain_pop(SIGPIPE);
+ }
@@ t/t7700-repack.sh: test_expect_success '--filter-to stores filtered out objects'
+ fi
+}
+
-+test_expect_success '--filter-to-loose failure to write leaves the source intact' '
++test_expect_success '--filter-to-loose requires an existing directory' '
++ setup_loose_src &&
++
++ ls loose-src.git/objects/pack/*.pack >packs-before &&
++ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
++ repack -a -d --filter=blob:limit=1k \
++ --filter-to-loose=../no-such-dir 2>err &&
++ test_grep "no-such-dir.*is not a directory" err &&
++ test_path_is_missing no-such-dir &&
++
++ ls loose-src.git/objects/pack/*.pack >packs-after &&
++ test_cmp packs-before packs-after &&
++ git -C loose-src.git cat-file -e $big
++'
++
++test_expect_success POSIXPERM,SANITY '--filter-to-loose failure to write leaves the source intact' '
+ setup_loose_src &&
-+ >not-a-dir &&
++ mkdir read-only &&
++ chmod a-w read-only &&
++ test_when_finished "chmod u+w read-only" &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
-+ --filter-to-loose=../not-a-dir &&
++ --filter-to-loose=../read-only &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-after &&
+ test_cmp packs-before packs-after &&
@@ t/t7700-repack.sh: test_expect_success '--filter-to stores filtered out objects'
+ git -C loose-src.git cat-file -e $big
+'
+
++test_expect_success '--filter-to-loose resolves a relative path from a subdirectory' '
++ rm -rf sub-work extra-loose-objects &&
++ git init sub-work &&
++ test-tool genrandom big 2k >sub-work/big &&
++ git -C sub-work add big &&
++ test_tick &&
++ git -C sub-work commit -m big &&
++ big=$(git -C sub-work rev-parse HEAD:big) &&
++ # objects in the index are never filtered out
++ git -C sub-work update-index --force-remove big &&
++ git -C sub-work repack -a -d &&
++
++ mkdir extra-loose-objects &&
++ mkdir -p sub-work/sub/dir &&
++ (
++ cd sub-work/sub/dir &&
++ git -c repack.writebitmaps=false repack -a -d \
++ --filter=blob:limit=1k \
++ --filter-to-loose=../../../extra-loose-objects
++ ) &&
++
++ test_path_is_file extra-loose-objects/$(test_oid_to_path $big)
++'
++
+test_expect_success '--filter-to-loose does not move objects from kept packs' '
+ setup_loose_src &&
+
@@ t/t7700-repack.sh: test_expect_success '--filter-to stores filtered out objects'
+'
+
+test_expect_success '--filter-to-loose requires --filter, rejects --filter-to and --max-pack-size' '
++ mkdir -p x y &&
+ test_must_fail git -C bare.git repack -a --filter-to-loose=../x 2>err &&
+ test_grep "can only be used along with" err &&
+
2: ba2534e3bc ! 2: 0f1f0356b4 repack: also copy loose objects excluded by --filter-to-loose
@@ Documentation/git-repack.adoc: depth is 4095.
pack is removed.
+ Loose objects in this repository that the filter excludes are
-+ copied to `<dir>` as well, and with `-d` the source copies are
++ copied to `<directory>` as well, and with `-d` the source copies are
+ removed once everything has been written.
+
--drop-filtered::
@@ t/t7700-repack.sh: setup_loose_src () {
+ git -C loose-dst.git fsck
+'
+
- test_expect_success '--filter-to-loose failure to write leaves the source intact' '
+ test_expect_success '--filter-to-loose requires an existing directory' '
setup_loose_src &&
- >not-a-dir &&
-@@ t/t7700-repack.sh: test_expect_success '--filter-to-loose failure to write leaves the source intact
- git -C loose-src.git cat-file -e $big
+
+@@ t/t7700-repack.sh: test_expect_success '--filter-to-loose resolves a relative path from a subdirect
+ test_path_is_file extra-loose-objects/$(test_oid_to_path $big)
'
+test_expect_success '--filter-to-loose failure to copy a loose object leaves the source intact' '
--
gitgitgadget
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
@ 2026-11-25 1:44 ` Adithya Chakilam via GitGitGadget
2026-11-25 19:07 ` Junio C Hamano
2026-11-25 1:44 ` [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-25 1:44 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam, Adithya Chakilam
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.
Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
---
Documentation/git-repack.adoc | 11 ++-
builtin/repack.c | 25 ++++-
repack-filtered.c | 44 ++++++++-
repack.h | 1 +
t/t7700-repack.sh | 172 ++++++++++++++++++++++++++++++++++
5 files changed, 246 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
index a1f9e64f66..bcd7c1fe54 100644
--- a/Documentation/git-repack.adoc
+++ b/Documentation/git-repack.adoc
@@ -12,7 +12,7 @@ SYNOPSIS
'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]
[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
[--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]
- [--filter=<filter-spec>] [--drop-filtered [--dry-run]]
+ [--filter=<filter-spec> [--filter-to-loose=<directory>]] [--drop-filtered [--dry-run]]
DESCRIPTION
-----------
@@ -183,6 +183,15 @@ depth is 4095.
`objects` and `objects/info/alternates` sections of
linkgit:gitrepository-layout[5].
+--filter-to-loose=<directory>::
+ Like `--filter-to`, but treat `<directory>` as an object
+ directory and write the filtered out objects there as loose
+ objects instead of as a pack. The directory must already
+ exist. Cannot be combined with `--filter-to` or
+ `--max-pack-size`. Objects already present in `<directory>` are
+ not rewritten. All objects are written before any existing
+ pack is removed.
+
--drop-filtered::
Delete the local objects that match the `--filter` specification
instead of keeping them in a separate packfile, reclaiming the
diff --git a/builtin/repack.c b/builtin/repack.c
index 21835453c6..dc2b4a3ce2 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,6 +1,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "builtin.h"
+#include "abspath.h"
#include "config.h"
#include "environment.h"
#include "parse-options.h"
@@ -41,7 +42,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=<directory>]] [--drop-filtered [--dry-run]]"),
NULL
};
@@ -182,6 +183,7 @@ int cmd_repack(int argc,
const char *cruft_expiration = NULL;
const char *expire_to = NULL;
const char *filter_to = NULL;
+ const char *filter_to_loose = NULL;
const char *opt_window = NULL;
const char *opt_window_memory = NULL;
const char *opt_depth = NULL;
@@ -257,6 +259,8 @@ int cmd_repack(int argc,
N_("pack prefix to store a pack containing pruned objects")),
OPT_STRING(0, "filter-to", &filter_to, N_("dir"),
N_("pack prefix to store a pack containing filtered out objects")),
+ OPT_FILENAME(0, "filter-to-loose", &filter_to_loose,
+ N_("object directory to write filtered out objects into as loose objects")),
OPT_BOOL(0, "drop-filtered", &drop_filtered,
N_("delete filtered out objects (requires --filter)")),
OPT_BOOL(0, "dry-run", &dry_run,
@@ -282,8 +286,19 @@ int cmd_repack(int argc,
po_args.depth = xstrdup_or_null(opt_depth);
po_args.threads = xstrdup_or_null(opt_threads);
- die_for_incompatible_opt2(drop_filtered, "--drop-filtered",
- !!filter_to, "--filter-to");
+ die_for_incompatible_opt3(drop_filtered, "--drop-filtered",
+ !!filter_to, "--filter-to",
+ !!filter_to_loose, "--filter-to-loose");
+ die_for_incompatible_opt2(!!filter_to, "--filter-to",
+ !!filter_to_loose, "--filter-to-loose");
+ die_for_incompatible_opt2(!!filter_to_loose, "--filter-to-loose",
+ !!po_args.max_pack_size, "--max-pack-size");
+
+ if (filter_to_loose) {
+ if (!is_directory(filter_to_loose))
+ die(_("'%s' is not a directory"), filter_to_loose);
+ filter_to = filter_to_loose;
+ }
if (dry_run && !drop_filtered)
die(_("--dry-run only takes effect with --drop-filtered"));
@@ -553,7 +568,8 @@ int cmd_repack(int argc,
strvec_pushf(&cmd.args, "--filter=%s",
expand_list_objects_filter_spec(&po_args.filter_options));
else if (filter_to)
- die(_("option '%s' can only be used along with '%s'"), "--filter-to", "--filter");
+ die(_("option '%s' can only be used along with '%s'"),
+ filter_to_loose ? "--filter-to-loose" : "--filter-to", "--filter");
if (geometry.split_factor)
cmd.in = -1;
@@ -698,6 +714,7 @@ int cmd_repack(int argc,
struct write_pack_opts opts = {
.po_args = &po_args,
.destination = filter_to,
+ .loose = !!filter_to_loose,
.packdir = packdir,
.packtmp = packtmp,
};
diff --git a/repack-filtered.c b/repack-filtered.c
index 869b9fc6e3..b33274b5b8 100644
--- a/repack-filtered.c
+++ b/repack-filtered.c
@@ -9,19 +9,40 @@
#include "list-objects-filter.h"
#include "odb.h"
#include "promisor-remote.h"
+#include "sigchain.h"
+
+static void start_unpack_objects(struct child_process *unpack,
+ const char *objdir)
+{
+ strvec_push(&unpack->args, "unpack-objects");
+ strvec_push(&unpack->args, "-q");
+ strvec_pushf(&unpack->env, "GIT_OBJECT_DIRECTORY=%s", objdir);
+ strvec_push(&unpack->env, "GIT_ALTERNATE_OBJECT_DIRECTORIES");
+ unpack->git_cmd = 1;
+ unpack->in = -1;
+ if (start_command(unpack))
+ die(_("could not start unpack-objects for '%s'"), objdir);
+}
int write_filtered_pack(const struct write_pack_opts *opts,
struct existing_packs *existing,
struct string_list *names)
{
struct child_process cmd = CHILD_PROCESS_INIT;
+ struct child_process unpack = CHILD_PROCESS_INIT;
struct string_list_item *item;
FILE *in;
int ret;
const char *caret;
const char *pack_prefix = write_pack_opts_pack_prefix(opts);
- prepare_pack_objects(&cmd, opts->po_args, opts->destination);
+ if (opts->loose) {
+ sigchain_push(SIGPIPE, SIG_IGN);
+ start_unpack_objects(&unpack, opts->destination);
+ prepare_pack_objects(&cmd, opts->po_args, "--stdout");
+ } else {
+ prepare_pack_objects(&cmd, opts->po_args, opts->destination);
+ }
strvec_push(&cmd.args, "--stdin-packs");
@@ -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) {
+ /* start_command() already closed cmd.out, i.e. unpack.in */
+ finish_command(&unpack);
+ sigchain_pop(SIGPIPE);
+ }
return ret;
+ }
/*
* Here 'names' contains only the pack(s) that were just
@@ -52,6 +81,17 @@ int write_filtered_pack(const struct write_pack_opts *opts,
fprintf(in, "%s%s.pack\n", caret, item->string);
fclose(in);
+ if (opts->loose) {
+ ret = finish_command(&cmd);
+ if (finish_command(&unpack))
+ ret = -1;
+ sigchain_pop(SIGPIPE);
+ if (ret)
+ ret = error(_("failed to write filtered out objects to '%s'"),
+ opts->destination);
+ return ret;
+ }
+
return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
names);
}
diff --git a/repack.h b/repack.h
index 61e554e4ed..d5528745ec 100644
--- a/repack.h
+++ b/repack.h
@@ -41,6 +41,7 @@ void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
struct write_pack_opts {
struct pack_objects_args *po_args;
const char *destination;
+ bool loose;
const char *packdir;
const char *packtmp;
};
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index f0a390e3c6..1b74d40551 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -489,6 +489,178 @@ test_expect_success '--filter-to stores filtered out objects' '
test "$blob_content" = "content1"
'
+test_expect_success '--filter-to-loose writes filtered out objects loose' '
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base file1 content1 &&
+ git clone --bare loose-work loose-src.git &&
+ git -C loose-src.git repack -a -d &&
+
+ blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob) &&
+ find loose-dst.git/objects/pack -name "*.pack" >actual-packs &&
+ test_must_be_empty actual-packs &&
+ test_must_fail git -C loose-src.git cat-file -e $blob &&
+
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ echo content1 >expect &&
+ git -C loose-src.git cat-file blob $blob >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--filter-to-loose writes objects that also exist in the source' '
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base file1 content1 &&
+ git clone --bare loose-work loose-src.git &&
+ git -C loose-src.git repack -a -d &&
+
+ blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob)
+'
+
+# Create loose-work/loose-src.git/loose-dst.git; $big is a 2k blob on
+# refs/heads/big in loose-src.git, packed unless $1 is "loose".
+setup_loose_src () {
+ rm -rf loose-work loose-src.git loose-dst.git &&
+ git init --bare loose-dst.git &&
+ git init loose-work &&
+ test_commit -C loose-work base small small &&
+ git clone --bare loose-work loose-src.git &&
+
+ big=$(test-tool genrandom big 2k | git -C loose-src.git hash-object -w --stdin) &&
+ tree=$(printf "100644 blob %s\tbig\n" $big | git -C loose-src.git mktree) &&
+ commit=$(git -C loose-src.git commit-tree -m big $tree) &&
+ git -C loose-src.git update-ref refs/heads/big $commit &&
+
+ if test "$1" != loose
+ then
+ git -C loose-src.git repack -a -d
+ fi
+}
+
+test_expect_success '--filter-to-loose requires an existing directory' '
+ setup_loose_src &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
+ --filter-to-loose=../no-such-dir 2>err &&
+ test_grep "no-such-dir.*is not a directory" err &&
+ test_path_is_missing no-such-dir &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-after &&
+ test_cmp packs-before packs-after &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success POSIXPERM,SANITY '--filter-to-loose failure to write leaves the source intact' '
+ setup_loose_src &&
+ mkdir read-only &&
+ chmod a-w read-only &&
+ test_when_finished "chmod u+w read-only" &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
+ --filter-to-loose=../read-only &&
+
+ ls loose-src.git/objects/pack/*.pack >packs-after &&
+ test_cmp packs-before packs-after &&
+
+ find loose-src.git/objects/pack -name ".tmp-*" >tmp-leftovers &&
+ test_must_be_empty tmp-leftovers &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose resolves a relative path from a subdirectory' '
+ rm -rf sub-work extra-loose-objects &&
+ git init sub-work &&
+ test-tool genrandom big 2k >sub-work/big &&
+ git -C sub-work add big &&
+ test_tick &&
+ git -C sub-work commit -m big &&
+ big=$(git -C sub-work rev-parse HEAD:big) &&
+ # objects in the index are never filtered out
+ git -C sub-work update-index --force-remove big &&
+ git -C sub-work repack -a -d &&
+
+ mkdir extra-loose-objects &&
+ mkdir -p sub-work/sub/dir &&
+ (
+ cd sub-work/sub/dir &&
+ git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k \
+ --filter-to-loose=../../../extra-loose-objects
+ ) &&
+
+ test_path_is_file extra-loose-objects/$(test_oid_to_path $big)
+'
+
+test_expect_success '--filter-to-loose does not move objects from kept packs' '
+ setup_loose_src &&
+
+ for p in loose-src.git/objects/pack/pack-*.pack
+ do
+ >${p%.pack}.keep || return 1
+ done &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_missing loose-dst.git/objects/$(test_oid_to_path $big) &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose leaves unreachable objects in cruft packs alone' '
+ setup_loose_src loose &&
+ git -C loose-src.git update-ref -d refs/heads/big &&
+ git -C loose-src.git repack --cruft -d &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d --cruft \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ test_path_is_missing loose-dst.git/objects/$(test_oid_to_path $big) &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose output survives gc and prune of the source' '
+ setup_loose_src &&
+
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ git -C loose-src.git gc --prune=now &&
+ git -C loose-src.git prune --expire=now &&
+
+ git -C loose-src.git fsck &&
+ git -C loose-src.git cat-file -e $big &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big)
+'
+
+test_expect_success '--filter-to-loose requires --filter, rejects --filter-to and --max-pack-size' '
+ mkdir -p x y &&
+ test_must_fail git -C bare.git repack -a --filter-to-loose=../x 2>err &&
+ test_grep "can only be used along with" err &&
+
+ test_must_fail git -C bare.git repack -a --filter=blob:none \
+ --filter-to=../y --filter-to-loose=../x 2>err &&
+ test_grep "cannot be used together" err &&
+
+ test_must_fail git -C bare.git repack -a --filter=blob:none \
+ --filter-to-loose=../x --max-pack-size=1M 2>err &&
+ test_grep "cannot be used together" err
+'
+
test_expect_success '--filter works with --max-pack-size' '
rm -rf filtered.git &&
git init --bare filtered.git &&
--
gitgitgadget
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
@ 2026-11-25 1:44 ` Adithya Chakilam via GitGitGadget
2026-11-25 19:27 ` Junio C Hamano
2026-11-25 19:37 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Junio C Hamano
2026-11-26 10:58 ` Christian Couder
3 siblings, 1 reply; 13+ messages in thread
From: Adithya Chakilam via GitGitGadget @ 2026-11-25 1:44 UTC (permalink / raw)
To: git; +Cc: Martin Fick, Christian Couder, Adithya Chakilam, Adithya Chakilam
From: Adithya Chakilam <achakilam@nvidia.com>
--filter-to-loose only writes objects that were in an existing pack,
because the filtered pack is built with --stdin-packs. Loose objects
that the filter excludes stay behind in the source repository, so the
destination does not get the complete set of filtered-out objects.
Copy such loose objects to the destination as well. An object already
present in the destination is not rewritten. With -d, the source copies
are removed once everything is written.
Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
---
Documentation/git-repack.adoc | 4 ++
builtin/repack.c | 11 ++++
repack-filtered.c | 108 ++++++++++++++++++++++++++++++++++
repack.h | 13 ++++
t/t7700-repack.sh | 59 +++++++++++++++++++
5 files changed, 195 insertions(+)
diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
index bcd7c1fe54..1cba380177 100644
--- a/Documentation/git-repack.adoc
+++ b/Documentation/git-repack.adoc
@@ -192,6 +192,10 @@ depth is 4095.
not rewritten. All objects are written before any existing
pack is removed.
+ Loose objects in this repository that the filter excludes are
+ copied to `<directory>` as well, and with `-d` the source copies are
+ removed once everything has been written.
+
--drop-filtered::
Delete the local objects that match the `--filter` specification
instead of keeping them in a separate packfile, reclaiming the
diff --git a/builtin/repack.c b/builtin/repack.c
index dc2b4a3ce2..46a50d7c7d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -184,6 +184,7 @@ int cmd_repack(int argc,
const char *expire_to = NULL;
const char *filter_to = NULL;
const char *filter_to_loose = NULL;
+ struct oidset moved_loose = OIDSET_INIT;
const char *opt_window = NULL;
const char *opt_window_memory = NULL;
const char *opt_depth = NULL;
@@ -725,6 +726,14 @@ int cmd_repack(int argc,
ret = write_filtered_pack(&opts, &existing, &names);
if (ret)
goto cleanup;
+
+ if (filter_to_loose) {
+ ret = move_loose_filtered_objects(repo,
+ &po_args.filter_options, filter_to,
+ &moved_loose);
+ if (ret)
+ goto cleanup;
+ }
}
string_list_sort(&names);
@@ -781,6 +790,7 @@ int cmd_repack(int argc,
if (show_progress)
opts |= PRUNE_PACKED_VERBOSE;
prune_packed_objects(repo, opts);
+ remove_moved_loose_objects(repo, &moved_loose);
if (!keep_unreachable &&
(!(pack_everything & LOOSEN_UNREACHABLE) ||
@@ -805,6 +815,7 @@ cleanup:
string_list_clear(&keep_pack_list, 0);
string_list_clear(&names, 1);
oidset_clear(&drop_oids);
+ oidset_clear(&moved_loose);
existing_packs_release(&existing);
pack_geometry_release(&geometry);
pack_objects_args_release(&po_args);
diff --git a/repack-filtered.c b/repack-filtered.c
index b33274b5b8..180c28a758 100644
--- a/repack-filtered.c
+++ b/repack-filtered.c
@@ -9,6 +9,11 @@
#include "list-objects-filter.h"
#include "odb.h"
#include "promisor-remote.h"
+#include "copy.h"
+#include "object-file.h"
+#include "odb/source-files.h"
+#include "oidset.h"
+#include "path.h"
#include "sigchain.h"
static void start_unpack_objects(struct child_process *unpack,
@@ -171,3 +176,106 @@ cleanup:
oidset_clear(&all_promisor_blobs);
return ret;
}
+
+static int collect_loose_oid(const struct object_id *oid,
+ const char *path UNUSED, void *cb_data)
+{
+ oidset_insert(cb_data, oid);
+ return 0;
+}
+
+static void dest_loose_path(struct strbuf *buf, const char *objdir,
+ const struct object_id *oid)
+{
+ const char *hex = oid_to_hex(oid);
+
+ strbuf_reset(buf);
+ strbuf_addf(buf, "%s/%.2s/%s", objdir, hex, hex + 2);
+}
+
+int move_loose_filtered_objects(struct repository *repo,
+ const struct list_objects_filter_options *filter,
+ const char *dest_objdir,
+ struct oidset *moved)
+{
+ struct odb_source_files *files =
+ odb_source_files_downcast(repo->objects->source);
+ struct oidset loose = OIDSET_INIT;
+ struct oidset omitted = OIDSET_INIT;
+ struct oidset_iter iter;
+ const struct object_id *oid;
+ struct strbuf src = STRBUF_INIT;
+ struct strbuf dst = STRBUF_INIT;
+ struct strbuf tmp = STRBUF_INIT;
+ int ret = 0;
+
+ if (filter->choice != LOFC_BLOB_LIMIT)
+ return 0;
+
+ ret = for_each_loose_file_in_source(&files->dirs->loose->base,
+ collect_loose_oid, NULL, NULL,
+ &loose);
+ if (ret)
+ goto out;
+ ret = list_objects_filter__filter_oidset(repo, filter, &loose,
+ &omitted);
+ if (ret)
+ goto out;
+
+ oidset_iter_init(&omitted, &iter);
+ while ((oid = oidset_iter_next(&iter))) {
+ odb_loose_path(files->dirs->loose, &src, oid);
+ dest_loose_path(&dst, dest_objdir, oid);
+
+ /*
+ * Only the destination decides whether the copy is needed;
+ * the object being present in the source says nothing.
+ */
+ if (!access(dst.buf, F_OK)) {
+ oidset_insert(moved, oid);
+ continue;
+ }
+
+ if (safe_create_leading_directories(repo, dst.buf) < 0) {
+ ret = error_errno(_("unable to create leading directories of '%s'"),
+ dst.buf);
+ goto out;
+ }
+ strbuf_reset(&tmp);
+ strbuf_addf(&tmp, "%s.tmp-%"PRIuMAX, dst.buf,
+ (uintmax_t)getpid());
+ if (copy_file(repo, tmp.buf, src.buf, 0444) ||
+ finalize_object_file(repo, tmp.buf, dst.buf)) {
+ unlink(tmp.buf);
+ ret = error(_("unable to copy loose object '%s' to '%s'"),
+ src.buf, dst.buf);
+ goto out;
+ }
+ oidset_insert(moved, oid);
+ }
+
+out:
+ oidset_clear(&loose);
+ oidset_clear(&omitted);
+ strbuf_release(&src);
+ strbuf_release(&dst);
+ strbuf_release(&tmp);
+ return ret;
+}
+
+void remove_moved_loose_objects(struct repository *repo,
+ const struct oidset *moved)
+{
+ struct odb_source_files *files =
+ odb_source_files_downcast(repo->objects->source);
+ struct strbuf path = STRBUF_INIT;
+ struct oidset_iter iter;
+ const struct object_id *oid;
+
+ oidset_iter_init(moved, &iter);
+ while ((oid = oidset_iter_next(&iter))) {
+ odb_loose_path(files->dirs->loose, &path, oid);
+ unlink(path.buf);
+ }
+ strbuf_release(&path);
+}
diff --git a/repack.h b/repack.h
index d5528745ec..18a0dc6314 100644
--- a/repack.h
+++ b/repack.h
@@ -168,6 +168,19 @@ int write_filtered_pack(const struct write_pack_opts *opts,
struct existing_packs *existing,
struct string_list *names);
+/*
+ * Copy loose objects that the filter excludes into the loose-object store
+ * at `dest_objdir`, recording them in `moved`.
+ */
+int move_loose_filtered_objects(struct repository *repo,
+ const struct list_objects_filter_options *filter,
+ const char *dest_objdir,
+ struct oidset *moved);
+
+/* Delete the source copies of objects copied by move_loose_filtered_objects. */
+void remove_moved_loose_objects(struct repository *repo,
+ const struct oidset *moved);
+
int enumerate_promisor_blobs(struct repository *repo,
const struct list_objects_filter_options *filter,
struct oidset *to_drop);
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 1b74d40551..d48ab73293 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -547,6 +547,44 @@ setup_loose_src () {
fi
}
+test_expect_success '--filter-to-loose copies loose filtered out blobs, and -d removes the source copy' '
+ setup_loose_src loose &&
+ test_path_is_file loose-src.git/objects/$(test_oid_to_path $big) &&
+
+ # without -d the source copy is left alone
+ git -C loose-src.git -c repack.writebitmaps=false repack -a \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_file loose-src.git/objects/$(test_oid_to_path $big) &&
+
+ # with -d it is removed from the source after being copied
+ rm -rf loose-dst.git/objects/$(dirname $(test_oid_to_path $big)) &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+ test_path_is_file loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_missing loose-src.git/objects/$(test_oid_to_path $big) &&
+ echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
+ git -C loose-src.git cat-file -e $big
+'
+
+test_expect_success '--filter-to-loose leaves an identical existing destination object alone' '
+ setup_loose_src &&
+
+ test-tool genrandom big 2k |
+ GIT_OBJECT_DIRECTORY=loose-dst.git/objects git hash-object -w --stdin &&
+
+ path=loose-dst.git/objects/$(test_oid_to_path $big) &&
+ test_path_is_file $path &&
+
+ ls -i $path >before &&
+ git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
+
+ ls -i $path >after &&
+ test_cmp before after &&
+ git -C loose-dst.git fsck
+'
+
test_expect_success '--filter-to-loose requires an existing directory' '
setup_loose_src &&
@@ -605,6 +643,27 @@ test_expect_success '--filter-to-loose resolves a relative path from a subdirect
test_path_is_file extra-loose-objects/$(test_oid_to_path $big)
'
+test_expect_success '--filter-to-loose failure to copy a loose object leaves the source intact' '
+ setup_loose_src loose &&
+ path=$(test_oid_to_path $big) &&
+ >loose-dst.git/objects/$(dirname $path) &&
+
+ find loose-src.git/objects/pack -name "*.pack" | sort >packs-before &&
+ test_must_fail git -C loose-src.git -c repack.writebitmaps=false \
+ repack -a -d --filter=blob:limit=1k \
+ --filter-to-loose=../loose-dst.git/objects 2>err &&
+
+ test_grep "unable to create leading directories" err &&
+ find loose-src.git/objects/pack -name "*.pack" | sort >packs-after &&
+ test_cmp packs-before packs-after &&
+
+ find loose-src.git/objects/pack -name ".tmp-*" >tmp-leftovers &&
+ test_must_be_empty tmp-leftovers &&
+
+ test_path_is_file loose-src.git/objects/$path &&
+ git -C loose-src.git cat-file -e $big
+'
+
test_expect_success '--filter-to-loose does not move objects from kept packs' '
setup_loose_src &&
--
gitgitgadget
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
2026-11-25 1:44 ` [PATCH v2 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
@ 2026-11-25 19:07 ` Junio C Hamano
0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2026-11-25 19:07 UTC (permalink / raw)
To: Adithya Chakilam via GitGitGadget
Cc: git, Martin Fick, Christian Couder, Adithya Chakilam
"Adithya Chakilam via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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.
Micronit: the patch to the documentation says <directory>, not <dir>.
> 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.
>
> Signed-off-by: Adithya Chakilam <achakilam@nvidia.com>
> ---
> Documentation/git-repack.adoc | 11 ++-
> builtin/repack.c | 25 ++++-
> repack-filtered.c | 44 ++++++++-
> repack.h | 1 +
> t/t7700-repack.sh | 172 ++++++++++++++++++++++++++++++++++
> 5 files changed, 246 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
> index a1f9e64f66..bcd7c1fe54 100644
> --- a/Documentation/git-repack.adoc
> +++ b/Documentation/git-repack.adoc
> @@ -12,7 +12,7 @@ SYNOPSIS
> 'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]
> [--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
> [--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]
> - [--filter=<filter-spec>] [--drop-filtered [--dry-run]]
> + [--filter=<filter-spec> [--filter-to-loose=<directory>]] [--drop-filtered [--dry-run]]
This is getting overly long. Time to line-wrap?
> @@ -183,6 +183,15 @@ depth is 4095.
> `objects` and `objects/info/alternates` sections of
> linkgit:gitrepository-layout[5].
>
> +--filter-to-loose=<directory>::
> + Like `--filter-to`, but treat `<directory>` as an object
> + directory and write the filtered out objects there as loose
> + objects instead of as a pack. The directory must already
> + exist. Cannot be combined with `--filter-to` or
> + `--max-pack-size`. Objects already present in `<directory>` are
> + not rewritten. All objects are written before any existing
> + pack is removed.
I wonder if the readers find this description sufficient to decide
between the use of this option and writing the evicted objects into a
pack. What is your motivation behind the addition of this option? What
makes it more useful to evict them as individual loose object files, as
opposed to a single 'junk' pack? Is there some lesson or story you can
offer to help the readers decide if this option matches their needs?
> diff --git a/builtin/repack.c b/builtin/repack.c
> index 21835453c6..dc2b4a3ce2 100644
> --- a/builtin/repack.c
> +++ b/builtin/repack.c
> @@ -1,6 +1,7 @@
> #define DISABLE_SIGN_COMPARE_WARNINGS
>
> #include "builtin.h"
> +#include "abspath.h"
> #include "config.h"
> #include "environment.h"
> #include "parse-options.h"
> @@ -41,7 +42,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=<directory>]] [--drop-filtered [--dry-run]]"),
> NULL
> };
>
> @@ -182,6 +183,7 @@ int cmd_repack(int argc,
> const char *cruft_expiration = NULL;
> const char *expire_to = NULL;
> const char *filter_to = NULL;
> + const char *filter_to_loose = NULL;
> const char *opt_window = NULL;
> const char *opt_window_memory = NULL;
> const char *opt_depth = NULL;
> @@ -257,6 +259,8 @@ int cmd_repack(int argc,
> N_("pack prefix to store a pack containing pruned objects")),
> OPT_STRING(0, "filter-to", &filter_to, N_("dir"),
> N_("pack prefix to store a pack containing filtered out objects")),
> + OPT_FILENAME(0, "filter-to-loose", &filter_to_loose,
> + N_("object directory to write filtered out objects into as loose objects")),
As OPT_FILENAME() always gives you a newly allocated string, you would
need to free(filter_to_loose) below the 'cleanup' label, where you
release resources held by other variables like 'po_args', 'existing',
etc.
It may make sense to drop 'const' from the type, as it seems to be our
convention to make things we pass to free() non-const.
> @@ -282,8 +286,19 @@ int cmd_repack(int argc,
> po_args.depth = xstrdup_or_null(opt_depth);
> po_args.threads = xstrdup_or_null(opt_threads);
>
> - die_for_incompatible_opt2(drop_filtered, "--drop-filtered",
> - !!filter_to, "--filter-to");
> + die_for_incompatible_opt3(drop_filtered, "--drop-filtered",
> + !!filter_to, "--filter-to",
> + !!filter_to_loose, "--filter-to-loose");
> + die_for_incompatible_opt2(!!filter_to, "--filter-to",
> + !!filter_to_loose, "--filter-to-loose");
> + die_for_incompatible_opt2(!!filter_to_loose, "--filter-to-loose",
> + !!po_args.max_pack_size, "--max-pack-size");
> +
> + if (filter_to_loose) {
> + if (!is_directory(filter_to_loose))
> + die(_("'%s' is not a directory"), filter_to_loose);
> + filter_to = filter_to_loose;
> + }
What happens when you use --filter-to-loose and specify your own object
directory, e.g., --filter-to-loose=objects in a bare repository, or
--filter-to-loose=.git/objects?
unpack-objects runs while the source packs are still on disk, sees via
odb_freshen_object() that every filtered-out object already exists in a
pack, and skips writing loose copies. With -d, cmd_repack() then
removes the old packs, losing those objects, I suspect.
Perhaps you want to prevent such permanent data loss by comparing
realpath(filter_to_loose) and repo_get_object_directory(repo) or
something? Perhaps add a test to make sure this does not happen?
> else if (filter_to)
> - die(_("option '%s' can only be used along with '%s'"), "--filter-to", "--filter");
> + die(_("option '%s' can only be used along with '%s'"),
> + filter_to_loose ? "--filter-to-loose" : "--filter-to", "--filter");
OK.
> +test_expect_success '--filter-to-loose writes filtered out objects loose' '
> + rm -rf loose-work loose-src.git loose-dst.git &&
> + git init --bare loose-dst.git &&
> + git init loose-work &&
> + test_commit -C loose-work base file1 content1 &&
> + git clone --bare loose-work loose-src.git &&
> + git -C loose-src.git repack -a -d &&
> +
> + blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
> + git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
> + --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
> +
> + test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob) &&
> + find loose-dst.git/objects/pack -name "*.pack" >actual-packs &&
> + test_must_be_empty actual-packs &&
> + test_must_fail git -C loose-src.git cat-file -e $blob &&
> +
> + echo $(pwd)/loose-dst.git/objects >loose-src.git/objects/info/alternates &&
> + echo content1 >expect &&
> + git -C loose-src.git cat-file blob $blob >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success '--filter-to-loose writes objects that also exist in the source' '
> + rm -rf loose-work loose-src.git loose-dst.git &&
> + git init --bare loose-dst.git &&
> + git init loose-work &&
> + test_commit -C loose-work base file1 content1 &&
> + git clone --bare loose-work loose-src.git &&
> + git -C loose-src.git repack -a -d &&
> +
> + blob=$(git -C loose-src.git rev-parse HEAD:file1) &&
> + git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
> + --filter=blob:none --filter-to-loose=../loose-dst.git/objects &&
> +
> + test_path_is_file loose-dst.git/objects/$(test_oid_to_path $blob)
> +'
Curious. This is identical to the early half of the previous test. If
the previous one passes, this one certainly would, as there is nothing
done differently.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose
2026-11-25 1:44 ` [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
@ 2026-11-25 19:27 ` Junio C Hamano
0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2026-11-25 19:27 UTC (permalink / raw)
To: Adithya Chakilam via GitGitGadget
Cc: git, Martin Fick, Christian Couder, Adithya Chakilam
"Adithya Chakilam via GitGitGadget" <gitgitgadget@gmail.com> writes:
> diff --git a/Documentation/git-repack.adoc b/Documentation/git-repack.adoc
> index bcd7c1fe54..1cba380177 100644
> --- a/Documentation/git-repack.adoc
> +++ b/Documentation/git-repack.adoc
> @@ -192,6 +192,10 @@ depth is 4095.
> not rewritten. All objects are written before any existing
> pack is removed.
>
> + Loose objects in this repository that the filter excludes are
> + copied to `<directory>` as well, and with `-d` the source copies are
> + removed once everything has been written.
> +
Does this format correctly? Have you tried "make doc" and checked the
rendered results?
Find and imitate how the next entry `--drop-filtered::` adds second and
subsequent paragraphs by prefixing them with a line with a lone '+' on
it, and not indenting them.
> --drop-filtered::
> Delete the local objects that match the `--filter` specification
> instead of keeping them in a separate packfile, reclaiming the
> diff --git a/repack-filtered.c b/repack-filtered.c
> index b33274b5b8..180c28a758 100644
> --- a/repack-filtered.c
> +++ b/repack-filtered.c
> + ...
> +int move_loose_filtered_objects(struct repository *repo,
> + const struct list_objects_filter_options *filter,
> + const char *dest_objdir,
> + struct oidset *moved)
> +{
> + struct odb_source_files *files =
> + odb_source_files_downcast(repo->objects->source);
> + struct oidset loose = OIDSET_INIT;
> + struct oidset omitted = OIDSET_INIT;
> + struct oidset_iter iter;
> + const struct object_id *oid;
> + struct strbuf src = STRBUF_INIT;
> + struct strbuf dst = STRBUF_INIT;
> + struct strbuf tmp = STRBUF_INIT;
> + int ret = 0;
> +
> + if (filter->choice != LOFC_BLOB_LIMIT)
> + return 0;
This silently turns move_loose_filtered_objects() into a no-op for every
filter other than 'blob:limit', doesn't it? That contradicts both the
proposed commit message and the documentation.
In particular, suppose a repository has a loose blob and the user runs
git repack -a -d --filter=blob:none --filter-to-loose=../dst/objects
The main pack-objects invocation excludes all blobs,
write_filtered_pack() passes --stdin-packs without --unpacked so it only
sees existing packs, and move_loose_filtered_objects() returns 0
immediately. The loose blob is neither copied to the destination nor
removed from the source. The code should support LOFC_BLOB_NONE at
least and document and reject unsupported filters, no?
> + ret = for_each_loose_file_in_source(&files->dirs->loose->base,
> + collect_loose_oid, NULL, NULL,
> + &loose);
> + if (ret)
> + goto out;
> + ret = list_objects_filter__filter_oidset(repo, filter, &loose,
> + &omitted);
> + if (ret)
> + goto out;
Enumerating every loose object on disk and filtering purely by size
ignores reachability, pack membership, and the index. Note that in
cmd_repack(), move_loose_filtered_objects() runs after the main pack and
any cruft pack have been written, yet before generated_pack_install()
and prune_packed_objects() have removed loose copies of newly packed
objects.
Consider three cases where a loose blob larger than the blob:limit
threshold exists in the source repository.
* with --cruft -a -d, write_cruft_pack() packs an unreachable loose
blob into the new cruft pack, leaving its loose file on disk until
prune_packed_objects() runs later. Because
move_loose_filtered_objects() runs beforehand and checks every loose
file, it copies that unreachable blob to the destination, breaking
the invariant tested in [1/2] that unreachable objects in cruft packs
are left alone. Am I mistaken?
* with -a -d (without --cruft), an unreachable loose blob is never
packed, yet move_loose_filtered_objects() copies it into the
destination and remove_moved_loose_objects() unlinks the source copy
immediately, bypassing normal prune expiration and polluting the
destination with unreachable objects.
* in a non-bare repository where a large loose blob is staged in the
index, pack-objects --indexed-objects keeps that blob in the main
pack rather than filtering it out, yet move_loose_filtered_objects()
still copies it to the destination.
In order to move only truly filtered-out reachable objects, a walk from
the refs over reachable objects, or filtering after packs are installed,
excluding any object that ended up in the kept/new/cruft packs or index,
is needed, instead of walking all loose files indiscriminately, no?
> + oidset_iter_init(&omitted, &iter);
> + while ((oid = oidset_iter_next(&iter))) {
> + odb_loose_path(files->dirs->loose, &src, oid);
> + dest_loose_path(&dst, dest_objdir, oid);
> +
> + /*
> + * Only the destination decides whether the copy is needed;
> + * the object being present in the source says nothing.
> + */
> + if (!access(dst.buf, F_OK)) {
> + oidset_insert(moved, oid);
> + continue;
> + }
As noted on [1/2], if dest_objdir is the source repository's own object
directory, dst and src refer to the same file, so access() succeeds and
remove_moved_loose_objects() unlinks the only copy of the loose object.
> + if (safe_create_leading_directories(repo, dst.buf) < 0) {
> + ret = error_errno(_("unable to create leading directories of '%s'"),
> + dst.buf);
> + goto out;
> + }
> + strbuf_reset(&tmp);
> + strbuf_addf(&tmp, "%s.tmp-%"PRIuMAX, dst.buf,
> + (uintmax_t)getpid());
> + if (copy_file(repo, tmp.buf, src.buf, 0444) ||
> + finalize_object_file(repo, tmp.buf, dst.buf)) {
Two issues:
* copy_file() maps mode 0444 to 0666 (masked by umask), so the written
loose object is writable instead of read-only 0444 as created by
normal loose-object writes. As we do not specify what the
destination directory really is (other than "it looks like an object
directory with a bunch of loose object files in it"), it might be OK
that such details are not identical to real object files, but I
suspect that it is not your intention to offer a poor imitation of
it.
* Naming the temporary file <oid>.tmp-<pid> uses O_EXCL against a fixed
PID name and does not match the tmp_obj_ prefix that fsck ignores, so
a crashed run leaves a file that triggers "bad sha1 file" warnings in
'git fsck' and can block a later run with the same PID.
Using a tmp_obj_XXXXXX template with git_mkstemp_mode(..., 0444) and
copy_fd() would avoid both of these problems.
> +void remove_moved_loose_objects(struct repository *repo,
> + const struct oidset *moved)
> +{
> + struct odb_source_files *files =
> + odb_source_files_downcast(repo->objects->source);
> + struct strbuf path = STRBUF_INIT;
> + struct oidset_iter iter;
> + const struct object_id *oid;
> +
> + oidset_iter_init(moved, &iter);
> + while ((oid = oidset_iter_next(&iter))) {
> + odb_loose_path(files->dirs->loose, &path, oid);
> + unlink(path.buf);
> + }
> + strbuf_release(&path);
> +}
Unlike prune_packed_objects() that use unlink_or_warn(), this silently
ignores unlink() errors. It also leaves empty 2-hex 'fan-out'
subdirectories behind, which may or may not matter.
> diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
> index 1b74d40551..d48ab73293 100755
> --- a/t/t7700-repack.sh
> +++ b/t/t7700-repack.sh
> @@ -547,6 +547,44 @@ setup_loose_src () {
> fi
> }
> ...
> +test_expect_success '--filter-to-loose leaves an identical existing destination object alone' '
> + setup_loose_src &&
> +
> + test-tool genrandom big 2k |
> + GIT_OBJECT_DIRECTORY=loose-dst.git/objects git hash-object -w --stdin &&
> +
> + path=loose-dst.git/objects/$(test_oid_to_path $big) &&
> + test_path_is_file $path &&
> +
> + ls -i $path >before &&
> + git -C loose-src.git -c repack.writebitmaps=false repack -a -d \
> + --filter=blob:limit=1k --filter-to-loose=../loose-dst.git/objects &&
> +
> + ls -i $path >after &&
> + test_cmp before after &&
> + git -C loose-dst.git fsck
> +'
I am not sure what this wants to test. Does this test [1/2]'s
unpack-objects code path, rather than the access() + copy_file() in
move_loose_filtered_objects() that is new code in this patch?
Also 'ls -i' as a measure of testing file identity is not portable (some
platforms lack the notion of i-num) and nowhere else in the t/ directory
do we use it. Perhaps 'test-tool chmtime' or something would serve as a
substitute?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] repack: write filtered-out objects as loose objects
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
@ 2026-11-25 19:37 ` Junio C Hamano
2026-11-26 10:58 ` Christian Couder
3 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2026-11-25 19:37 UTC (permalink / raw)
To: Adithya Chakilam via GitGitGadget
Cc: git, Martin Fick, Christian Couder, Adithya Chakilam
"Adithya Chakilam via GitGitGadget" <gitgitgadget@gmail.com> writes:
> git repack -a --filter=blob=1m --filter-to-loose=/path/to/objects
Shouldn't this be "--filter=blob:limit=1m"?
> The destination is treated as a Git object directory.
>
> The first patch adds the option for objects already stored in packs. The
> second extends it to include loose objects excluded by the filter, so the
> destination also receives those objects. Objects already present in the
> destination are not rewritten. With -d, the source copies of those loose
> objects are removed after all objects have been written successfully.
Note that as implemented, the second patch only handles blob:limit
filters and silently skips loose objects under other filters such as
blob:none, I think.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] repack: write filtered-out objects as loose objects
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
` (2 preceding siblings ...)
2026-11-25 19:37 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Junio C Hamano
@ 2026-11-26 10:58 ` Christian Couder
2026-11-30 6:33 ` Adithya Chakilam
3 siblings, 1 reply; 13+ messages in thread
From: Christian Couder @ 2026-11-26 10:58 UTC (permalink / raw)
To: Adithya Chakilam via GitGitGadget; +Cc: git, Martin Fick, Adithya Chakilam
On Wed, Nov 25, 2026 at 2:44 AM Adithya Chakilam via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> Some key-value object stores manage and retrieve Git objects individually.
> The existing --filter-to option writes filtered-out objects into packs, so
> using it with such stores requires unpacking the resulting packs before
> importing the objects.
One could say that it's the existing `--filter=<filter-spec>` option
that writes filtered-out objects into a separate pack, as it does so
even if `--filter-to=<dir>` isn't set. This means that
`--filter-to=<dir>` merely decides where the separate pack will be
written. When it is not set, `--filter=<filter-spec>` writes the
separate pack to the usual "<gitdir>/objects/pack/" directory.
> This series adds --filter-to-loose=dir to git repack, allowing filtered-out
> objects to be written directly as loose objects into another object
> directory.
What if someone wants to write the filtered-out objects as loose
objects into the repository's own "<gitdir>/objects/" directory? (Also
it looks like in patch 2, passing the repository's own
"<gitdir>/objects/" directory to `--filter-to-loose` might currently
cause data loss when combined with `-d`.)
It might be more coherent with how `--filter=<filter-spec>` and
`--drop-filtered` work to separate *how* filtered-out objects are
handled from *where* they are written. For example, with an option
like `--unpack-filtered` (or `--loosen-filtered`) alongside
`--filter=<filter-spec>` defaulting to "<gitdir>/objects/".
One issue with reusing `--filter-to` for the external destination is
that, despite the documentation calling it `--filter-to=<dir>`, it
currently takes a pack path prefix (e.g. ".../objects/pack/pack")
rather than an object directory. So its meaning might differ between
pack mode and loose mode. Still this seems worth thinking through
before going for `--filter-to-loose=<dir>`.
(Note that when I implemented `--filter-to=<dir>`, `--expire-to=<dir>`
was already passing a pack path prefix, so I thought it might be
actually OK or could be clarified later, though I failed to mention
it. Now I plan to send a patch to fix the docs for both
`--filter-to=<dir>` and `--expire-to=<dir>`, or at least to discuss
this separately.)
Thanks.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] repack: write filtered-out objects as loose objects
2026-11-26 10:58 ` Christian Couder
@ 2026-11-30 6:33 ` Adithya Chakilam
0 siblings, 0 replies; 13+ messages in thread
From: Adithya Chakilam @ 2026-11-30 6:33 UTC (permalink / raw)
To: Christian Couder, Adithya Chakilam via GitGitGadget
Cc: git@vger.kernel.org, Martin Fick
> > This series adds --filter-to-loose=dir to git repack, allowing filtered-out
> > objects to be written directly as loose objects into another object
> > directory.
>
> What if someone wants to write the filtered-out objects as loose
> objects into the repository's own "<gitdir>/objects/" directory? (Also
> it looks like in patch 2, passing the repository's own
> "<gitdir>/objects/" directory to `--filter-to-loose` might currently
> cause data loss when combined with `-d`.)
>
> It might be more coherent with how `--filter=<filter-spec>` and
> `--drop-filtered` work to separate *how* filtered-out objects are
> handled from *where* they are written. For example, with an option
> like `--unpack-filtered` (or `--loosen-filtered`) alongside
> `--filter=<filter-spec>` defaulting to "<gitdir>/objects/".
>
> One issue with reusing `--filter-to` for the external destination is
> that, despite the documentation calling it `--filter-to=<dir>`, it
> currently takes a pack path prefix (e.g. ".../objects/pack/pack")
> rather than an object directory. So its meaning might differ between
> pack mode and loose mode. Still this seems worth thinking through
> before going for `--filter-to-loose=<dir>`.
I like splitting how from where. My use case is writing the
filtered-out objects as loose objects into a different object
directory (one an alternate or a large-object promisor can read), not
only into <gitdir>/objects/.
With something like --loosen-filtered, how should that directory be
given ? It seems fine for --filter-to=<dir> to mean a pack prefix
normally and an object directory with --loosen-filtered, as long as
we document it ? Or would you rather have an optional argument, e.g.
--loosen-filtered[=<directory>], defaulting to <gitdir>/objects/ ?
Also, My idea was not to support the repository's own object directory,
to avoid handling all the cases that come up with -d. Is it okay to
leave that for later ?
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-30 6:33 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 22:11 [PATCH 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-13 22:11 ` [PATCH 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
2026-11-14 20:08 ` Junio C Hamano
2026-11-25 1:42 ` Adithya Chakilam
2026-11-13 22:11 ` [PATCH 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Adithya Chakilam via GitGitGadget
2026-11-25 1:44 ` [PATCH v2 1/2] repack: add --filter-to-loose to " Adithya Chakilam via GitGitGadget
2026-11-25 19:07 ` Junio C Hamano
2026-11-25 1:44 ` [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose Adithya Chakilam via GitGitGadget
2026-11-25 19:27 ` Junio C Hamano
2026-11-25 19:37 ` [PATCH v2 0/2] repack: write filtered-out objects as loose objects Junio C Hamano
2026-11-26 10:58 ` Christian Couder
2026-11-30 6:33 ` Adithya Chakilam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox