2
# Generate a patch for each of the ia64 files in the linux-2.6-xen-sparse tree
4
# Path to mercurial tree of upstream Linux
5
# WARNING: This will do an 'hg up -C' on the upstream Linux tree, you
6
# will lose data if there's anything there you care about.
7
: ${LINUXPATH:=/tmp/linux-2.6}
8
# Tag of current base upstream image for Xen files
9
: ${OLDTAG:=v$(awk '/^LINUX_VER/{print $NF}' buildconfigs/mk.linux-2.6-xen)}
10
# Tag of new upstream base to go to
11
: ${NEWTAG:=v$(wget -O- -o/dev/null http://kernel.org/kdist/finger_banner \
12
| awk '/latest stable/{print $NF}')}
13
# Restrict merge to specific arch (set to . for all)
16
SPARSEDIR=linux-2.6-xen-sparse
19
if [ ! -d $SPARSEDIR ]; then
20
echo "Can't find $SPARSEDIR directory."
24
# Check for modified files in the sparse tree before starting
25
if hg st $SPARSEDIR | head | grep .; then
27
echo "$SPARSEDIR contains modifications, please clean it up first"
31
# We want the linux upstream tree to be at the OLDTAG to get the OLDTAG-Xen diff.
32
# Save current revision to restore when done
33
cd $LINUXPATH || exit 1
34
OLDCSET=$(hg parents | awk '/^changeset:/{print($2)}' | cut -f 1 -d :)
35
for t in $OLDTAG $NEWTAG; do
36
[[ $t == *.* ]] || continue
37
if ! hg tags | cut -f1 -d' ' | grep -Fx $t; then
38
echo "Tag $t not found, ketching up"
39
if [[ $t == *-* ]]; then
40
# rc/pre/git versions start at the previous stable release
41
micro=${t%%-*}; micro=${micro##*.}
42
stable=${t%%-*}; stable=${stable%.*}.$((micro-1))
45
hg up -C ${t%.*} || exit 1
47
ketchup ${t#v} || exit 1
53
hg up -C $OLDTAG || exit 1
56
for i in $(hg manifest | awk '{print($3)}' | grep $SPARSEDIR | grep "$ARCH"); do
59
FILENAME=$(basename $i)
61
DIFFPATH=$(echo $i | sed -e "s,^$SPARSEDIR,$LINUXPATH,")
63
if [ ! -d $DIRNAME ]; then
64
echo "Hmm, something bad happened parsing directory name: $i"
68
if [ ! -e $DIFFPATH ]; then
77
ORIGPATH=$(echo $i | sed -e "s/^$SPARSEDIR/./")
78
APATH=$(echo $i | sed -e "s/^$SPARSEDIR/a/")
79
BPATH=$(echo $i | sed -e "s/^$SPARSEDIR/b/")
81
hg diff -r $OLDTAG -r $NEWTAG $ORIGPATH | \
82
sed -e "s,^--- $APATH,--- $FILENAME," \
83
-e "s,^+++ $BPATH,+++ $FILENAME," \
84
> $XENDIR/$FILENAME-$OLDTAG-$NEWTAG.diff
87
# Do we have a diff file? Did anything change?
88
if [ ! -s $FILENAME-$OLDTAG-$NEWTAG.diff ]; then
89
echo "SUCCESS (Upstream unchanged)"
93
if ! patch -f -i $FILENAME-$OLDTAG-$NEWTAG.diff > /dev/null 2>&1; then
94
# It failed, how badly?
95
if [ ! -e ${FILENAME}.rej ]; then
96
echo "ERROR, Hmm, no .rej file, but diff failed, fix manually"
99
TONEWREJ=$(wc -l ${FILENAME}.rej | \
101
hg st $FILENAME | grep -q . && hg revert $FILENAME
102
rm -f ${FILENAME}.rej ${FILENAME}.orig
103
diff -uN $DIFFPATH $FILENAME | \
104
sed -e "s,^--- $DIFFPATH,--- $FILENAME," \
105
> $FILENAME-$OLDTAG-Xen.diff
107
if [ ! -e $FILENAME-$OLDTAG-Xen.diff ]; then
108
echo "ERROR, failed to create patch file"
112
if ! patch -R -i $FILENAME-$OLDTAG-Xen.diff > /dev/null 2>&1; then
113
echo "ERROR, reverting Xen changes failed"
118
if ! patch -f -i $FILENAME-$OLDTAG-$NEWTAG.diff > /dev/null 2>&1; then
119
echo "ERROR, new upstream patch failed on reverted file"
124
if ! patch -f -i $FILENAME-$OLDTAG-Xen.diff > /dev/null 2>&1; then
125
if [ ! -e ${FILENAME}.rej ]; then
126
echo "ERROR, Hmm, no .rej file, but diff failed, fix manually"
129
TOXENREJ=$(wc -l ${FILENAME}.rej | \
132
if [ $TOXENREJ -gt $TONEWREJ ]; then
134
rm -f ${FILENAME}.rej ${FILENAME}.orig
135
patch -f -i $FILENAME-$OLDTAG-$NEWTAG.diff > /dev/null 2>&1
136
echo "MANUAL MERGE REQUIRED (Upstream reject)"
138
echo "MANUAL MERGE REQUIRED (Xen reject)"
142
rm -f ${FILENAME}.rej ${FILENAME}.orig
143
echo "SUCCESS (Re-applied Xen patch)"
146
rm -f ${FILENAME}.rej ${FILENAME}.orig
147
echo "SUCCESS (Upstream applied)"
150
find $SPARSEDIR -name \*.diff -empty | xargs -r rm -f