blob: 495214150072c6ce76d9d66aa0b5766f675b95d6 (
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
#!/usr/bin/env bash
# This script helps you check which branches are checked out on git and make
# sure all repos linked in the current worktree are on the same branch (either
# by checking it out, or by creating it if it doesn't exist). The branch must
# exist in at least one of the repos. If it doesn't you can force its creation
# with -b.
# Syntax: llvm-branch [-d|-b] [branch]
# -d: delete chosen branch
# -b: create branch in all repos
# branch: checkout or create branch on all repos linked in the current tree
# Without arguments, the script lists all branches and highlights the current one
. llvm-common
safe_run verify_env
function print_branches() {
# TODO: put a star or something next to branches that exist in other
# worktrees? (can be found by iterating through LLVM_ROOT)
local current=$1
shift
local space=0
for each in $*; do
if [[ $space = 1 ]]; then
echo -n " "
fi
if [[ $each = $current ]]; then
echo -n "[$each]"
else
echo -n $each
fi
space=1
done
}
function switch() {
SRC=$1
branch=$2
in=$3
if [ -d $SRC ]; then
cd $SRC
pwd
if [[ $in = 'yes' ]]; then
if [[ $DELETE = '' ]]; then
echo " + Checking out $branch in $SRC"
safe_run git checkout $branch
else
echo " + Deleting $branch in $SRC"
safe_run git branch $DELETE $branch
fi
else
if [[ $DELETE = '' ]]; then
echo " + Creating $branch in $SRC"
safe_run git checkout -b $branch
fi
fi
fi
}
# Gather info
cd $LLVM_SRC
llvm_branch=`get_branch`
llvm_branches=`get_branches`
CLANG_SRC=$LLVM_SRC/tools/clang
if [ -d $CLANG_SRC ]; then
cd $CLANG_SRC
clang_branch=`get_branch`
clang_branches=`get_branches`
fi
RT_SRC=$LLVM_SRC/projects/compiler-rt
if [ -d $RT_SRC ]; then
cd $RT_SRC
rt_branch=`get_branch`
rt_branches=`get_branches`
fi
CXX_SRC=$LLVM_SRC/projects/libcxx
if [ -d $CXX_SRC ]; then
cd $CXX_SRC
cxx_branch=`get_branch`
cxx_branches=`get_branches`
fi
CXXABI_SRC=$LLVM_SRC/projects/libcxxabi
if [ -d $CXXABI_SRC ]; then
cd $CXXABI_SRC
cxxabi_branch=`get_branch`
cxxabi_branches=`get_branches`
fi
UNW_SRC=$LLVM_SRC/projects/libunwind
if [ -d $UNW_SRC ]; then
cd $UNW_SRC
unw_branch=`get_branch`
unw_branches=`get_branches`
fi
LLD_SRC=$LLVM_SRC/tools/lld
if [ -d $LLD_SRC ]; then
cd $LLD_SRC
lld_branch=`get_branch`
lld_branches=`get_branches`
fi
LLDB_SRC=$LLVM_SRC/tools/lldb
if [ -d $LLDB_SRC ]; then
cd $LLDB_SRC
lldb_branch=`get_branch`
lldb_branches=`get_branches`
fi
# Delete chosen branch
DELETE=''
if [[ $1 = '-d' || $1 = '-D' ]]; then
DELETE=$1
shift
fi
# Force creation
CREATE=''
if [[ $1 = '-b' ]]; then
if [[ $DELETE != '' ]]; then
echo "Can't create and delete branch at the same time"
exit 1
fi
CREATE=$1
shift
fi
# No branch chosen, list all
if [[ $1 = '' ]]; then
echo -n "LLVM branches: "
print_branches $llvm_branch $llvm_branches
echo
if [ -d $CLANG_SRC ]; then
echo -n "Clang branches: "
print_branches $clang_branch $clang_branches
echo
fi
if [ -d $RT_SRC ]; then
echo -n "Compiler-RT branches: "
print_branches $rt_branch $rt_branches
echo
fi
if [ -d $CXX_SRC ]; then
echo -n "LibC++ branches: "
print_branches $cxx_branch $cxx_branches
echo
fi
if [ -d $CXXABI_SRC ]; then
echo -n "LibC++ABI branches: "
print_branches $cxxabi_branch $cxxabi_branches
echo
fi
if [ -d $UNW_SRC ]; then
echo -n "LibUnwind branches: "
print_branches $unw_branch $unw_branches
echo
fi
if [ -d $LLD_SRC ]; then
echo -n "LLD branches: "
print_branches $lld_branch $lld_branches
echo
fi
if [ -d $LLDB_SRC ]; then
echo -n "LLDB branches: "
print_branches $lldb_branch $lldb_branches
echo
fi
exit
fi
# Search for branch name
branch=$1
if [[ $DELETE != '' ]]; then
if [[ $branch = 'master' ]]; then
echo "Cannot delete the master branch"
exit 1
fi
if [[ $branch = $llvm_branch ]]; then
echo "Cannot delete $branch - it is checked out in llvm"
exit 2
fi
if [[ $branch = $clang_branch ]]; then
echo "Cannot delete $branch - it is checked out in clang"
exit 2
fi
if [[ $branch = $rt_branch ]]; then
echo "Cannot delete $branch - it is checked out in compiler rt"
exit 2
fi
if [[ $branch = $cxx_branch ]]; then
echo "Cannot delete $branch - it is checked out in libcxx"
exit 2
fi
if [[ $branch = $cxxabi_branch ]]; then
echo "Cannot delete $branch - it is checked out in libcxxabi"
exit 2
fi
if [[ $branch = $unw_branch ]]; then
echo "Cannot delete $branch - it is checked out in libunwind"
exit 2
fi
if [[ $branch = $lld_branch ]]; then
echo "Cannot delete $branch - it is checked out in lld"
exit 2
fi
if [[ $branch = $lldb_branch ]]; then
echo "Cannot delete $branch - it is checked out in lldb"
exit 2
fi
fi
# Check which projects have the branch
in_llvm=`has $branch $llvm_branches`
in_clang=`has $branch $clang_branches`
in_rt=`has $branch $rt_branches`
in_cxx=`has $branch $cxx_branches`
in_cxxabi=`has $branch $cxxabi_branches`
in_unw=`has $branch $unw_branches`
in_lld=`has $branch $lld_branches`
in_lldb=`has $branch $lldb_branches`
if [[ $CREATE = '' ]]; then
if [[ $in_clang = 'no' && $in_llvm = 'no' && \
$in_rt = 'no' && $in_cxx = 'no' && $in_cxxabi = 'no' && \
$in_unw = 'no' && $in_lld = 'no' && $in_lldb = 'no' ]]; then
echo "Branch $branch doesn't exist on any repository"
echo "Force its creation with -b"
exit 1
fi
fi
# DO IT
switch $LLVM_SRC $branch $in_llvm
switch $CLANG_SRC $branch $in_clang
switch $RT_SRC $branch $in_rt
switch $CXX_SRC $branch $in_cxx
switch $CXXABI_SRC $branch $in_cxxabi
switch $UNW_SRC $branch $in_unw
switch $LLD_SRC $branch $in_lld
switch $LLDB_SRC $branch $in_lldb
|