3 # Invoked from taskd/taskd.pl
7 # darcs fast-export | git fast-import with error handling
13 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
15 exec 4>&3 3>&1 1>&4 4>&-
18 "$cfg_basedir"/bin/darcs-fast-export \
19 --export-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$?
25 --export-marks="$(pwd)/gfi-marks" \
26 --export-pack-edges="$(pwd)/gfi-packs" \
27 --force 3>&- || _e2=$?
33 [ "$_err1" = 0 -a "$_err2" = 0 ]
37 # bzr fast-export | git fast-import with error handling
45 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
47 exec 4>&3 3>&1 1>&4 4>&-
50 bzr fast-export --plain \
51 --export-marks="$(pwd)/bfe-marks" "$1" 3>&- || _e1=$?
57 --export-marks="$(pwd)/gfi-marks" \
58 --export-pack-edges="$(pwd)/gfi-packs" \
59 --force 3>&- || _e2=$?
65 [ "$_err1" = 0 -a "$_err2" = 0 ]
71 # We must now close the .clonelog file that is open on stdout and stderr
73 failaddrs
="$(config_get owner || :)"
74 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \
75 if [ -z "$failaddrs" ]; then failaddrs
="$cfg_admin"; else failaddrs
="$failaddrs,$cfg_admin"; fi
76 [ -z "$failaddrs" ] || \
79 Condolences. The clone of project $proj just failed.
82 * Project settings: $cfg_webadmurl/editproj.cgi?name=$(echo "$proj" | sed -e 's/[+]/%2B/g')
84 The project settings link may be used to adjust the settings
85 and restart the clone in order to try the clone again.
87 if [ -f .clonelog
-a -r .clonelog
]; then
91 loglines
=$
(wc -l <.clonelog
)
92 if [ $loglines -le 203 ]; then
97 echo "[ ... elided $(( $loglines - 200 )) middle lines ... ]"
102 } |
mail -s "[$cfg_name] $proj clone failed" "$failaddrs" ||
:
108 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
111 cd "$cfg_reporoot/$proj.git"
114 ! [ -e .delaygc
] ||
> .allowgc ||
:
116 # Any pre-existing FETCH_HEAD from a previous clone failed or not is garbage
119 trap "echo '@OVER@'; touch .clone_failed; send_clone_failed" EXIT
120 echo "Project: $proj"
122 [ -n "$cfg_mirror" ] ||
{ echo "Mirroring is disabled" >&2; exit 1; }
123 url
="$(config_get baseurl || :)"
124 case "$url" in *" "*|
*" "*|
"")
125 echo "Bad mirror URL (\"$url\")"
128 echo "Mirroring from URL \"$url\""
131 if [ "$cfg_project_owners" = "source" ]; then
132 config_set owner
"$(stat -c %U "$url" 2>/dev/null)"
135 mailaddrs
="$(config_get owner || :)"
136 [ -z "$cfg_admin" ] || \
137 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
140 echo "Initiating mirroring..."
145 svn
://* | svn
+http
://* | svn
+https
://* | svn
+file://*)
146 [ -n "$cfg_mirror_svn" ] ||
{ echo "Mirroring svn is disabled" >&2; exit 1; }
147 # We just remove svn+ here, so svn+http://... becomes http://...
148 # We also remove a trailing '/' to match what git-svn will do
151 # Remove any left-over svn-remote.svn config from a previous failed attempt
152 git config
--remove-section svn-remote.svn
2>/dev
/null ||
:
153 # Remove any left-over svn dir from a previous failed attempt
155 # Use an 'anonsvn' username as is commonly used for anonymous svn
156 # Use an 'anonsvn' password as is commonly used for anonymous svn
157 GIT_ASKPASS_PASSWORD
=anonsvn
158 export GIT_ASKPASS_PASSWORD
159 # We require svn info to succeed on the URL otherwise it's
160 # simply not a valid URL and without using -s on the init it
161 # will not otherwise be tested until the fetch
162 svn
--non-interactive --username anonsvn
--password anonsvn info
"$svnurl" > /dev
/null
163 # We initially use -s for the init which will possibly shorten
164 # the URL. However, the shortening can fail if a password is
165 # not required for the longer version but is for the shorter,
166 # so try again without -s if the -s version fails.
167 # We must use GIT_DIR=. here or ever so "helpful" git-svn will
168 # create a .git subdirectory!
169 GIT_DIR
=. git svn init
--username=anonsvn
--prefix "" -s "$svnurl" < /dev
/null || \
170 GIT_DIR
=. git svn init
--username=anonsvn
--prefix "" "$svnurl" < /dev
/null
171 # We need to remember this url so we can detect changes because
172 # ever so "helpful" git-svn may shorten it!
173 config_set svnurl
"$svnurl"
174 # At this point, since we asked for a standard layout (-s) git-svn
175 # may have been "helpful" and adjusted our $svnurl to a prefix and
176 # then glued the removed suffix onto the front of any svn-remote.svn.*
177 # config items. We could avoid this by not using the '-s' option
178 # but then we might not get all the history. If, for example, we
179 # are cloning an http://svn.example.com/repos/public repository that
180 # early in its history moved trunk => public/trunk we would miss that
181 # earlier history without allowing the funky shorten+prefix behavior.
182 # So we read back the svn-remote.svn.fetch configuration and compute
183 # the prefix. This way we are sure to get the correct prefix.
184 gitsvnurl
="$(git config --get svn-remote.svn.url || :)"
185 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)"
186 gitsvnprefix
="${gitsvnfetch%%:*}"
187 gitsvnsuffix
="${gitsvnprefix##*/}"
188 gitsvnprefix
="${gitsvnprefix%$gitsvnsuffix}"
189 # Ask git-svn to store everything in the normal non-remote
190 # locations being careful to use the correct prefix
191 git config
--replace-all svn-remote.svn.fetch
"${gitsvnprefix}trunk:refs/heads/master"
192 git config
--replace-all svn-remote.svn.branches
"${gitsvnprefix}branches/*:refs/heads/*"
193 git config
--replace-all svn-remote.svn.tags
"${gitsvnprefix}tags/*:refs/tags/*"
194 # look for additional non-standard directories to fetch
195 # check for standard layout at the same time
198 { svn
--non-interactive --username anonsvn
--password anonsvn
ls "$gitsvnurl/${gitsvnprefix}" 2>/dev
/null ||
:; } | \
199 { while read file; do case $file in
200 # skip the already-handled standard ones and any with a space or tab
202 trunk
/|branches
/|tags
/) foundstd
=1;;
203 # only fetch extra directories from the $svnurl root (not any files)
204 *?
/) git config
--add svn-remote.svn.fetch \
205 "${gitsvnprefix}${file%/}:refs/heads/${file%/}";;
208 # if files found and no standard directories present use a simpler layout
209 if [ -z "$foundstd" ] && [ -n "$foundfile" ]; then
210 git config
--unset svn-remote.svn.branches
211 git config
--unset svn-remote.svn.tags
212 git config
--replace-all svn-remote.svn.fetch
':refs/heads/master'
214 # Again, be careful to use GIT_DIR=. here or else new .git subdirectory!
215 GIT_DIR
=. git svn fetch
--log-window-size=$var_log_window_size --username=anonsvn
--quiet < /dev
/null
216 # git svn does not preserve group permissions in the svn subdirectory
217 chmod -R ug
+rw
,o
+r svn
218 # git svn also leaves behind ref turds that end with @nnn
219 # We get rid of them now
220 git for-each-ref
--format='%(objectname) %(refname)' | \
221 { while read sha1 ref
; do
223 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
224 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
225 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
226 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
227 git update-ref
-d "$ref"
230 unset GIT_ASKPASS_PASSWORD
233 [ -n "$cfg_mirror_darcs" ] ||
{ echo "Mirroring darcs is disabled" >&2; exit 1; }
234 httpurl
="http://${url#darcs://}"
235 # Remove any left-over .darcs dirs from a previous failed attempt
237 # Remove any left-over export files from a previous failed attempt
238 rm -f dfe-marks gfi-marks gfi-packs
239 git_darcs_fetch
"$httpurl"
242 [ -n "$cfg_mirror_bzr" ] ||
{ echo "Mirroring bzr is disabled" >&2; exit 1; }
243 # we just remove bzr:// here, a typical bzr url is just
245 bzrurl
="${url#bzr://}"
246 # Remove any left-over export files from a previous failed attempt
247 rm -f bfe-marks gfi-marks gfi-packs
248 git_bzr_fetch
"$bzrurl"
250 hg
+http
://* | hg
+https
://*)
251 [ -n "$cfg_mirror_hg" ] ||
{ echo "Mirroring hg is disabled" >&2; exit 1; }
252 # We just remove hg+ here, so hg+http://... becomes http://...
254 # Remove any left-over repo.hg dir from a previous failed attempt
256 # Remove any left-over export files from a previous failed attempt
257 rm -f gfi-packs hg2git-heads hg2git-mapping hg2git-marks
* hg2git-state
258 # Perform the initial hg clone
259 hg clone
-U "$hgurl" "$(pwd)/repo.hg"
260 # Do the fast-export | fast-import
264 git remote
rm origin
>/dev
/null
2>&1 ||
:
265 # starting with Git 1.7.5 --mirror by itself will spew a warning
266 # since we support older Git versions, just toss the warning
267 git remote add
--mirror origin
"$url" 2>/dev
/null
268 # Set the correct HEAD symref by using ls-remote first
269 GIT_SSL_NO_VERIFY
=1 GIT_TRACE_PACKET
=1 git ls-remote origin
>.refs-temp
2>.pkts-temp || \
271 # Since everything was redirected, on failure there'd be no output,
272 # so let's make some failure output
275 echo "git ls-remote \"$url\" failed"
278 # Compensate for git() {} side effects
279 unset GIT_TRACE_PACKET
280 # If the server is running at least Git 1.8.4.3 then it will send us the actual
281 # symref for HEAD. If we are running at least Git 1.7.5 then we can snarf that
282 # out of the packet trace data.
283 if [ -s .refs-temp
]; then
284 # Nothing to do unless the remote repository has at least 1 ref
285 # See if we got a HEAD ref
286 head="$(grep -E "^
$octet20[ $tab]+HEAD\$
" <.refs-temp | awk '{print $1}')"
287 # If the remote has HEAD set to a symbolic ref that does not exist
288 # then we will not receive a HEAD ref in the ls-remote output
292 if [ -n "$head" ]; then
293 symrefcap
="$(sed -ne <.pkts-temp \
294 "/packet
:.
*git
<.
*[ $tab]symref
="'HEAD:refs\/heads\/'"[^
$tab]/\
295 {s
/^.
*[ $tab]symref
="'HEAD:\(refs\/heads\/'"[^
$tab][^
$tab]*"'\).*$/\1/;p;}')"
296 # prefer $symrefcap (refs/heads/master if no $symrefcap) if it
297 # matches HEAD otherwise take the first refs/heads/... match
300 [ -n "$ref" ] ||
continue
301 matchcnt
=$
(( $matchcnt + 1 ))
302 if [ -z "$headref" ] ||
[ "$ref" = "${symrefcap:-refs/heads/master}" ]; then
305 [ "$headref" = "${symrefcap:-refs/heads/master}" -a $matchcnt -gt 1 ] && break
307 $(grep -E "^$head[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \
310 # Warn if there was more than one match and $symrefcap is empty
311 # or $symrefcap is not the same as $headref since our choice might
312 # differ from the source repository's HEAD
313 if [ $matchcnt -ge 1 -a "$symrefcap" != "$headref" ] && \
314 [ -n "$symrefcap" -o $matchcnt -gt 1 ]; then
318 if [ -z "$headref" ]; then
319 # If we still don't have a HEAD ref then prefer refs/heads/master
320 # if it exists otherwise take the first refs/heads/...
321 # We do not support having a detached HEAD.
322 # We always warn now because we will be setting HEAD differently
323 # than the source repository had HEAD set
326 [ -n "$ref" ] ||
continue
327 if [ -z "$headref" ] ||
[ "$ref" = "refs/heads/master" ]; then
330 [ "$headref" = "refs/heads/master" ] && break
332 $(grep -E "^$octet20[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \
336 # If we STILL do not have a HEAD ref (perhaps the source repository
337 # contains only tags) then use refs/heads/master. It will be invalid
338 # but is no worse than we used to do by default and we'll warn about
339 # it. We do not support a HEAD symref to anything other than refs/heads/...
340 [ -n "$headref" ] || headref
="refs/heads/master"
341 git symbolic-ref HEAD
"$headref"
342 GIT_SSL_NO_VERIFY
=1 git remote update
--prune
345 git symbolic-ref HEAD
"refs/heads/master"
347 rm -f .refs-temp .pkts-temp
351 # The objects subdirectories permissions must be updated now.
352 # In the case of a dumb http clone, the permissions will not be correct
353 # (missing group write) despite the core.sharedrepository=1 setting!
354 # The objects themselves seem to have the correct permissions.
355 # This problem appears to have been fixed in the most recent git versions.
357 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
358 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
360 # We may have just cloned a lot of refs and they will all be
361 # individual files at this point. Let's pack them now so we
362 # can have better performance right from the start.
365 # Initialize gitweb.lastreceive, gitweb.lastchange and info/lastactivity
366 git config gitweb.lastreceive
"$(date '+%a, %d %b %Y %T %z')"
367 git config gitweb.lastchange
"$(date '+%a, %d %b %Y %T %z')"
368 git for-each-ref
--sort=-committerdate --format='%(committerdate:iso8601)' \
369 --count=1 refs
/heads
> info
/lastactivity ||
:
370 ! [ -d htmlcache
] ||
{ >htmlcache
/changed
; } 2>/dev
/null ||
:
372 # Don't leave a multi-megabyte useless FETCH_HEAD behind
376 echo "Final touches..."
377 git update-server-info
380 # allow gc now unless it's empty
381 [ -n "$warnempty" ] ||
rm -f .delaygc .allowgc
384 [ -z "$warnempty" ] ||
386 WARNING: You have mirrored an empty repository.
389 [ -n "$showheadwarn" -a -n "$headref" ] &&
391 NOTE: HEAD has been set to a symbolic ref to \"$headref\".
392 Use the \"Project settings\" link to choose a different HEAD symref.
397 NOTE: Since this is a mirror of a non-Git source, the initial repository
398 size may be somewhat larger than necessary. This will be corrected
399 shortly. If you intend to clone this repository you may want to
400 wait up to 1 hour before doing so in order to receive the more
403 [ -z "$mailaddrs" ] ||
404 mail -s "[$cfg_name] $proj clone completed" "$mailaddrs" <<EOT || :
405 Congratulations! The clone of project $proj just completed.
408 * GitWeb interface: $cfg_gitweburl/$proj.git
409 * Project settings: $cfg_webadmurl/editproj.cgi?name=$(echo "$proj" | sed -e 's/[+]/%2B/g')
410 $emptynote$headnote$sizenote
414 echo "Mirroring finished successfuly!"
415 # In case this is a re-mirror, lastgc could have been set already so clear it now
416 git config
--unset gitweb.lastgc ||
:
417 rm .clone_in_progress
418 echo "$sizenote@OVER@"