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 "$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>
|