Skip to content

Commit 92db280

Browse files
committed
Merge #17411: doc: Add some better examples for scripted diff
adbe155 doc: Add some better examples for scripted diff (Wladimir J. van der Laan) Pull request description: 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. ACKs for top commit: hebasto: re-ACK adbe155 Tree-SHA512: 38f03716a122a1791c93abc052ea7572a3d2108b3d0d93dc95d3c4a7eb190c6b639d1cc66e4f74d378c4b11d6951dbd901d0973792f8f13cbeb9d9dcf4f8e037
2 parents 2065ef6 + adbe155 commit 92db280

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

doc/developer-notes.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Developer Notes
3535
- [GUI](#gui)
3636
- [Subtrees](#subtrees)
3737
- [Scripted diffs](#scripted-diffs)
38+
- [Suggestions and examples](#suggestions-and-examples)
3839
- [Release notes](#release-notes)
3940
- [RPC interface guidelines](#rpc-interface-guidelines)
4041

@@ -889,7 +890,7 @@ Scripted diffs
889890
For reformatting and refactoring commits where the changes can be easily automated using a bash script, we use
890891
scripted-diff commits. The bash script is included in the commit message and our Travis CI job checks that
891892
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
893894
on the new master commit).
894895

895896
To create a scripted-diff:
@@ -910,7 +911,35 @@ For development, it might be more convenient to verify all scripted-diffs in a r
910911
test/lint/commit-script-check.sh origin/master..HEAD
911912
```
912913

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+
```
914943

915944
Release notes
916945
-------------

0 commit comments

Comments
 (0)