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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 21, 2023, 16:08 UTC
Message-ID
<xmqqzg4siyru.fsf@gitster.g>
In-Reply-To
<20230621081754.GA803861@coredump.intra.peff.net>
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 ;-). 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.
Show 8 quoted lines
> ... 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>".

Previous: Guido MartínezNext: Guido Martínez
Message 4 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.