Re: [PATCH] ls-files: add an --exclude-links option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> 
> 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". 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 ...

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.

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux