rpmsafereduce: revert
[nethome.git] / bin / dashtopatch
1 #! /bin/sh
2 set -ex
3 compile=false
4 if [ "$1" = -c ];then
5   compile=true
6   shift
7 fi
8 if [ $# != 1 ] || ! echo "$1" | grep -q '-';then
9   echo >&2 "Syntax: $0 branch-list-delimited-by-dashes"
10   exit 1
11 fi
12 if [ -f origin ];then
13   origin="`cat origin`"
14 else
15   origin="gdb/master"
16 fi
17 base=$origin
18 gerrit=true
19 if git branch -D gerrit;then
20   git checkout $origin
21   git checkout -b gerrit
22 else
23   gerrit=false
24 fi
25 for elem in $(echo "$1"|tr '-' ' ');do
26   if [ "$base" = $origin ];then
27     next="$elem"
28   else
29     next="$base-$elem"
30   fi
31   git checkout "$next"
32   git merge --no-edit "$base"
33   if $compile;then
34     make
35   fi
36   if [ -e "$next".patch ];then
37     echo -e '/^--- /,$d\nw'|ed "$next".patch || :
38   fi
39   git diff "$base" "$next"|diffdecvs >>"$next".patch
40   if $gerrit;then
41     cp "$next".patch dashtopatch.patch
42     echo -e '/^--- /,$d\nw'|ed dashtopatch.patch
43     git checkout gerrit
44     patch -p1 <"$next".patch
45     git commit -a -F dashtopatch.patch
46     rm -f dashtopatch.patch
47   fi
48   base="$next"
49 done
50 git checkout "$next"
51 echo OK