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

Other arbitrary tags can also be put in the series:
#tag:for-upstream

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
0001-for-upstream.patch
#tag:base
0002-foo.patch
0003-bar.batch
# 25a3096f40bc8d841c8bf3ec24dd101f  - git-ptx-patches magic

If you would like the patch set that you are regenerating to begin with a
particular number use -n <startnum>

Signed-off-by: Jon Ringle <[email protected]>
---
 scripts/git-ptx-patches                |   70 +++++++++++++++++++++++++++++---
 scripts/lib/ptxd_make_world_patchin.sh |   26 ++++++++++++
 2 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/scripts/git-ptx-patches b/scripts/git-ptx-patches
index c5eb405..1c9c437 100755
--- a/scripts/git-ptx-patches
+++ b/scripts/git-ptx-patches
@@ -18,6 +18,8 @@ if [ ! -L .ptxdist/series ]; then
 fi
 
 remove_old=no
+tag=base
+startnum=1
 
 if grep -q "$PTX_PATCHES_HEADER" .ptxdist/series; then
        echo "Found series file generated by git-ptx-patches."
@@ -31,8 +33,53 @@ 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}"
+                       ;;
+               n)
+                       startnum="${OPTARG}"
+                       ;;
+       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:,,')
+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
+       if grep -q "#tag:${tag}" .ptxdist/series; then
+               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
+       echo "#tag:${tag}" >> .ptxdist/series.0
 fi
 
 case "$remove_old" in
@@ -53,7 +100,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 +116,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 --start-number ${startnum} -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 +130,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
-
diff --git a/scripts/lib/ptxd_make_world_patchin.sh 
b/scripts/lib/ptxd_make_world_patchin.sh
index bbb7490..b812f0f 100644
--- a/scripts/lib/ptxd_make_world_patchin.sh
+++ b/scripts/lib/ptxd_make_world_patchin.sh
@@ -112,6 +112,16 @@ ptxd_make_world_patchin_apply_git_compat()
        esac
 
        case "${patch}" in
+           "#tag:"*)
+               local tag="${patch##\#tag:}"
+               if [ -f ${pkg_patchin_dir}/.ptxdist/git-patches/series ]; then
+                   mv ${pkg_patchin_dir}/.ptxdist/git-patches/series{,.${tag}} 
&&
+                   touch ${pkg_patchin_dir}/.ptxdist/git-patches/series
+               else
+                   touch ${pkg_patchin_dir}/.ptxdist/git-patches/series.${tag}
+               fi
+               continue
+               ;;
            ""|"#"*) continue ;;        # skip empty lines and comments
            *.gz)  cat="zcat" ;;
            *.bz2) cat="bzcat" ;;
@@ -141,6 +151,22 @@ ptxd_make_world_patchin_apply_git()
     #
     ptxd_make_world_patchin_apply_git_compat || return
 
+    grep "\#tag:" "${pkg_patchin_dir}/.ptxdist/series" | while read tagline; do
+       local tag="${tagline##\#tag:}"
+       if [ -f "${pkg_patchin_dir}/.ptxdist/git-patches/series.${tag}" ]; then
+           mv ${pkg_patchin_dir}/.ptxdist/git-patches/series{,.1} || return
+           mv ${pkg_patchin_dir}/.ptxdist/git-patches/series{.${tag},} || 
return
+
+           git quiltimport \
+               --patches "${pkg_patchin_dir}/.ptxdist/git-patches" \
+               --author "unknown author <[email protected]>"
+           echo "tagging -> ${tag}"
+           git tag -f ${tag}
+           mv ${pkg_patchin_dir}/.ptxdist/git-patches/series{,.${tag}} || 
return
+           mv ${pkg_patchin_dir}/.ptxdist/git-patches/series{.1,} || return
+       fi
+    done
+
     git quiltimport \
        --patches "${pkg_patchin_dir}/.ptxdist/git-patches" \
        --author "unknown author <[email protected]>"
-- 
1.7.0.4


-- 
ptxdist mailing list
[email protected]

Reply via email to