summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-dev/2013-March/024025.html
blob: 5e73dac00e0cbf29b7100bdffa4e8a09f049cb07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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>