diff options
Diffstat (limited to 'zarb-ml/mageia-dev/2013-March/024025.html')
-rw-r--r-- | zarb-ml/mageia-dev/2013-March/024025.html | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/zarb-ml/mageia-dev/2013-March/024025.html b/zarb-ml/mageia-dev/2013-March/024025.html new file mode 100644 index 000000000..5e73dac00 --- /dev/null +++ b/zarb-ml/mageia-dev/2013-March/024025.html @@ -0,0 +1,187 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<HTML> + <HEAD> + <TITLE> [Mageia-dev] Script for rediffing patches + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20Script%20for%20rediffing%20patches&In-Reply-To=%3C5158A7DD.3030804%40mageia.org%3E"> + <META NAME="robots" CONTENT="index,nofollow"> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="024020.html"> + + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[Mageia-dev] Script for rediffing patches</H1> + <B>Anssi Hannula</B> + <A HREF="mailto:mageia-dev%40mageia.org?Subject=Re%3A%20%5BMageia-dev%5D%20Script%20for%20rediffing%20patches&In-Reply-To=%3C5158A7DD.3030804%40mageia.org%3E" + TITLE="[Mageia-dev] Script for rediffing patches">anssi at mageia.org + </A><BR> + <I>Sun Mar 31 23:17:17 CEST 2013</I> + <P><UL> + <LI>Previous message: <A HREF="024020.html">[Mageia-dev] pandoc? +</A></li> + + <LI> <B>Messages sorted by:</B> + <a href="date.html#24025">[ date ]</a> + <a href="thread.html#24025">[ thread ]</a> + <a href="subject.html#24025">[ subject ]</a> + <a href="author.html#24025">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>Hi all, + +Colin's question reminded me of another hacky script I use for rediffing +patches. I had planned to clean it up but clearly that is never going to +happen, so I may as well provide it here in case someone else finds it +useful or even wants to make a clean version... + +It has accumulated hacks on top of hacks over the years to handle lots +of special cases (%apply_patches, Patch: foo.patch, concatenated +patches, tarballs containing .orig files etc.) with little regard to +readability, but it has worked well for me... + +Usage, in pkg checkout: +$ rediffpatches SOURCES/foobar-1.2.tar.bz2 + +It rediffs all patches automatically, and in case of nonmergeable +conflict it will drop you to shell to apply the patch manually, and will +continue after you exit. + +Of course you still *have to* manually review *all* the changes made as +always, but it still makes the work progress faster (especially in pkgs +with lots of patches). + +-- +Anssi Hannula +-------------- next part -------------- +#!/bin/bash +allow_fastmode=1 +[ -f "$1" ] || exit 1 +tarball=$(readlink -f $1) +[ -d ../SPECS ] && cd ../SPECS +[ -d SPECS ] && cd SPECS +name=$(dirname $PWD | sed s,.*/,,) +spec=$(readlink -f $name.spec) +[ -e $spec ] || exit 1 +sourcedir=$(readlink -f $PWD/../SOURCES) +#source=$sourcedir/$(awk '/^Source.*:/ { print $2 }' $spec | head -n1) +source=$tarball +rm -rf .rediff +mkdir .rediff +cd .rediff +tar -xf $source +for file in ./*; do + if [ -L "$file" ]; then + rm -vf $file + fi +done +workdir=$(echo */) +workdir=${workdir%/} +plain_magic=9999924 +for patch in $(sed "s/^[Pp]atch:/Patch$plain_magic:/" $spec | sed -n -r "/^[Pp]atch.*:/s,^[Pp]atch([0-9]+):\s*(.+)$,\1=\2,p" | sed "s,%{name},${name},"); do + eval patch$patch +done +ext=.orig +[ $(find */ -name '*.orig' | wc -l) -eq 0 ] || ext=.orig2 +apply_magic= +egrep -q '^%{?apply_patches}?' $spec && apply_magic=1 +for patch in $(sed -r $([ -n "$apply_magic" ] && echo "-e s/^[Pp]atch([0-9]*):.*$/%patch\1/") -e "s/^%patch[$ ]/%patch$plain_magic /" $spec | sed -n -r "/^%patch[0-9]+/s,^%patch([0-9]+)\s*(\-p[0-9])?.*$,\1:\2,p"); do + pvar=${patch#*:} + [ -n "$pvar" ] || pvar=-p1 + patch=${patch%:*} + eval patch=\$patch$patch + patch="$sourcedir/${patch##*/}" + while echo "$patch" | grep -q '%'; do + variable=$(echo "$patch" | sed -r 's,^.*%\{?([a-zA-Z0-9_]+)\}?.*$,\1,') + value=$(awk "/^%define[[:space:]]+$variable[[:space:]]+/ { print \$3 }" $spec) + patch=$(echo "$patch" | sed -r "s,%\{?$variable\}?,$value,") + done + if patch -d */ -F0 --dry-run -i $patch $pvar >/dev/null; then + echo "Up-to-date: $patch" + patch -d */ -F0 --no-backup-if-mismatch -i $patch $pvar -s || exit 1 + continue + fi + echo -n "Rediffing $patch... " + gawk '{ if ($1 == "Index:" || $1 == "diff" || $1 == "---") exit; print; }' $patch > pretext.txt + fastmode=1 + if [ -n "$allow_fastmode" ]; then + if [ $(cat $patch | egrep '^(\+\+\+|---) ' | grep -v '^... /dev/null' | cut -f1 | sed -r 's, [^/]+/, ,' | sort | uniq -d | wc -l) -ne 0 ]; then + echo -n "combined patch detected, disabling fast mode... " + fastmode= + elif [ $(cat $patch | egrep '^(\+\+\+|---) ' | grep -c '^... /dev/null') -ne 0 ]; then + echo -n "files added or removed, disabling fast mode... " + fastmode= + + elif ! patch -d $workdir -F2 -i $patch --dry-run $pvar >/dev/null; then + echo -n "patch does not apply, disabling fast mode... " + fastmode= + fi + fi + + pstatus=0 + if [ -n "$fastmode" -a -n "$allow_fastmode" ]; then + patch -d */ -F2 -V simple -b -z $ext -i $patch $pvar -s || exit 1 + else + cp -a $workdir newdir + patch -d newdir -F2 --merge=diff3 -V simple -z $ext -i $patch $pvar > out.txt + pstatus=$? + fi + if [ $pstatus -ne 0 ]; then + echo + echo "Patch $patch did not apply cleanly, dropping to shell." + echo "Apply manually and then exit, or abort with \"exit 1\"." + cd newdir + cat ../out.txt + bash + ret=$? + [ $ret -ne 0 ] && echo "Aborted." && exit $ret + cd .. + echo -n "Assuming clean state, continuing... " + fi + rm -f out.txt + if [ -n "$fastmode" -a -n "$allow_fastmode" ]; then + gendiff $workdir $ext > $patch.new + else + diff -Nurpa -x '*~' -x '*.orig' -x '*.rej' -x '*.swp' $workdir newdir | sed -e "s,^+++ newdir/,+++ $workdir/," -e "s,^\(diff.* \)newdir/,\1$workdir/," > $patch.new + rm -rf newdir + patch -d $workdir -F0 -i $patch.new -p1 -s || exit 1 + fi + backupname=$patch.origsvn + if [ -e $backupname ]; then + i=1 + while [ -e $backupname.$i ]; do + i=$((i+1)) + done + backupname=$backupname.$i + fi + mv $patch $backupname + cat pretext.txt $patch.new > $patch + rm $patch.new + find . -name "*${ext}" -delete + echo "OK" +done +cd .. +rm -rf .rediff +</PRE> + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="024020.html">[Mageia-dev] pandoc? +</A></li> + + <LI> <B>Messages sorted by:</B> + <a href="date.html#24025">[ date ]</a> + <a href="thread.html#24025">[ thread ]</a> + <a href="subject.html#24025">[ subject ]</a> + <a href="author.html#24025">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="https://www.mageia.org/mailman/listinfo/mageia-dev">More information about the Mageia-dev +mailing list</a><br> +</body></html> |