@@ -35,6 +35,7 @@ Developer Notes
35
35
- [ GUI] ( #gui )
36
36
- [ Subtrees] ( #subtrees )
37
37
- [ Scripted diffs] ( #scripted-diffs )
38
+ - [ Suggestions and examples] ( #suggestions-and-examples )
38
39
- [ Release notes] ( #release-notes )
39
40
- [ RPC interface guidelines] ( #rpc-interface-guidelines )
40
41
@@ -889,7 +890,7 @@ Scripted diffs
889
890
For reformatting and refactoring commits where the changes can be easily automated using a bash script, we use
890
891
scripted-diff commits. The bash script is included in the commit message and our Travis CI job checks that
891
892
the result of the script is identical to the commit. This aids reviewers since they can verify that the script
892
- does exactly what it's supposed to do. It is also helpful for rebasing (since the same script can just be re-run
893
+ does exactly what it is supposed to do. It is also helpful for rebasing (since the same script can just be re-run
893
894
on the new master commit).
894
895
895
896
To create a scripted-diff:
@@ -910,7 +911,35 @@ For development, it might be more convenient to verify all scripted-diffs in a r
910
911
test/lint/commit-script-check.sh origin/master..HEAD
911
912
```
912
913
913
- Commit [ ` bb81e173 ` ] ( https://github.com/bitcoin/bitcoin/commit/bb81e173 ) is an example of a scripted-diff.
914
+ ### Suggestions and examples
915
+
916
+ If you need to replace in multiple files, prefer ` git ls-files ` to ` find ` or globbing, and ` git grep ` to ` grep ` , to
917
+ avoid changing files that are not under version control.
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 is good to keep the selection of files as specific as possible — for example, replace only in directories where
924
+ you expect replacements — because it reduces the risk that a rebase of your commit by re-running the script will
925
+ introduce accidental changes.
926
+
927
+ Some good examples of scripted-diff:
928
+
929
+ - [ scripted-diff: Rename InitInterfaces to NodeContext] ( https://github.com/bitcoin/bitcoin/commit/301bd41a2e6765b185bd55f4c541f9e27aeea29d )
930
+ uses an elegant script to replace occurences of multiple terms in all source files.
931
+
932
+ - [ scripted-diff: Remove g_connman, g_banman globals] ( https://github.com/bitcoin/bitcoin/commit/301bd41a2e6765b185bd55f4c541f9e27aeea29d )
933
+ replaces specific terms in a list of specific source files.
934
+
935
+ - [ scripted-diff: Replace fprintf with tfm::format] ( https://github.com/bitcoin/bitcoin/commit/fac03ec43a15ad547161e37e53ea82482cc508f9 )
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-"
942
+ ```
914
943
915
944
Release notes
916
945
-------------
0 commit comments