cookutils annotate doc/general-questions.md @ rev 1150

Show recent broken packages first
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 19 15:32:45 2022 +0000 (2022-02-19)
parents 6867a12b73aa
children
rev   line source
al@1137 1 # General questions
al@1137 2
al@1137 3 ## `sed` or patches?
al@1137 4
al@1137 5 Sometimes I come across cases where `sed` is used to change some values in the
paul@1138 6 source code or to add / remove / change some parts of the source code.
al@1137 7 It may look like a good idea for a one-time job, but you will encounter
al@1137 8 problems in the future when you upgrade the package.
al@1137 9
paul@1138 10 `sed` works quietly and it is impossible to understand whether it found what
paul@1138 11 was needed to be found, whether it replaced what we wanted? Maybe this change
paul@1138 12 is already in the new sources and we no longer need `sed` command?
al@1137 13
al@1137 14 If we consider only the updated sources, sometimes it is impossible
al@1137 15 to understand the essence of the `sed` changes. And then you have to download
al@1137 16 and analyze the old sources.
al@1137 17
al@1137 18 Feel free to use patches. The `patch` is smart enough to find the necessary
paul@1138 19 lines in the new sources and also it will signal to you if your changes have
paul@1138 20 already been made in the sources or if the sources has changed so much that
al@1137 21 your intervention is required.
al@1137 22
al@1137 23 Go from `sed` to `patch` is easy. You must use the `-o.backup` option (value
al@1137 24 after the `-o` you can change). For example, you used this code:
al@1137 25
al@1137 26 ```bash
al@1137 27 sed -i '/debug/ s|true|false|' config
al@1137 28 ```
al@1137 29
al@1137 30 Now apply the changes saving the original file:
al@1137 31
al@1137 32 ```bash
al@1137 33 sed -i.orig '/debug/ s|true|false|' config
al@1137 34 ```
al@1137 35
al@1137 36 Create a patch using the original and modified files:
al@1137 37
al@1137 38 ```bash
al@1137 39 diff ./config.orig ./config > ../../stuff/patches/config.patch
al@1137 40 ```
al@1137 41
al@1137 42 Now you can use the created patch and remove the `sed` command.
al@1137 43