Git development
 help / color / mirror / Atom feed
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 1/2] repack: add --filter-to-loose to write filtered-out objects as loose objects
Date: Wed, 25 Nov 2026 11:07:38 -0800	[thread overview]
Message-ID: <xmqq4id43f2d.fsf@gitster.g> (raw)
In-Reply-To: <4157ce33a1d6c392575cc27fee7c6bd3126e97c6.1795571091.git.gitgitgadget@gmail.com> (Adithya Chakilam via GitGitGadget's message of "Wed, 25 Nov 2026 01:44:50 +0000")

"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.

  reply	other threads:[~2026-11-25 19:07 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 [this message]
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

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=xmqq4id43f2d.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