Re: git-ls-files(1) avoiding symlinks
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 6, 2026, 20:16 UTC
- Message-ID
- <xmqqeccxhg0f.fsf@gitster.g>
- In-Reply-To
- <au4rmQRjRtIv1Oru@debian>
Alejandro Colomar <alx+git@kernel.org> writes:
Show 7 quoted lines
>> > 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?
Show 5 quoted lines
>> > 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 -ldthe 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.