summaryrefslogtreecommitdiff
path: root/backflip-from-tsv
blob: 90e2cf90d5b3c7dc58e12b9816ff57fbdc0ed5b8 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash

# This script is a helper to process backports in batch from the main
# spreadsheet.

# Typical use: export the spreadsheet page in TSV (tab-separated
# values), then call this script with the TSV as std input.
# The script prints the list of backflip commands needed to perform
# all the backports described in the TSV file.
#
# For simple backports (with no dependency), it's as easy as calling
# backflip with the revision number as parameter.

# When several commits have to be stacked, the script parses the
# 'Stack with' column and build the stack of commits to be backported
# together. The dependencies need not be all on the same line, nor in
# order. The script builds the union of the stacks describing one
# backport.

# Simple backports are generated as they are read, stacks are
# processed at the end of the script, once all the TSV table has been
# parsed.

lineno=0
declare -A stack
verbose=

trap "rm -f /tmp/backflip-stack.keys.$$ /tmp/backflip-stack.$$" EXIT

usage()
{
    echo Usage: $0 [-v] '<' TSV-table
    exit 1
}

if [ $# -gt 1 ]
then
    usage
fi

if [ x"$1" = x-v ]
then
    verbose=1
else
    if [ x"$1" != x ]
    then
	usage
    fi
fi

while read line
do
    lineno=$(( lineno = lineno + 1 ))
    # We replace the tab separator by a comma in the sed command at
    # the bottom of the loop. This is needed to use IFS.
    saved_IFS=$IFS
    IFS=','

    set $line
    IFS=$saved_IFS

    svn=$1
    fsf=$2
    linaro=$3
    summary=$4
    target=$5
    type=$6
    stackwith=$7
    notes=$8
    status=$9
    owner=${10}
    author=${11}
    #echo svn $svn fsf $fsf linaro $linaro

    case $svn in
	Colors*|revs)
	    [ $verbose ] && echo "skipping line $lineno"
	    continue
	    ;;
	"")
	    [ $verbose ] && echo "skipping line $lineno with empty 1st elem"
	    continue
	    ;;
	[0-9][0-9][0-9][0-9][0-9][0-9])
	    [ $verbose ] && echo "Handling revision $svn"
	    if [ x"$fsf" != x ]; then
		[ $verbose ] && echo "$svn will come from branch merge, skipping (fsf rev=$fsf)"
		continue
	    fi
	    case $status in
		on*going)
		    [ $verbose ] && echo "$svn backport already on-going"
		    continue
		    ;;
	    esac
	    case $linaro in
		"")
		    [ $verbose ] && echo "$svn needs to be backported, alone"
		    echo backflip -x $svn "|| echo failed to backport $svn"
		    ;;
		auto)
		    [$verbose ] && echo "$svn backported automatically, skipping"
		    continue
		    ;;
		no)
		    [ $verbose ] && echo "$svn not wanted, skipping"
		    continue
		    ;;
		stack)
		    [ $verbose ] && echo "$svn should be stacked with $stackwith"
		    # Sort stack, use a tmp file to avoid shell
		    # sub-processes.
		    for rev in $stackwith
		    do
			echo $rev
		    done | sort > /tmp/backflip-stack.$$
		    while read rev
		    do
			# The stacks we build are ordered (increasing
			# revisions), but there may be overlaps. We'll
			# merge them later.

			# revisions in the 'svn' column are sorted, so
			# if $rev < $svn, it means that this stack has
			# already been started. Append to the existing
			# stack.
			if [ $rev -lt $svn ]
			then
			    stack[${rev}]="${stack[${rev}]} ${svn}"
			else
			    stack[${svn}]="${stack[${svn}]} $rev"
			fi
		    done < /tmp/backflip-stack.$$
		    continue # FIXME
		    ;;
		*not*yet)
		    [ $verbose ] && echo "$svn is part of a stack which is not ready yet"
		    continue
		    ;;
		"via merge")
		    echo "ERROR: rev $svn should already be handled"
		    continue
		    ;;
		*)
		    [ $verbose ] && echo "$svn type $linaro already backported, skipping"
		    continue
		    ;;
	    esac
	    ;;
	*)
	    echo "Unsupported line $svn"
	    ;;
    esac
done < <(sed -e 's/,//g' -e 's/	/,/g')

# Sort the keys, to process them in order, so that we can build the
# union of the stacks in case of overlap
for key in ${!stack[@]}
do
    echo ${key}
done | sort > /tmp/backflip-stack.keys.$$

for key in `cat /tmp/backflip-stack.keys.$$`
do
    backport=
    # If the stack of $key is empty, it means it has already been
    # processed as part of a previous stack: ignore it.
    if [ x"${stack[${key}]}" != x ]
    then
	backport="${key}"
	for rev in ${stack[${key}]}
	do
	    backport="${backport} ${rev} ${stack[${rev}]}"
	    stack[${rev}]=
	done
	[ $verbose ] && echo stack: ${backport}
	echo backflip -x ${backport} "|| echo failed to backport ${backport}"
    fi
done