Re: [PATCH 5/6] builtin/repo: add disk size info to keyvalue stucture output
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Dec 12, 2025, 20:40 UTC
- Message-ID
- <54kuvik2ecbkygjp57osmqjxiy7xtyjeffbzavuxbhuvta2oc5@mkqufah7cb3z>
- In-Reply-To
- <aTkTCplQuSX_Y3oG@pks.im>
On 25/12/10 07:28AM, Patrick Steinhardt wrote:
Show 34 quoted lines
> 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.
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.
Regardless, in the tests I can hack around this problem by using something like:
$ git cat-file --batch-check='$(objectsize:disk)' --batch-all-objects \
--filter=object:type=tree | awk '{ sum += $1 } END { print sum }'to add up the sizes by object type. This doesn't really leave me a great way to verify the human-readable values in the table output though. I may just continue to omit those values from the test like I already do in the next patch.
-Justin