From: Junio C Hamano <gitster@pobox.com>
To: Alejandro Colomar <alx+git@kernel.org>
Cc: Ben Knoble <ben.knoble@gmail.com>,
git@vger.kernel.org, Andy Shevchenko <andy@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: git-ls-files(1) avoiding symlinks
Date: Fri, 06 Nov 2026 12:16:48 -0800 [thread overview]
Message-ID: <xmqqeccxhg0f.fsf@gitster.g> (raw)
In-Reply-To: <au4rmQRjRtIv1Oru@debian> (Alejandro Colomar's message of "Fri, 6 Nov 2026 20:36:31 +0100")
Alejandro Colomar <alx+git@kernel.org> writes:
>> > With -z it becomes a bit tedious:
>> >
>> > $ git ls-files -z --format='%(objectmode) %(path)' \
>> > | grep -zv ^120000 \
>> > | sed -z 's/^.* //' \
>> > | grep -z '\.[ch]$' \
>> > | xargs -0 grepc creat;
Shouldn't the grep|sed|grep be doable with a single sed invocation?
>> > I expect git-ls-files(1) could make this much simpler, though:
>> >
>> > $ git ls-files --type f \
>> > | grep '\.[ch]$' \
>> > | xargs grepc creat;
Not really. Why is "--type" have to be so special? What would the
next person ask for? --size?
The "ls-files" plumbing command is designed as a component to build
your own pipeline with. Don't throw in random unrelated features to
it. In the longer run, it is not a good substitute for improving
the skill to construct a good pipeline.
Learn the tools available to you that you already have heard of, so
that you can make better uses of them (in this case "sed"). If you
squash the grep|sed|grep pipeline into a single sed
git ls-files -z -s "*.[ch]" |
sed -z -n -e '/^120000/d' -e '/^.* 0 /s///p' |
xargs -r -0 ls -ld
the result does not look too bad.
One unrelated tip for better readability is to end, not begin, your
lines with the "|" pipe characters. That way you do not have to
sprinkle so many unsightly backslashes ;-).
HTH.
next prev parent reply other threads:[~2026-11-06 20:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:35 git-ls-files(1) avoiding symlinks Alejandro Colomar
2026-11-06 14:15 ` D. Ben Knoble
2026-11-06 14:45 ` Alejandro Colomar
[not found] ` <AE63992D-7BEA-413D-A372-78708CFA8F6F@gmail.com>
2026-11-06 19:36 ` Alejandro Colomar
2026-11-06 20:16 ` Junio C Hamano [this message]
2026-11-06 21:06 ` Alejandro Colomar
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=xmqqeccxhg0f.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=alx+git@kernel.org \
--cc=andy@kernel.org \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=krzk@kernel.org \
--cc=torvalds@linux-foundation.org \
/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