The current example isn't too great, for example it uses find instead of git ls-files. Add a subsection with suggestions and examples.
Feel free to propose some other great examples to add.
The current example isn't too great, for example it uses find instead of git ls-files. Add a subsection with suggestions and examples.
Feel free to propose some other great examples to add.
936 | +does a global replacement but excludes certain directories. 937 | + 938 | +To find all previous uses of scripted diffs in the repository, do: 939 | + 940 | +``` 941 | +git log --grep="-BEGIN VERIFY SCRIPT-"
Great tip!
Concept ACK.
You have to update the TOC.
Concept ACK -- git ls-files and git grep are both great! :)
BTW: what is the best way to do a re-apply of a conflicted scripted diff when rebasing? I did the following to rebase #17410 and it seems it could be more efficient, and if so, we'd want to add it to the documentation:
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Rename `db` log category to `walletdb` (like `coindb`)
Applying: scripted-diff: Change `BCLog::DB` to `BCLog::WALLETDB` Using index info to reconstruct a base tree...
M src/wallet/db.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/wallet/db.cpp
CONFLICT (content): Merge conflict in src/wallet/db.cpp
error: Failed to merge in the changes.
Patch failed at 0002 scripted-diff: Change `BCLog::DB` to `BCLog::WALLETDB`
Use 'git am --show-current-patch' to see the failed patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
do hard reset, to get rid of git's attempt at re-applying, and conflict markers
$ git reset --hard
manually paste script steps
$ git grep -l "BCLog::DB" src | xargs sed -i "s/BCLog::DB/BCLog::WA
LLETDB/g"
$ sed -i "s/DB =/WALLETDB =/g" src/logging.h
$ git status
M src/logging.cpp
M src/logging.h
M src/wallet/db.cpp
M src/wallet/walletdb.cpp
mandually git add changed objects, and roll rebase forward
$ git add src/logging.cpp src/logging.h src/wallet/db.cpp src/wallet/walletdb.cpp
$ git rebase --continue
I have a one-line script-get bash function would let you replace the manual paste step:
bash -c "$(script-get HEAD)"
Probably more of this could be scripted in general, though
Thanks!
Indeed, my idea was that this is pretty much an alternative merge strategy: ignore git's own attempt (which could cause conflicts or miss new occurences) in favor of re-running the script. It won't have any merge conflicts, by definition, though obviously the result still has to be reviewed.
909 | @@ -910,7 +910,35 @@ For development, it might be more convenient to verify all scripted-diffs in a r 910 | test/lint/commit-script-check.sh origin/master..HEAD 911 | ``` 912 | 913 | -Commit [`bb81e173`](https://github.com/bitcoin/bitcoin/commit/bb81e173) is an example of a scripted-diff. 914 | +### Suggestions and examples
yes, will update the TOC
918 | + 919 | +For efficient replacement scripts, reduce the selection to the files that potentially need to be modified, so for 920 | +example, instead of a blanket `git ls-files src | xargs sed -i s/apple/orange/`, use 921 | +`git grep -l apple src | xargs sed -i s/apple/orange/`. 922 | + 923 | +Also, it's good to keep the selection of files as specific as possible — for example, replace only in directories where
nit: contractions, "it's", should be avoided in well-styled docs ;)
ok
ACK d8ae24fae2fce7f39a9eb7fa7c9b21fac79e82ac, I have reviewed the code and it looks OK, I agree it can be merged.
The current example isn't too great, for example it uses `find` instead
of `git ls-files`. Add a subsection with suggestions and examples.
Updated toc, replaced occurrences of "it's" with "it is".
re-ACK adbe15504713ddba6e9c024c59d977675d49e350