* git-ls-files(1) avoiding symlinks
@ 2026-11-06 13:35 Alejandro Colomar
2026-11-06 14:15 ` D. Ben Knoble
0 siblings, 1 reply; 6+ messages in thread
From: Alejandro Colomar @ 2026-11-06 13:35 UTC (permalink / raw)
To: git; +Cc: Andy Shevchenko, Linus Torvalds, Krzysztof Kozlowski
[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]
Hi!
Yesterday, we were discussing alternative methods for grepping source
code. Here's a list of similar alternatives:
$ find . -type f | xargs grep ARRAY_END;
$ git ls-files | xargs grep ARRAY_END;
$ git grep ARRAY_END;
The version using find(1) has some problems: it is slow, especially
after having built a kernel, when the directory is full of temporary
objects.
The version using git-grep(1) without IPC is the fastest, and doesn't
have any problems, but it is limited to just grep(1). If we want to use
sed(1), or any other programs, we're out of luck.
A common program I want to use is grepc(1), which searches source code.
See for example this code for finding the creat(2) system call:
$ git ls-files | grep '\.[ch]$' | xargs grepc creat;
fs/open.c:SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
{
int flags = O_CREAT | O_WRONLY | O_TRUNC;
if (force_o_largefile())
flags |= O_LARGEFILE;
return do_sys_open(AT_FDCWD, pathname, flags, mode);
}
include/linux/syscalls.h:asmlinkage long sys_creat(const char __user *pathname, umode_t mode);
tools/include/nolibc/fcntl.h:static __attribute__((unused))
int creat(const char *path, mode_t mode)
{
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
}
A problem with git-ls-files(1) is that it doesn't have a way to filter
files by type. That is, it will list symlinks, which will affect the
search. With find(1), I can control that with '-type f', which makes
sure I only search in regular files. I'd like to have some feature in
git-ls-files(1) that allows me to print files of the specified type.
Since git(1) knows the type of the files, this should be doable without
much overhead, right?
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: git-ls-files(1) avoiding symlinks
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
0 siblings, 1 reply; 6+ messages in thread
From: D. Ben Knoble @ 2026-11-06 14:15 UTC (permalink / raw)
To: Alejandro Colomar
Cc: git, Andy Shevchenko, Linus Torvalds, Krzysztof Kozlowski
On Fri, Nov 6, 2026 at 8:35 AM Alejandro Colomar <alx+git@kernel.org> wrote:
>
> Hi!
>
> Yesterday, we were discussing alternative methods for grepping source
> code. Here's a list of similar alternatives:
>
> $ find . -type f | xargs grep ARRAY_END;
> $ git ls-files | xargs grep ARRAY_END;
> $ git grep ARRAY_END;
>
> The version using find(1) has some problems: it is slow, especially
> after having built a kernel, when the directory is full of temporary
> objects.
>
> The version using git-grep(1) without IPC is the fastest, and doesn't
> have any problems, but it is limited to just grep(1). If we want to use
> sed(1), or any other programs, we're out of luck.
>
> A common program I want to use is grepc(1), which searches source code.
> See for example this code for finding the creat(2) system call:
>
> $ git ls-files | grep '\.[ch]$' | xargs grepc creat;
> fs/open.c:SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
> {
> int flags = O_CREAT | O_WRONLY | O_TRUNC;
>
> if (force_o_largefile())
> flags |= O_LARGEFILE;
> return do_sys_open(AT_FDCWD, pathname, flags, mode);
> }
> include/linux/syscalls.h:asmlinkage long sys_creat(const char __user *pathname, umode_t mode);
> tools/include/nolibc/fcntl.h:static __attribute__((unused))
> int creat(const char *path, mode_t mode)
> {
> return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
> }
>
> A problem with git-ls-files(1) is that it doesn't have a way to filter
> files by type. That is, it will list symlinks, which will affect the
> search. With find(1), I can control that with '-type f', which makes
> sure I only search in regular files. I'd like to have some feature in
> git-ls-files(1) that allows me to print files of the specified type.
> Since git(1) knows the type of the files, this should be doable without
> much overhead, right?
Perhaps something with "git ls-files --format='%(objectmode) %(path)'
-z"? Of course, your examples already omit -z, so if you can assume
that it might be simpler.
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: git-ls-files(1) avoiding symlinks
2026-11-06 14:15 ` D. Ben Knoble
@ 2026-11-06 14:45 ` Alejandro Colomar
[not found] ` <AE63992D-7BEA-413D-A372-78708CFA8F6F@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Alejandro Colomar @ 2026-11-06 14:45 UTC (permalink / raw)
To: D. Ben Knoble; +Cc: git, Andy Shevchenko, Linus Torvalds, Krzysztof Kozlowski
[-- Attachment #1: Type: text/plain, Size: 1442 bytes --]
Hi Ben,
> Date: 2026-11-06 09:15:22-0500
> From: "D. Ben Knoble" <ben.knoble@gmail.com>
>
[...]
> > A problem with git-ls-files(1) is that it doesn't have a way to filter
> > files by type. That is, it will list symlinks, which will affect the
> > search. With find(1), I can control that with '-type f', which makes
> > sure I only search in regular files. I'd like to have some feature in
> > git-ls-files(1) that allows me to print files of the specified type.
> > Since git(1) knows the type of the files, this should be doable without
> > much overhead, right?
>
> Perhaps something with "git ls-files --format='%(objectmode) %(path)'
> -z"? Of course, your examples already omit -z, so if you can assume
> that it might be simpler.
Hmmm, that could work. Thanks!
$ git ls-files --format='%(objectmode) %(path)' \
| grep -v ^120000 \
| sed 's/^.* //' \
| grep '\.[ch]$' \
| xargs grepc creat;
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;
But, indeed, I don't care about files with spaces often, because I don't
create them in my stuff.
I expect git-ls-files(1) could make this much simpler, though:
$ git ls-files --type f \
| grep '\.[ch]$' \
| xargs grepc creat;
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-06 21:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-06 21:06 ` Alejandro Colomar
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.