3 # Invoked from taskd/taskd.pl
7 # darcs fast-export | git fast-import with error handling
12 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
14 exec 4>&3 3>&1 1>&4 4>&-
15 { _e1=0; "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks "$1" 3>&- || _e1=$?; echo $_e1 >&3; } | \
16 { _e2=0; git fast-import --force --export-marks=$(pwd)/gfi-marks 3>&- || _e2=$?; echo $_e2 >&3; }
20 [ "$_err1" = 0 -a "$_err2" = 0 ]
24 # bzr fast-export | git fast-import with error handling
29 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
31 exec 4>&3 3>&1 1>&4 4>&-
32 { _e1=0; bzr fast-export --export-marks=$(pwd)/bfe-marks "$1" 3>&- || _e1=$?; echo $_e1 >&3; } | \
33 { _e2=0; git fast-import --force --export-marks=$(pwd)/gfi-marks 3>&- || _e2=$?; echo $_e2 >&3; }
37 [ "$_err1" = 0 -a "$_err2" = 0 ]
44 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
47 proj
="${projdir%.git}"
49 cd "$cfg_reporoot/$projdir"
50 trap "echo '@OVER@'; touch .clone_failed" EXIT
51 [ -n "$cfg_mirror" ] ||
{ echo "Mirroring is disabled" >&2; exit 1; }
52 url
="$(config_get baseurl)"
54 if [ "$cfg_project_owners" = "source" ]; then
55 config_set owner
"$(stat -c %U "$url" 2>/dev/null)"
58 mailaddrs
="$(config_get owner || :)"
59 [ -z "$cfg_admin" ] || \
60 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
63 echo "Initiating mirroring..."
65 svn
://* | svn
+http
://* | svn
+https
://*)
66 [ -n "$cfg_mirror_svn" ] ||
{ echo "Mirroring svn is disabled" >&2; exit 1; }
67 # We just remove svn+ here, so svn+http://... becomes http://...
68 # We also remove a trailing '/' to match what git-svn will do
71 # We require svn info to succeed on the URL otherwise it's
72 # simply not a valid URL and without using -s on the init it
73 # will not otherwise be tested until the fetch
74 svn
--non-interactive info
"$svnurl" > /dev
/null
75 # We initially use -s for the init which will possibly shorten
76 # the URL. However, the shortening can fail if a password is
77 # not required for the longer version but is for the shorter,
78 # so try again without -s if the -s version fails.
79 # We must use GIT_DIR=. here or ever so "helpful" git-svn will
80 # create a .git subdirectory!
81 GIT_DIR
=. git svn init
--prefix= -s "$svnurl" < /dev
/null || \
82 GIT_DIR
=. git svn init
--prefix= "$svnurl" < /dev
/null
83 # We need to remember this url so we can detect changes because
84 # ever so "helpful" git-svn may shorten it!
85 config_set svnurl
"$svnurl"
86 # At this point, since we asked for a standard layout (-s) git-svn
87 # may have been "helpful" and adjusted our $svnurl to a prefix and
88 # then glued the removed suffix onto the front of any svn-remote.svn.*
89 # config items. We could avoid this by not using the '-s' option
90 # but then we might not get all the history. If, for example, we
91 # are cloning an http://svn.example.com/repos/public repository that
92 # early in its history moved trunk => public/trunk we would miss that
93 # earlier history without allowing the funky shorten+prefix behavior.
94 # So we read back the svn-remote.svn.fetch configuration and compute
95 # the prefix. This way we are sure to get the correct prefix.
96 gitsvnurl
="$(git config --get svn-remote.svn.url || :)"
97 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | tail -1 || :)"
98 gitsvnprefix
="${gitsvnfetch%%:*}"
99 gitsvnsuffix
="${gitsvnprefix##*/}"
100 gitsvnprefix
="${gitsvnprefix%$gitsvnsuffix}"
101 # Ask git-svn to store everything in the normal non-remote
102 # locations being careful to use the correct prefix
103 git config
--replace-all svn-remote.svn.fetch
"${gitsvnprefix}trunk:refs/heads/master"
104 git config
--replace-all svn-remote.svn.branches
"${gitsvnprefix}branches/*:refs/heads/*"
105 git config
--replace-all svn-remote.svn.tags
"${gitsvnprefix}tags/*:refs/tags/*"
106 # look for additional non-standard directories to fetch
107 # check for standard layout at the same time
110 { svn
--non-interactive ls "$gitsvnurl/${gitsvnprefix}" 2>/dev
/null ||
:; } | \
111 { while read file; do case $file in
112 # skip the already-handled standard ones and any with a space or tab
114 trunk
/|branches
/|tags
/) foundstd
=1;;
115 # only fetch extra directories from the $svnurl root (not any files)
116 *?
/) git config
--add svn-remote.svn.fetch \
117 "${gitsvnprefix}${file%/}:refs/heads/${file%/}";;
120 # if files found and no standard directories present use a simpler layout
121 if [ -z "$foundstd" ] && [ -n "$foundfile" ]; then
122 git config
--unset svn-remote.svn.branches
123 git config
--unset svn-remote.svn.tags
124 git config
--replace-all svn-remote.svn.fetch
':refs/heads/master'
126 # Again, be careful to use GIT_DIR=. here or else new .git subdirectory!
127 GIT_DIR
=. git svn fetch
--quiet < /dev
/null
128 # git svn does not preserve group permissions in the svn subdirectory
129 chmod -R ug
+rw
,o
+r svn
130 # git svn also leaves behind ref turds that end with @nnn
131 # We get rid of them now
133 { while read sha1 ref
; do
135 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
136 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
137 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
138 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
139 git update-ref
-d "$ref"
144 [ -n "$cfg_mirror_darcs" ] ||
{ echo "Mirroring darcs is disabled" >&2; exit 1; }
145 httpurl
="http://${url#darcs://}"
146 # Remove any left-over .darcs dirs from a previous failed attempt
148 git_darcs_fetch
"$httpurl"
151 [ -n "$cfg_mirror_bzr" ] ||
{ echo "Mirroring bzr is disabled" >&2; exit 1; }
152 # we just remove bzr:// here, a typical bzr url is just
154 bzrurl
="${url#bzr://}"
155 git_bzr_fetch
"$bzrurl"
157 hg
+http
://* | hg
+https
://*)
158 [ -n "$cfg_mirror_hg" ] ||
{ echo "Mirroring hg is disabled" >&2; exit 1; }
159 # We just remove hg+ here, so hg+http://... becomes http://...
161 # Remove any left-over repo.hg dir from a previous failed attempt
163 # Remove any left-over export files from a previous failed attempt
164 rm -f hg2git-heads hg2git-mapping hg2git-marks
* hg2git-state
165 # Perform the initial hg clone
166 hg clone
-U "$hgurl" "$(pwd)/repo.hg"
167 # Do the fast-export | fast-import
171 git remote
rm origin
>/dev
/null
2>&1 ||
:
172 # starting with Git 1.7.5 --mirror by itself will spew a warning
173 # since we support older Git versions, just toss the warning
174 git remote add
--mirror origin
"$url" 2>/dev
/null
175 GIT_SSL_NO_VERIFY
=1 git remote update
176 GIT_SSL_NO_VERIFY
=1 git remote prune origin
180 # The objects subdirectories permissions must be updated now.
181 # In the case of a dumb http clone, the permissions will not be correct
182 # (missing group write) despite the core.sharedrepository=1 setting!
183 # The objects themselves seem to have the correct permissions.
184 # This problem appears to have been fixed in the most recent git versions.
186 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
187 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
189 # Initialize gitweb.lastchange and info/lastactivity
190 git config gitweb.lastchange
"$(date '+%a, %d %b %Y %T %z')"
191 git for-each-ref
--sort=-committerdate --format='%(committerdate:iso8601)' \
192 --count=1 refs
/heads
> info
/lastactivity
193 [ -s info
/lastactivity
] ||
rm -f info
/lastactivity
196 echo "Final touches..."
197 git update-server-info
200 [ -z "$mailaddrs" ] ||
201 mail -s "[$cfg_name] $proj clone completed" "$mailaddrs" <<EOT || :
202 Congratulations! The clone of project $proj just completed.
205 * GitWeb interface: $cfg_gitweburl/$projdir
206 * Project settings: $cfg_webadmurl/editproj.cgi?name=$(echo "$proj" | sed -e 's/[+]/%2B/g')
211 echo "Mirroring finished successfuly!"
212 # In case this is a re-mirror, lastgc could have been set already so clear it now
213 git config
--unset gitweb.lastgc ||
:
214 rm .clone_in_progress