summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-dev/2013-March/024025.html
diff options
context:
space:
mode:
Diffstat (limited to 'zarb-ml/mageia-dev/2013-March/024025.html')
-rw-r--r--zarb-ml/mageia-dev/2013-March/024025.html187
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 &quot;$1&quot; ] || exit 1
+tarball=$(readlink -f $1)
+[ -d ../SPECS ] &amp;&amp; cd ../SPECS
+[ -d SPECS ] &amp;&amp; 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 &quot;$file&quot; ]; then
+ rm -vf $file
+ fi
+done
+workdir=$(echo */)
+workdir=${workdir%/}
+plain_magic=9999924
+for patch in $(sed &quot;s/^[Pp]atch:/Patch$plain_magic:/&quot; $spec | sed -n -r &quot;/^[Pp]atch.*:/s,^[Pp]atch([0-9]+):\s*(.+)$,\1=\2,p&quot; | sed &quot;s,%{name},${name},&quot;); do
+ eval patch$patch
+done
+ext=.orig
+[ $(find */ -name '*.orig' | wc -l) -eq 0 ] || ext=.orig2
+apply_magic=
+egrep -q '^%{?apply_patches}?' $spec &amp;&amp; apply_magic=1
+for patch in $(sed -r $([ -n &quot;$apply_magic&quot; ] &amp;&amp; echo &quot;-e s/^[Pp]atch([0-9]*):.*$/%patch\1/&quot;) -e &quot;s/^%patch[$ ]/%patch$plain_magic /&quot; $spec | sed -n -r &quot;/^%patch[0-9]+/s,^%patch([0-9]+)\s*(\-p[0-9])?.*$,\1:\2,p&quot;); do
+ pvar=${patch#*:}
+ [ -n &quot;$pvar&quot; ] || pvar=-p1
+ patch=${patch%:*}
+ eval patch=\$patch$patch
+ patch=&quot;$sourcedir/${patch##*/}&quot;
+ while echo &quot;$patch&quot; | grep -q '%'; do
+ variable=$(echo &quot;$patch&quot; | sed -r 's,^.*%\{?([a-zA-Z0-9_]+)\}?.*$,\1,')
+ value=$(awk &quot;/^%define[[:space:]]+$variable[[:space:]]+/ { print \$3 }&quot; $spec)
+ patch=$(echo &quot;$patch&quot; | sed -r &quot;s,%\{?$variable\}?,$value,&quot;)
+ done
+ if patch -d */ -F0 --dry-run -i $patch $pvar &gt;/dev/null; then
+ echo &quot;Up-to-date: $patch&quot;
+ patch -d */ -F0 --no-backup-if-mismatch -i $patch $pvar -s || exit 1
+ continue
+ fi
+ echo -n &quot;Rediffing $patch... &quot;
+ gawk '{ if ($1 == &quot;Index:&quot; || $1 == &quot;diff&quot; || $1 == &quot;---&quot;) exit; print; }' $patch &gt; pretext.txt
+ fastmode=1
+ if [ -n &quot;$allow_fastmode&quot; ]; then
+ if [ $(cat $patch | egrep '^(\+\+\+|---) ' | grep -v '^... /dev/null' | cut -f1 | sed -r 's, [^/]+/, ,' | sort | uniq -d | wc -l) -ne 0 ]; then
+ echo -n &quot;combined patch detected, disabling fast mode... &quot;
+ fastmode=
+ elif [ $(cat $patch | egrep '^(\+\+\+|---) ' | grep -c '^... /dev/null') -ne 0 ]; then
+ echo -n &quot;files added or removed, disabling fast mode... &quot;
+ fastmode=
+
+ elif ! patch -d $workdir -F2 -i $patch --dry-run $pvar &gt;/dev/null; then
+ echo -n &quot;patch does not apply, disabling fast mode... &quot;
+ fastmode=
+ fi
+ fi
+
+ pstatus=0
+ if [ -n &quot;$fastmode&quot; -a -n &quot;$allow_fastmode&quot; ]; 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 &gt; out.txt
+ pstatus=$?
+ fi
+ if [ $pstatus -ne 0 ]; then
+ echo
+ echo &quot;Patch $patch did not apply cleanly, dropping to shell.&quot;
+ echo &quot;Apply manually and then exit, or abort with \&quot;exit 1\&quot;.&quot;
+ cd newdir
+ cat ../out.txt
+ bash
+ ret=$?
+ [ $ret -ne 0 ] &amp;&amp; echo &quot;Aborted.&quot; &amp;&amp; exit $ret
+ cd ..
+ echo -n &quot;Assuming clean state, continuing... &quot;
+ fi
+ rm -f out.txt
+ if [ -n &quot;$fastmode&quot; -a -n &quot;$allow_fastmode&quot; ]; then
+ gendiff $workdir $ext &gt; $patch.new
+ else
+ diff -Nurpa -x '*~' -x '*.orig' -x '*.rej' -x '*.swp' $workdir newdir | sed -e &quot;s,^+++ newdir/,+++ $workdir/,&quot; -e &quot;s,^\(diff.* \)newdir/,\1$workdir/,&quot; &gt; $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 &gt; $patch
+ rm $patch.new
+ find . -name &quot;*${ext}&quot; -delete
+ echo &quot;OK&quot;
+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>