aboutsummaryrefslogtreecommitdiffstats
path: root/tools/backport-rev
blob: 31dd38290c8b086afb1f2210c2a1c95d43c3001b (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
#!/bin/bash
#
# Copyrev - copies a revision from the Wireshark trunk to the current
# directory.
#
# Usage: backport-rev <svn revision>
#
# $Id$
#
# Copyright 2013 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

if [ -z "$VISUAL" ] ; then
    VISUAL=$EDITOR
fi

#Check if pbcopy (or similar) is available...
if [ `builtin type -p pbcopy` ] ; then
    PBCOPY="pbcopy"
fi

if [ `builtin type -p xsel` ]  ; then
    PBCOPY="xsel --clipboard --input"
fi

if [ `builtin type -p putclip` ]  ; then
    PBCOPY="putclip"
fi

if [ -z "$PBCOPY" ] ; then
    echo "Can't find an clipboard copy. Check if pbcopy, xsel or putclip is installed in your system"
    exit 1
fi
function exit_err
{
    if [ -n "$*" ] ; then
        echo "$*"
    fi
    echo -n $patchfile | $PBCOPY
    echo "Patch saved to $patchfile and copied to pasteboard"
    if [ -n "$VISUAL" ] ; then
        "$VISUAL" $patchfile $logfile
    else
        echo "Can't find an editor. You'll have to open $patchfile and $logfile yourself."
    fi
    exit 1
}

subdir=""
trunk="trunk"

while getopts "at:" opt ; do
    case $opt in
        a)
            subdir="/asn1"
            ;;
        t)
            trunk="trunk-$OPTARG"
            ;;
        \?)
            echo "Unknown option -$OPTARG"
            ;;
    esac
done
shift $((OPTIND-1))

svninfo="`svn info | grep ^URL | cut -f2 -d' '`"
if [ -z "$svninfo" ] ; then
    exit_err "Can't find repository information. Are you running this from a Wireshark SVN directory?"
fi

svnurl=`dirname $svninfo`
svnurl="$svnurl/$trunk"
#svnurl="$HOME/Development/wireshark"

rev="$1"

patchfile="/tmp/backport-rev-$rev.patch"
logfile="/tmp/backport-rev-$rev.log"
mergefile="/tmp/backport-rev-$rev.merge"
oldrev=$(( $rev - 1 ))
echo "Working on r$rev ($oldrev)"

echo -n "Attempting 'svn merge' dry run. "
if [ -n "$subdir" ] ; then
    cd .$subdir
fi

svn diff --diff-cmd /usr/bin/diff -x "-w -b -U 5" -c $rev $svnurl$subdir \
    > $patchfile || exit_err "Error"

svn log -v -r $rev $svnurl | sed -e 's/^..*/  &/' > $logfile || exit 1

merge_err=0
# Some versions of svn always return 0. Check the return value then look
# for a "Summary of conflicts" line.
svn merge --dry-run -c$rev $svnurl > $mergefile 2>&1
merge_err=$?
grep '^Summary' $mergefile > /dev/null 2>&1 && merge_err=1

if [ $merge_err -ne 0 ] ; then
    echo "Error. Dry run output follows."
    echo ""
    cat $mergefile
    rm $mergefile
    echo ""
    dry_run_cmd="patch --batch --ignore-whitespace --strip=0 --dry-run"
    echo "Merge failed. Trying 'patch' dry run:"
    echo "    $dry_run_cmd < $patchfile"
    echo ""
    $dry_run_cmd < $patchfile
    echo ""
    exit_err "Giving up. You'll have to merge the patch yourself."
fi

rm $mergefile

echo "OK"
echo "Attempting 'svn merge' live run:"
svn merge -c$rev $svnurl

if [ -n "$subdir" ] ; then
    cd ..
fi
echo Done with r$rev

echo "Copy over revisions from the trunk:"
echo ""
uniq < $logfile

rm -v $patchfile $logfile

#
# Editor modelines  -  http://www.wireshark.org/tools/modelines.html
#
# Local variables:
# c-basic-offset: 4
# tab-width: 8
# indent-tabs-mode: nil
# End:
#
# vi: set shiftwidth=4 tabstop=8 expandtab:
# :indentSize=4:tabSize=8:noTabs=true:
#