summaryrefslogtreecommitdiffstats
path: root/scripts/git-ptx-patches
diff options
context:
space:
mode:
authorJon Ringle <jon@ringle.org>2011-07-04 09:22:04 -0400
committerMichael Olbrich <m.olbrich@pengutronix.de>2011-07-15 15:36:06 +0200
commit957c6c663cdd46ef8341b84893b32d1bb1a04edf (patch)
treefbab67fa4f7865d4d0524e05b56c79a18be01bfd /scripts/git-ptx-patches
parent6b42a4e51a796de571697418afe4ec54e84a0df7 (diff)
downloadptxdist-957c6c663cdd46ef8341b84893b32d1bb1a04edf.tar.gz
ptxdist-957c6c663cdd46ef8341b84893b32d1bb1a04edf.tar.xz
git-ptx-patches: Allow patches before base tag
The patch series I have for the Linux kernel includes incremental patches from upstream like patch-2.6.33.1.bz2 patch-2.6.33.1-2.bz2 followed by a patch series for my board. But ptxdist messes this up when applying the patch series with git. This patch allows one to mark the base tag in the series with: #tag:base --start-number 1 Other arbitrary tags can also be put in the series: #tag:for-upstream --start-number 5 When using 'git ptx-patches' to regenerate the series, only the patches between "#tag:base" and the next "#tag:*" or EOF in the series are regenerated. All others in the series are left untouched. To use a different tag than the default tag base, use -t tagname. e.g.: # generated by git-ptx-patches patch-2.6.33.1.bz2 patch-2.6.33.1-2.bz2 patch-2.6.33.2-3.bz2 #tag:for-upstream --start-number 1 0001-for-upstream-1.patch 0002-for-upstream-2.patch 0003-for-upstream-3.patch #tag:base --start-number 4 0004-foo.patch 0005-bar.batch # 25a3096f40bc8d841c8bf3ec24dd101f - git-ptx-patches magic Any options included on a #tag:* line are passed to git format-patch when generating the patches for that section. Signed-off-by: Jon Ringle <jon@ringle.org> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts/git-ptx-patches')
-rwxr-xr-xscripts/git-ptx-patches73
1 files changed, 67 insertions, 6 deletions
diff --git a/scripts/git-ptx-patches b/scripts/git-ptx-patches
index c5eb405f4..396797c6e 100755
--- a/scripts/git-ptx-patches
+++ b/scripts/git-ptx-patches
@@ -18,6 +18,7 @@ if [ ! -L .ptxdist/series ]; then
fi
remove_old=no
+tag=base
if grep -q "$PTX_PATCHES_HEADER" .ptxdist/series; then
echo "Found series file generated by git-ptx-patches."
@@ -31,8 +32,57 @@ if grep -q "$PTX_PATCHES_HEADER" .ptxdist/series; then
fi
fi
+while getopts "ft:n:" opt; do
+ case "${opt}" in
+ f)
+ remove_old="force"
+ ;;
+ t)
+ tag="${OPTARG}"
+ range="${tag}"
+ ;;
+ esac
+done
+shift $((${OPTIND} - 1))
+
if [ "x$1" = "x--force-remove" ]; then
remove_old="force"
+ shift
+fi
+
+tag2=$(grep "#tag:" .ptxdist/series | awk "/#tag:${tag}/{getline;print \$0}" | sed 's,#tag:,,' | cut -d' ' -f1)
+if [ "${tag}" != "${tag2}" ]; then
+ range="${tag}..${tag2}"
+else
+ range="${tag}"
+ tag2=""
+fi
+
+echo "$PTX_PATCHES_HEADER" > .ptxdist/series.0
+:> .ptxdist/series.1
+if grep -q "#tag:" .ptxdist/series; then
+ tagline=$(grep "#tag:${tag}" .ptxdist/series)
+ t=$(echo "${tagline}"|cut -d' ' -f1)
+ if [ "#tag:${tag}" == "${t}" ]; then
+ tagopt=$(echo "${tagline}"|cut -d' ' -f2-)
+ sed -e "/$PTX_PATCHES_HEADER/d" -n -e "0,/#tag:${tag}/p" .ptxdist/series >> .ptxdist/series.0
+ # Remove patches before #tag:${tag} so they don't get rm'd with remove_old=yes
+ sed -i --follow-symlinks "0,/#tag:${tag}/d" .ptxdist/series
+ if [ -n "${tag2}" ]; then
+ sed -n -e "/#tag:${tag2}/,/git-ptx-patches magic/p" .ptxdist/series > .ptxdist/series.1
+ sed -i "/git-ptx-patches magic/d" .ptxdist/series.1
+ sed -i --follow-symlinks "/#tag:${tag2}/,/git-ptx-patches magic/d" .ptxdist/series
+ fi
+ else
+ echo "series contains #tag:* lines, but could not find #tag:${tag} line in series. Aborting."
+ exit 1
+ fi
+else
+ if [ "${tag}" != "base" ]; then
+ echo "When using series with no #tag:* lines, you must use base tag."
+ exit 1
+ fi
+ echo "#tag:${tag} --start-number 1" >> .ptxdist/series.0
fi
case "$remove_old" in
@@ -53,7 +103,13 @@ case "$remove_old" in
".ptxdist/patches/") continue ;;
".ptxdist/patches/series") continue ;;
".ptxdist/patches/autogen.sh") continue ;;
- *) rm -rf "$file" ;;
+ *)
+ if grep -q "${file##\.ptxdist/patches/}" .ptxdist/series.{0,1}; then
+ echo "Keep base patch ${file}"
+ else
+ rm -rf "$file"
+ fi
+ ;;
esac
done
;;
@@ -63,8 +119,10 @@ if git format-patch -h 2>&1 | grep -q signature; then
GIT_EXTRA_ARGS="--no-signature"
fi
-echo "$PTX_PATCHES_HEADER" > .ptxdist/series
-git format-patch -N $GIT_EXTRA_ARGS -o .ptxdist/patches/ base | sed -e 's,^.ptxdist/patches/,,' >> .ptxdist/series
+cat .ptxdist/series.0 > .ptxdist/series
+git format-patch -N $GIT_EXTRA_ARGS ${tagopt} -o .ptxdist/patches/ ${range} | sed -e 's,^.ptxdist/patches/,,' > .ptxdist/series.auto
+cat .ptxdist/series.auto >> .ptxdist/series
+cat .ptxdist/series.1 >> .ptxdist/series
cat .ptxdist/series | _md5sum >> .ptxdist/series
# The first line of the patch is 'From <some-git-hash> ...'
@@ -75,14 +133,17 @@ while read patch para; do
"series"|"autogen.sh") continue ;;
*) ;;
esac
- if grep -q "$patch" .ptxdist/series; then
+ if grep -q "$patch" .ptxdist/series.auto; then
p=".ptxdist/patches/$patch"
lines=$(cat "$p" | wc -l)
lines=$[lines-1]
tail -n$lines "$p" > ".$patch.ptx-patches"
mv ".$patch.ptx-patches" "$p"
else
- echo "Old patch \"$patch\"!"
+ if grep -q "$patch" .ptxdist/series.{0,1}; then
+ echo "Base patch \"$patch\"!"
+ else
+ echo "Old patch \"$patch\"!"
+ fi
fi
done
-