Re: [Question] Can git cat-file have a type filtering option?
- From
ZheNing Hu <adlternative@gmail.com>
- Date
- Apr 8, 2023, 06:27 UTC
- Message-ID
- <CAOLTT8SXXKG3uEd8Q=uh3zx7XeUDUWezGgNUSCd1Fpq-Kyy-2A@mail.gmail.com>
- In-Reply-To
- <xmqqy1n3k63p.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2023年4月8日周六 00:30写道:
Show 12 quoted lines
> > ZheNing Hu <adlternative@gmail.com> writes: > > > all blobs, and then use `git cat-file --batch` to retrieve them. This > > is not very elegant, or in other words, it might be better to have an > > internal implementation of filtering within `git cat-file > > --batch-all-objects`. > > It does sound prominently elegant to have each tool does one task > and does it well, and being able to flexibly combine them to achieve > a larger task. >
Okay, you're right. It's not "ungraceful" to have each task do its own thing. I should clarify that for a command like `git cat-file --batch-all-objects`, which traverses all objects, it would be better to have a filter. It might be more performant than using `git rev-list --filter | git cat-file --batch`?
Show 17 quoted lines
> Once that approach is working well, it may still make sense to give > a special case codepath that bundles a specific combination of these > primitive features, if use cases for the specific combination appear > often. But I do not know if the particular one, "we do not want to > feed specific list of objects to check to 'cat-file --batch'", > qualifies as one. > > > For example, `--type-filter`? > > Is the object type the only thing that people often would want to > base their filtering decision on? Will we then see somebody else > request a "--size-filter", and then somebody else realizes that the > filtering criteria based on size need to be different between blobs > (most likely counted in bytes) and trees (it may be more convenient > to count the tree entries, not byes)? It sounds rather messy and > we may be better off having such an extensible logic in one place. >
Yes, having a generic filter for `git cat-file` would be better.
Show 7 quoted lines
> Like rev-list's object list filtering, that is. > > Is the logic that implements rev-list's object list filtering > something that is easily called from the side, as if it were a > library routine? Refactoring that and teaching cat-file an option > to activate that logic might be more palatable. >
I don't think so. While `git rev-list` traverses objects and performs filtering within a revision, `git cat-file --batch-all-objects` traverses all loose and packed objects. It might be difficult to perfectly extract the filtering from `git rev-list` and apply it to `git cat-file`.
> Thanks.