New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the git-sed command #709
Conversation
This is more in-line with how sed itself works.
A little question: |
I answered this in the git commit message:
This is more in-line with how sed itself works.
So, it makes git-sed a little more familiar to sed users.
|
@pabs3 |
bin/git-sed
Outdated
sep=/ | ||
;; | ||
esac | ||
command="git grep -lz '$search' | xargs -0r sed -i 's$sep$search$sep$replacement$sep$flags'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-r
option is a GNU extension. The xargs
in OS X doesn't support it.
We have to remove it for the compatibility.
@@ -3,12 +3,12 @@ git-sed(1) -- replace patterns in git-controlled files | |||
|
|||
## SYNOPSIS | |||
|
|||
`git-sed` [ -c ] [ -f <flags> ] <search> <replacement> | |||
`git-sed` [ -c ] [ -f <flags> ] <search> <replacement> [ <flags> ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to update the html and man page.
See https://github.com/tj/git-extras/blob/master/man/Readme.md
I've updated my branch to add a mechanism to check if the xargs -r
option exists and only use it when it does exist.
For the manual pages:
* Personally I don't think it is appropriate to include automatically
generated files in a git repository containing the source. I would
put generated files into either the website git or into packages for
end-users but not into the source git repository.
* There are two different build mechanisms that produce two different
results for manual pages. Both of them produce different results
than the files that are already in the git repository.
* Most of the files need updating at minimum for the dates.
* The ronn tool does not seem to perform deterministic builds,
it seems to insert random characters into email addresses.
https://reproducible-builds.org/
So I prefer to do the documentation changes in another pull request.
…--
bye,
pabs
http://bonedaddy.net/pabs3/
|
Does it cause different behaviors between different platforms? |
Yes, it causes the sed error to be hidden on GNU and shown on macOS.
I also don't think it is useful to workaround macOS xargs missing -r
since it would require running `git grep` twice instead of once and
the consequences of -r being missing are very much minor.
If macOS folks want the GNU/Linux behaviour they can install GNU xargs.
…--
bye,
pabs
http://bonedaddy.net/pabs3/
|
Maybe we could store the result in a bash variable? |
The results of `git grep -z` include NUL bytes and as far as I can tell
NUL bytes cannot be stored in bash variables, they are ignored:
$ foo="$(printf '%s\0' foo)" ; printf '%s' "$foo" | hexdump
bash: warning: command substitution: ignored null byte in input
00000000 66 6f 6f |foo|
00000003
|
@pabs3 |
I sent it to the git-sed branch on my git-extras fork, but I guess
github doesn't know how to associate that with the pull request.
|
Ah, I pushed to the wrong branch on my fork, fixed now.
…--
bye,
pabs
http://bonedaddy.net/pabs3/
|
bin/git-sed
Outdated
sep=/ | ||
;; | ||
esac | ||
r=$(xargs -0r false < /dev/null > /dev/null 2>&1 && echo r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use -r
instead of -0r
here, since we only want to test for -r
?
Prevents running sed when the search pattern does not match any files. This results in sed printing an unnessecary warning: $ git sed foo bar sed: no input files
Prevents sed from returning an error for arguments containing filenames: $ git sed src/foo.c src/bar.c sed: -e expression tj#1, char 13: unknown option to `s'
@pabs3 |
@pabs3 |
Discover a separator when the / character is used in arguments.
Prevent running sed when the search pattern does not match any files.
Allow the flags to be passed as a third argument.