From: Junio C Hamano <gitster@pobox.com>
To: "Adithya Chakilam via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Martin Fick <mfick@nvidia.com>,
Christian Couder <christian.couder@gmail.com>,
Adithya Chakilam <achakilam@nvidia.com>
Subject: Re: [PATCH v2 2/2] repack: also copy loose objects excluded by --filter-to-loose
Date: Wed, 25 Nov 2026 11:27:38 -0800 [thread overview]
Message-ID: <xmqqwlq01zkl.fsf@gitster.g> (raw)
In-Reply-To: <0f1f0356b46e59cb588b046540034e09dfa7fe7d.1795571091.git.gitgitgadget@gmail.com> (Adithya Chakilam via GitGitGadget's message of "Wed, 25 Nov 2026 01:44:51 +0000")
"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?
next prev parent reply other threads:[~2026-11-25 19:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqwlq01zkl.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=achakilam@nvidia.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=mfick@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox