git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
GMGuido Martínez <mtzguido@gmail.com>
Date
Jun 21, 2023, 17:54 UTC
Message-ID
<CA++DQUkVzz8Zn0x6BR+sAEo_LXFR67Z+JOgMhcY2JpS5UGi4rw@mail.gmail.com>
In-Reply-To
<xmqqzg4siyru.fsf@gitster.g>
Hi Junio, thanks for taking a look!
On Wed, Jun 21, 2023 at 9:08 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
>
> Jeff King <peff@peff.net> writes:
>
> >> 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 "$@"
>
> Unrelated nit.
>
> I think -i -e above is iffy, as it does not distribute -e across
> "$@" and your users may not always want to edit the files.  It is
> better to leave them to the callers.
>
> "sed" is also something the caller can easily pass from their
> command line, for that matter ;-).
I should have known my one-liner would be torn to shreds :-). But yes, agreed!
Show 23 quoted lines
> Passing the entire command
> part run under xargs from the command line of the wrapper,
>
>     $ git for-all-paths grep -e pattern
>
> would also work just fine, for example.
>
> > ... A mild application of perl works, though:
> >
> >   git ls-files -s -z |
> >   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.
>
> Yes, the above would be a perfectly reasonable implementation of
> "git for-all-paths", especially if you do not hardcode anything in
> the ... part and instead use something like xargs -0 "$@" there.
>
> What is somewhat unsatisfactory is that we cannot pass pathspec to
> the "ls-files" so that the command does not have to be for-all-paths
> but can be usable as "git do-for-paths -c '<command>' <pathspec>".

Indeed, a command like that would be great, and doing `git do-for-paths -c "sed -i 's/old/new/g'"` is still extremely convenient. I suppose this command should take options -n and -P to pass to xargs. In the case of sed, running in batches is _much_ faster than 1-by-1, and it trivially parallelizes.

So would it make sense to 1- Add the file type filter to ls-files 2- Use that to implement a proper git-do-for-paths script/binary, which can take pathspecs, filetype filters, -n, -P, and maybe more ?

Thanks again! Guido

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 7 in “ls-files: add an --exclude-links option”
  1. ls-files: add an --exclude-links optionGuido Martínez via GitGitGadget, Jun 21, 2023
  2. Jeff KingJun 21, 2023
  3. Guido MartínezJun 21, 2023
  4. Junio C HamanoJun 21, 2023
  5. Guido MartínezJun 21, 2023
  6. Junio C HamanoJun 21, 2023
  7. Guido MartínezJun 21, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.