5 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
6 datefmt
='+%a, %d %b %Y %T %z'
8 # darcs fast-export | git fast-import with error handling
14 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
16 exec 4>&3 3>&1 1>&4 4>&-
19 "$cfg_basedir"/bin/darcs-fast-export \
20 --export-marks="$(pwd)/dfe-marks" \
21 --import-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$?
27 --export-marks="$(pwd)/gfi-marks" \
28 --export-pack-edges="$(pwd)/gfi-packs" \
29 --import-marks="$(pwd)/gfi-marks" \
30 --force 3>&- || _e2=$?
36 [ "$_err1" = 0 -a "$_err2" = 0 ]
40 # bzr fast-export | git fast-import with error handling
46 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
48 exec 4>&3 3>&1 1>&4 4>&-
52 --export-marks="$(pwd)/dfe-marks" \
53 --import-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$?
59 --export-marks="$(pwd)/gfi-marks" \
60 --export-pack-edges="$(pwd)/gfi-packs" \
61 --import-marks="$(pwd)/gfi-marks" \
62 --force 3>&- || _e2=$?
68 [ "$_err1" = 0 -a "$_err2" = 0 ]
73 [ -n "$cfg_mirror" ] ||
{ echo "Mirroring is disabled" >&2; exit 0; }
74 trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
77 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
80 cd "$cfg_reporoot/$proj.git"
82 if check_interval lastrefresh
$cfg_min_mirror_interval; then
83 progress
"= [$proj] update skip (last at $(config_get lastrefresh))"
86 progress
"+ [$proj] update (`date`)"
92 bang
echo "Project: $proj"
93 mail="$(config_get owner || :)"
94 url
="$(config_get baseurl || :)"
95 case "$url" in *" "*|
*" "*|
"")
96 bang_eval
'echo "Bad mirror URL (\"$url\")"; ! :'
99 bang
echo "Mirroring from URL \"$url\""
101 statusok
="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
103 [ "$statusok" = "false" -o -z "$mail" ] || mailaddrs
="$mail"
104 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \
105 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
107 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
108 bang_eval
"LC_ALL=C sort -k1b,1 <.refs-temp >.refs-before"
111 svn
://* | svn
+http
://* | svn
+https
://*)
112 [ -n "$cfg_mirror_svn" ] ||
{ echo "Mirroring svn is disabled" >&2; exit 0; }
113 # Use an 'anonsvn' username as is commonly used for anonymous svn
114 # Use an 'anonsvn' password as is commonly used for anonymous svn
115 GIT_ASKPASS_PASSWORD
=anonsvn
116 export GIT_ASKPASS_PASSWORD
117 # Update the git svn url to match baseurl but be cognizant of any
118 # needed prefix changes. See the comments in taskd/clone.sh about
119 # why we need to put up with a prefix in the first place.
122 svnurlold
="$(config_get svnurl || :)"
123 if [ "$svnurl" != "$svnurlold" ]; then
124 # We better already have an svn-remote.svn.fetch setting
125 bang
test -n "$(git config --get-all svn-remote.svn.fetch || :)"
126 # the only way to truly know what the proper prefix is
127 # is to attempt a fresh git-svn init -s on the new url
128 rm -rf svn-new-url ||
:
129 # We require svn info to succeed on the URL otherwise it's
130 # simply not a valid URL and without using -s on the init it
131 # will not otherwise be tested until the fetch
132 bang
eval 'svn --non-interactive --username anonsvn --password anonsvn info "$svnurl" > /dev/null'
133 bang mkdir svn-new-url
134 GIT_DIR
=svn-new-url bang git init
--bare --quiet
135 # We initially use -s for the init which will possibly shorten
136 # the URL. However, the shortening can fail if a password is
137 # not required for the longer version but is for the shorter,
138 # so try again without -s if the -s version fails.
139 cmdstr
='git svn init --username=anonsvn --prefix "" -s "$svnurl" < /dev/null > /dev/null 2>&1 || '
140 cmdstr
="$cmdstr"'git svn init --username=anonsvn --prefix "" "$svnurl" < /dev/null > /dev/null 2>&1'
141 GIT_DIR
=svn-new-url bang
eval "$cmdstr"
142 gitsvnurl
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url || :)"
143 gitsvnfetch
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch || :)"
144 gitsvnprefixnew
="${gitsvnfetch%%:*}"
145 gitsvnsuffixnew
="${gitsvnprefixnew##*/}"
146 gitsvnprefixnew
="${gitsvnprefixnew%$gitsvnsuffixnew}"
147 rm -rf svn-new-url ||
:
148 # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to .
150 if [ "$gitsvnurl" != "$(git config --get svn-remote.svn.url || :)" ]; then
151 # The url has been changed.
152 # We must update the url and replace the prefix on all config items
153 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | head -1 || :)"
154 gitsvnprefixold
="${gitsvnfetch%%:*}"
155 gitsvnsuffixold
="${gitsvnprefixold##*/}"
156 gitsvnprefixold
="${gitsvnprefixold%$gitsvnsuffixold}"
157 git config
--remove-section 'svn-remote.svnnew' 2>/dev
/null ||
:
158 git config
'svn-remote.svnnew.url' "$gitsvnurl"
159 { git config
--get-regexp '^svn-remote\.svn\.' ||
:; } | \
160 { while read sname sval
; do
162 svn-remote.svn.fetch|svn-remote.svn.branches|svn-remote.svn.tags
)
163 sname
="${sname#svn-remote.svn.}"
164 sval
="${sval#$gitsvnprefixold}"
165 bang git config
--add "svn-remote.svnnew.$sname" "${gitsvnprefixnew}$sval"
168 bang git config
-f svn
/.metadata svn-remote.svn.reposRoot
"$gitsvnurl"
169 bang git config
--remove-section svn-remote.svn
170 bang git config
--rename-section svn-remote.svnnew svn-remote.svn
172 bang config_set svnurl
"$svnurl"
174 # remove any stale *.lock files greater than 1 hour old in case
175 # git-svn was killed on the last update because it took too long
176 find svn
-type f
-name '*.lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
177 GIT_DIR
=. bang git svn fetch
--username=anonsvn
--quiet < /dev
/null
178 # git svn does not preserve group permissions in the svn subdirectory
179 chmod -R ug
+rw
,o
+r svn
180 # git svn also leaves behind ref turds that end with @nnn
181 # We get rid of them now
183 { while read sha1 ref
; do
185 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
186 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
187 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
188 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
189 git update-ref
-d "$ref"
192 unset GIT_ASKPASS_PASSWORD
195 [ -n "$cfg_mirror_darcs" ] ||
{ echo "Mirroring darcs is disabled" >&2; exit 0; }
196 httpurl
="http://${url#darcs://}"
197 # remove any stale lock files greater than 1 hour old in case
198 # darcs_fast_export was killed on the last update because it took too long
199 find *.darcs
-maxdepth 2 -type f
-name 'lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
200 bang git_darcs_fetch
"$httpurl"
203 [ -n "$cfg_mirror_bzr" ] ||
{ echo "Mirroring bzr is disabled" >&2; exit 0; }
204 bzrurl
="${url#bzr://}"
205 bang git_bzr_fetch
"$bzrurl"
207 hg
+http
://* | hg
+https
://*)
208 [ -n "$cfg_mirror_hg" ] ||
{ echo "Mirroring hg is disabled" >&2; exit 0; }
209 # We just remove hg+ here, so hg+http://... becomes http://...
211 # Fetch any new updates
212 bang hg
-R "$(pwd)/repo.hg" pull
213 # Do the fast-export | fast-import
217 [ "$url" = "$(git config --get remote.origin.url || :)" ] || bang config_set_raw remote.origin.url
"$url"
218 GIT_SSL_NO_VERIFY
=1 bang git remote update
219 GIT_SSL_NO_VERIFY
=1 bang git remote prune origin
223 # The objects subdirectories permissions must be updated now.
224 # In the case of a dumb http clone, the permissions will not be correct
225 # (missing group write) despite the core.sharedrepository=1 setting!
226 # The objects themselves seem to have the correct permissions.
227 # This problem appears to have been fixed in the most recent git versions.
229 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
230 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
232 bang git update-server-info
233 bang config_set lastrefresh
"$(date "$datefmt")"
235 # Look at which refs changed and trigger ref-change for these
236 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
237 bang_eval
"LC_ALL=C sort -k1b,1 <.refs-temp >.refs-after"
238 sockpath
="$cfg_chroot/etc/taskd.socket"
239 if ! cmp -s .refs-before .refs-after
; then
240 bang config_set lastreceive
"$(date '+%a, %d %b %Y %T %z')"
241 if [ -S "$sockpath" ]; then
242 LC_ALL
=C
join -j 1 .refs-before .refs-after |
243 while read ref old new
; do
244 [ "$old" != "$new" ] ||
continue
245 echo "ref-change %$proj% $proj $old $new $ref" | nc_openbsd
-w 1 -U "$sockpath"
247 LC_ALL
=C
join -j 1 -v 1 .refs-before .refs-after |
248 while read ref old
; do
249 echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | \
250 nc_openbsd
-w 1 -U "$sockpath"
252 LC_ALL
=C
join -j 1 -v 2 .refs-before .refs-after |
253 while read ref new
; do
254 echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | \
255 nc_openbsd
-w 1 -U "$sockpath"
258 bang config_set lastchange
"$(date '+%a, %d %b %Y %T %z')"
259 bang_eval
"git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
260 --count=1 refs/heads > info/lastactivity"
263 rm -f .refs-before .refs-after .refs-temp
266 [ -z "$mailaddrs" ] ||
268 echo "$proj update succeeded - failure recovery"
269 echo "this status message may be disabled on the project admin page"
270 } |
mail -s "[$cfg_name] $proj update succeeded" "$mailaddrs" ||
:
274 progress
"- [$proj] update (`date`)"