From: Ævar Arnfjörð Bjarmason Date: Mon, 15 Nov 2021 15:13:24 GMT Subject: Re: [PATCH 0/3] support `--oid-only` in `ls-tree` Message-ID: <211115.86mtm5saz7.gmgdl@evledraar.gmail.com> In-Reply-To: <20211115115153.48307-1-dyroneteng@gmail.com> On Mon, Nov 15 2021, Teng Long wrote: > Sometimes, we only want to get the objects from output of `ls-tree` > and commands like `sed` or `cut` is usually used to intercept the > origin output to achieve this purpose in practical. > > The patch contains three commits > > 1. Implementation of the option. > 2. Add new tests in "t3104". > 3. Documentation modifications. > > I'm appreciate if someone help to review the patch. I've looked it over, they look correct mostly, the test code in 2/3 looks a bit too complex (using find?). But I'd much rather see this be done with adding strbuf_expand() to ls-tree. I.e. its docs say that it can emit: SP SP TAB Or, with -l: SP SP SP TAB If you use strbuf_expand() you can just define a default format of: %(objectmode) SP %(objecttype) SP %(objectname) TAB %(path) Then make the existing -l option a shorthand for tweaking that to: %(objectmode) SP %(objecttype) SP %(objectsize) SP %(objectname) TAB %(path) Then you can get what you want out of this with a simple: git ls-tree --format="%(objectname)" See e.g. git-cat-file for an existing use of strbuf_expand().