Re: [PATCH] ls-files: add an --exclude-links option
- From
- Guido Martínez <mtzguido@gmail.com>
- Date
- Jun 21, 2023, 15:19 UTC
- Message-ID
- <CA++DQUkM-o4_zR=oK=kF=wE5youvQ4iQrw2KyTTGhNbcUViTdg@mail.gmail.com>
- In-Reply-To
- <20230621081754.GA803861@coredump.intra.peff.net>
Hi Jeff, thanks for reviewing!
On Wed, Jun 21, 2023 at 1:17 AM Jeff King <peff@peff.net> wrote:
Show 20 quoted lines
> > On Wed, Jun 21, 2023 at 06:08:04AM +0000, Guido Martínez via GitGitGadget wrote: > > > From: =?UTF-8?q?Guido=20Mart=C3=ADnez?= <mtzguido@gmail.com> > > > > Add an option to exclude symlinks from the listed files. This is useful > > in case we are listing the files in order to process the contents, > > for instance to do some text replacement with `sed -i`. In that case, > > there is no point in processing the links, and it could even be > > counterproductive as some tools (like sed) will replace the link with a > > fresh regular file. > > > > This option enables a straightforward implementation of a `git sed`: > > > > #!/bin/bash > > git ls-files --exclude-links -z | xargs -0 -P $(nproc) -- sed -i -e "$@" > > This invocation would likewise have a problem with gitlink entries (for > submodules). I think what you really want is not "exclude symlinks" but > "show only regular files".
Ah, thanks! I hadn't realized that. I suppose my patch should also come with a few tests, including one with submodules.
Show 13 quoted lines
> There is no option for that, but you can do > it by grepping modes from "-s", like: > > git ls-files -s | grep '^100[67]' | ... > > You do unfortunately have to then pull the filename out of the rest of > the line, and since we didn't use "-z", it will be quoted (and using > "-z" makes it hard to use tools like grep and sed). A mild application > of perl works, though: > > git ls-files -s | > perl -0ne 'print if s/^100(644|755).*?\t//' | > xargs -0 ...
My perl-foo is not as strong, so I didn't realize perl could do this kind of thing :) Still it may be desirable for ls-files to do the filtering itself?
Show 8 quoted lines
> So I dunno. That is not exactly pretty, but if you were hiding it in a > "git sed" alias or script, it's not so bad. > > If we were to add an option to ls-files, it would make more sense to me > to allow the user to include/exclude by mode or possibly naming the type > (e.g., "f" for regular files, "l" for symbolic links, etc, which matches > "find"). And then allow inclusion/exclusion similar to the way that > git-diff's --diff-filter option works.
Yes, this is totally reasonable. I'll try to get that working here and resubmit.
Thanks, Guido
> > -Peff