Hi Junio, thanks for taking a look! On Wed, Jun 21, 2023 at 9:08 AM Junio C Hamano <gitster@xxxxxxxxx> wrote: > > Jeff King <peff@xxxxxxxx> 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! > 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