-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbzr2git.source
225 lines (178 loc) · 4.5 KB
/
bzr2git.source
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
#!/bin/bash
# initialize
unset PYTHONHOME
# Default to npandersen
: "${BZR_USER:=npandersen}"
# Default marks directory
_MARKS_DIR=marks
_MERGE_DIR=merge
# Default user
_SIESTA_USER=""
# Default to skip pull of new commits
_SKIP_PULL=1
function bzr2git_pull() {
_SKIP_PULL=0
}
function set_siesta_user {
_SIESTA_USER=$1
shift
}
# Function to provide all import-marks statements in correct order
function gmarks() {
for m in `echo -n $_GMARKS`
do
printf " --import-marks=../%s " "$m"
done
}
# Function to provide all import-marks statements in correct order
function bmarks() {
for m in `echo -n $_BMARKS`
do
printf " --import-marks=../%s " "$m"
done
}
function update_marks() {
local f=$1
shift
rm $f
while [ $# -gt 0 ]; do
printf "%s " "$1" >> $f
shift
done
}
# Download bzr-fastimport from:
# https://launchpad.net/bzr-fastimport
# AND it should be the latest trunk r360
# Also do
# pip install fastimport
# Check and create marks directory
if [ ! -d $_MARKS_DIR ]; then
mkdir $_MARKS_DIR
fi
# Initialize global marks stuff
_GMARKS=""
[ -e $_MARKS_DIR/git ] && _GMARKS=`cat $_MARKS_DIR/git`
_BMARKS=""
[ -e $_MARKS_DIR/bzr ] && _BMARKS=`cat $_MARKS_DIR/bzr`
function bzrbranch {
local DEF_URL="bzr+ssh://[email protected]/home/siesta-archives/$_SIESTA_USER"
while [ $# -gt 0 ]; do
# Other locals which are not "global"
local rem=$1
shift
echo "Fetching branch: $_SIESTA_USER/$rem"
# Local branch dir
local bdir=$_MERGE_DIR/$rem
if [ ! -d $bdir ]; then
# ensures that top-levels exists
mkdir -p $(dirname $bdir)
bzr branch $DEF_URL/bzr-repo/$rem $bdir
[ $? -ne 0 ] && return 1
elif [ $_SKIP_PULL -eq 0 ]; then
pushd $bdir
bzr pull
popd
fi
done
}
function bzr2git {
# Immediately fetch
local rem=$1
shift
if [ $_SKIP_PULL -eq 0 ]; then
bzrbranch $rem
fi
# immediately cd to directory
if [ -d siesta.git ]; then
pushd siesta.git 2>/dev/null
else
mkdir siesta.git
pushd siesta.git 2>/dev/null
git init --bare
fi
# Command for bzr fast-export
local BZR_CMD="bzr fast-export"
local GIT_CMD="git fast-import"
# Other locals which are not "global"
local bname=$rem
if [ $# -gt 0 ]; then
local bname=$1 ; shift
fi
echo "Saving with branch name $bname"
# Local branch dir
local bdir=../$_MERGE_DIR/$rem
# Local bzr/git marks
local bmark=$_MARKS_DIR/bzr.$bname
local gmark=$_MARKS_DIR/git.$bname
# Check if the branch already exists
# if so just return
local a=`git branch | grep $bname`
if [ ! -z "$a" ]; then
popd 2>/dev/null
return 0
fi
if [ "$bname" == "master" ]; then
$BZR_CMD --export-marks=../$bmark $bdir --git-branch=$bname | \
$GIT_CMD --export-marks=../$gmark
[ $? -ne 0 ] && return 1
else
$BZR_CMD --export-marks=../$bmark $(bmarks) $bdir --git-branch=$bname | \
$GIT_CMD $(gmarks) --export-marks=../$gmark
[ $? -ne 0 ] && return 1
fi
popd 2>/dev/null
# update globals
_GMARKS="$gmark $_GMARKS"
update_marks $_MARKS_DIR/git $_GMARKS
_BMARKS="$bmark $_BMARKS"
update_marks $_MARKS_DIR/bzr $_BMARKS
}
function bzrbranch_user() {
local user=$1
shift
# Update internal user
set_siesta_user $user
# First fetch branches
while read line ; do
case $line in
\#*) continue ;;
esac
# zero lines skipped
[ -z "${line// /}" ] && continue
bzrbranch ${line%% *}
done < repos/$user
}
function bzr2git_user() {
local user=$1
shift
# Update internal user
set_siesta_user $user
bzrbranch_user $user
# Make sure that we do not fetch/update (done above)
local old=$_SKIP_PULL
_SKIP_PULL=1
while read line ; do
case $line in
\#*) continue ;;
esac
# zero lines skipped
[ -z "${line// /}" ] && continue
local bzr_rem=${line%% *}
local git_loc=${line##* }
bzr2git $bzr_rem $git_loc
done < repos/$user
_SKIP_PULL=$old
}
echo ""
echo "Currently available shell-commands:"
echo " bzr2git_pull"
echo " inform bzr2git to also perform pull of the remote bzr repo"
echo " set_siesta_user <user>"
echo " update the siesta-user for the remote bzr-repo directory:"
echo " set_siesta_user npandersen ...> siesta.icmab.es/npandersen/bzr-repo"
echo " bzrbranch <remote>"
echo " fetches the remote branch (from `set_siesta_user`)"
echo " This will set the user to siesta and fetch the trunk version:"
echo " set_siesta_user siesta"
echo " bzrbranch trunk"
echo ""