~registry/cloud-utils/trunk

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
#!/bin/sh

fail() { [ $# -eq 0 ] || echo "$@" 1>&2; exit 1; }

Usage() {
   cat <<EOF
Usage: debian/${0##*/} trunk-branch [ upstream-ver ]

  revno is the revision in *this* branch that correlates
  with the last upstream release.
EOF
}

[ $# -lt 1 ] && { Usage; exit 1; }
tb=$1
upstream_ver=$2
pname="sync-to-trunk.patch"

if [ -z "$2" ]; then
   upstream_ver=$(head -n 1 debian/changelog |
      sed -e 's,[^(]*(\([^)]*\)).*,\1,' -e 's,-.*,,')
   [ -n "$upstream_ver" ] || fail "failed to get upstream_ver"
   upstream_ver="tag:${upstream_ver}"
fi

if [ "${upstream_ver#tag:}" != "${upstream_ver}" ]; then
   out=$( cd "${tb}" && bzr log -r "${upstream_ver}" --line) &&
      tag_revno=${out%%:*} ||
      fail "failed to get revision number for ${upstream_ver} from ${tb}"
else
   tag_revno=${upstream_ver}
fi

tag_plus1=$(($tag_revno+1))
end=$( cd "${tb}" && bzr revno)

tmpd=$(mktemp -d)
trap "rm -Rf $tmpd" EXIT


( cd "${tb}" && bzr log "-r$tag_plus1..$end" &&
   bzr diff -p1 -r $tag_revno..$end ) > "${tmpd}/raw" 
ret=$?
[ $ret -eq 0 -o $ret -eq 1 ] || fail "getting diff failed"

echo "Patch created with '${0} ${*}'" > "${tmpd}/${pname}"
filterdiff --exclude "*/debian/*" < "${tmpd}/raw" >> "${tmpd}/${pname}" ||
   fail "failed to filterdiff"

if quilt applied; then
   quilt pop -a ||
      fail "failed to pop patches in quilt queue"
fi

if quilt series | grep ^${pname} ; then
   quilt delete -r "${pname}" ||
      fail "failed patch ${pname}"
fi

quilt import "${tmpd}/${pname}" ||
   fail "failed to import"

quilt push "${pname}" || fail "failed to push to ${pname}"

for f in $(quilt files); do
   if [ -e "$f" ]; then
      bzr add "$f" ||
         fail "failed to add $f"
   fi
done


echo "refreshed ${pname}"
echo "you may need to quilt push -a now if you had other changes"