From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Guido Martínez via GitGitGadget" <gitgitgadget@gmail.com>,
git@vger.kernel.org, "Guido Martínez" <mtzguido@gmail.com>
Subject: Re: [PATCH] ls-files: add an --exclude-links option
Date: Wed, 21 Jun 2023 09:08:21 -0700 [thread overview]
Message-ID: <xmqqzg4siyru.fsf@gitster.g> (raw)
In-Reply-To: <20230621081754.GA803861@coredump.intra.peff.net> (Jeff King's message of "Wed, 21 Jun 2023 04:17:54 -0400")
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.
> ... 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>".
next prev parent reply other threads:[~2023-06-21 16:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 6:08 [PATCH] ls-files: add an --exclude-links option Guido Martínez via GitGitGadget
2023-06-21 8:17 ` Jeff King
2023-06-21 15:19 ` Guido Martínez
2023-06-21 16:08 ` Junio C Hamano [this message]
2023-06-21 17:54 ` Guido Martínez
2023-06-21 19:47 ` Junio C Hamano
2023-06-21 20:02 ` Guido Martínez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzg4siyru.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=mtzguido@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).