Subject: Re: [PATCH 5/6] builtin/repo: add disk size info to keyvalue stucture output

From: Patrick Steinhardt <[email-masked]>
Date: Mon, 15 Dec 2025 06:33:01 +0100

On Fri, Dec 12, 2025 at 02:40:24PM -0600, Justin Tobler wrote:
> On 25/12/10 07:28AM, Patrick Steinhardt wrote:
> > On Tue, Dec 09, 2025 at 04:58:19PM -0600, Justin Tobler wrote:
> > > @@ -106,16 +137,12 @@ test_expect_success SHA1 'keyvalue and nul format' '
> > >  		objects.tags.inflated=132
> > >  		EOF
> > >  
> > > -		git repo structure --format=keyvalue >out 2>err &&
> > > +		git repo structure --format=keyvalue >out.raw 2>err &&
> > >  
> > > -		test_cmp expect out &&
> > > -		test_line_count = 0 err &&
> > > +		# Strip object disk usage from output due to platform variance.
> > > +		grep -v "objects\..*\.disk=" out.raw >out &&
> > >  
> > > -		# Replace key and value delimiters for nul format.
> > > -		tr "\n=" "\0\n" <expect >expect_nul &&
> > > -		git repo structure --format=nul >out 2>err &&
> > > -
> > > -		test_cmp expect_nul out &&
> > > +		test_cmp expect out &&
> > >  		test_line_count = 0 err
> > >  	)
> > >  '
> > 
> > We could test disk sizes here test if we use git-rev-list(1) to compute
> > disk size by type:
> > 
> >     git rev-list --disk-usage HEAD --objects --filter=object:type=blob
> >     git rev-list --disk-usage HEAD --objects --filter=object:type=commit
> >     git rev-list --disk-usage HEAD --objects --filter=object:type=tag
> >     git rev-list --disk-usage HEAD --objects --filter=object:type=tree
> > 
> > The `--disk-usage` option also supports `--disk-usage=human`, which we
> > can use in the next commit to verify that our computations are the same
> > across git-rev-list(1) and git-repo(1).
> 
> So, I'm not sure we can use git-rev-list(1) in the manner suggested
> above. It looks like user-specified objects are always included in the
> output. When using "HEAD" this means the referenced object will always
> be included regardless of the filter used. In practice, this means
> reported disk-usage when filtering by trees or blobs will likely be
> inflated by objects not specified by the filter. As far as I am aware,
> there is not a way to suppress user-specified objects in git-rev-list(1)
> output.

There is, you can use "--filter-provided-objects".

> I am somewhat curious if always including user-specified objects in
> git-rev-list(1) output regardless of the specified filter is
> intentional. Looking at git-rev-list(1) --filter documentation:
> 
>   The form --filter=object:type=(tag|commit|tree|blob) omits all objects
>   which are not of the requested type.
> 
> doesn't indicate this limitation. From looking at the code in
> list-objects-filter.c:list_objects_filter__filter_object() though, it
> does somewhat seem like this behavior is intentional.

It is intentional, but I've been bitten by it in the past. Hence I
introduced the above option in 9cf68b27d5 (rev-list: allow filtering of
provided items, 2021-04-19).

Patrick