summaryrefslogtreecommitdiff
path: root/scripts/update-patches-git
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2016-03-26 13:20:28 +0100
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-03-27 18:52:53 +0200
commitb088c254e6ecca80c557c5500aae47a7307c51b3 (patch)
treef3e1800bfd3fae229063dec6fb6571e7771676a4 /scripts/update-patches-git
parent89d74be7e8cd61409c96dab0cc58c5f79dfe8588 (diff)
reimplement package patching and update-patches logic
This works by using git as backend for all the dirty work. This means that patches are not just applied, but committed separately on top of the base sources (which are put into an initial commit). A final empty commit marks the end of the applied patch series, which allows to have multiple sets of patches to apply on top of each other. So a git history might look like this: - OpenADK patch marker: 0000 (this is the initial commit, containing the unpatched sources) - patch 1 of series 1 - patch 2 of series 1 - patch 3 of series 1 - OpenADK patch marker: 0001 - patch 1 of series 2 - patch 2 of series 2 - OpenADK patch marker: 0002 In addition to the separating empty commits, for every patch series metadata files are added (which are used for update-patches): __patchfiles__: A list of the patches' file names __patchdir__: The directory containing the applied patches Since patches might have to be unzipped first and in order to allow calling git-am just once for each patch series, the patches (along with above metadata files) are cached in dedicated directories: .git/patch_tmp/NNNN (where NNNN is the series number with leading zeroes [so shell globbing returns them in the right order]). In case update-patches is called later, update_patches.sh works it's way reverse through the git history, searching for commits named 'OpenADK patch marker: NNNN'. For each one it finds, it uses the metadata info to first remove all source patch files, then export the history in between using git-format-patch. To change patches or add new ones, the user has to use git-rebase in order to get things where they need to be for update_patches.sh to put stuff at the right place. For an example, here is how to change patch 3 of series 1 in the sample history above: - make desired code changes - commit them, ideally using --fixup option - call 'git rebase -i --autosquash <hash of OpenADK patch marker: 0000>' Using --fixup and --autosquash is convenient, since it automatically edits the rebase todo as intended. It's optional though, editing the todo manually will do just fine as well. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'scripts/update-patches-git')
-rw-r--r--scripts/update-patches-git31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/update-patches-git b/scripts/update-patches-git
new file mode 100644
index 000000000..8337fa847
--- /dev/null
+++ b/scripts/update-patches-git
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+#
+# Update patches using git-format-patch from a source tree prepared by
+# patch_git.sh.
+#
+# (c) 2016 Phil Sutter <phil@nwl.cc>
+
+wrkdist=$1
+wd=$(pwd)
+
+cd "$wrkdist"
+top=""
+top_series=""
+git log --grep="^OpenADK patch marker:" --oneline | while read hash subject; do
+ [ -n "$top" ] || {
+ top=$hash
+ top_series="${subject#OpenADK patch marker: }"
+ continue
+ }
+ bottom=$hash
+ bottom_series="${subject#OpenADK patch marker: }"
+
+ patchdir=$(<.git/patch_tmp/${top_series}/__patchdir__)
+ while read patchfile; do
+ rm ${patchdir}/$patchfile
+ done < .git/patch_tmp/${top_series}/__patchfiles__
+ git format-patch -N -o "$patchdir" ${bottom}..${top}
+
+ top=$bottom
+ top_series=$bottom_series
+done