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
15 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
17 exec 4>&3 3>&1 1>&4 4>&-
20 "$cfg_basedir"/bin/darcs-fast-export \
21 --export-marks="$(pwd)/dfe-marks" \
22 --import-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$?
28 --export-marks="$(pwd)/gfi-marks" \
29 --export-pack-edges="$(pwd)/gfi-packs" \
30 --import-marks="$(pwd)/gfi-marks" \
31 --force 3>&- || _e2=$?
37 [ "$_err1" = 0 -a "$_err2" = 0 ]
41 # bzr fast-export | git fast-import with error handling
48 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
50 exec 4>&3 3>&1 1>&4 4>&-
54 --export-marks="$(pwd)/dfe-marks" \
55 --import-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$?
61 --export-marks="$(pwd)/gfi-marks" \
62 --export-pack-edges="$(pwd)/gfi-packs" \
63 --import-marks="$(pwd)/gfi-marks" \
64 --force 3>&- || _e2=$?
70 [ "$_err1" = 0 -a "$_err2" = 0 ]
75 [ -n "$cfg_mirror" ] ||
{ echo "Mirroring is disabled" >&2; exit 0; }
76 trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
79 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
82 cd "$cfg_reporoot/$proj.git"
84 if check_interval lastrefresh
$cfg_min_mirror_interval; then
85 progress
"= [$proj] update skip (last at $(config_get lastrefresh))"
88 progress
"+ [$proj] update (`date`)"
94 mail="$(config_get owner || :)"
95 url
="$(config_get baseurl || :)"
96 case "$url" in *" "*|
*" "*|
"")
97 bang_eval
'echo "Bad mirror URL (\"$url\")"; ! :'
100 bang
echo "Mirroring from URL \"$url\""
102 statusok
="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
104 [ "$statusok" = "false" -o -z "$mail" ] || mailaddrs
="$mail"
105 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \
106 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
108 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
109 bang_eval
"LC_ALL=C sort -k1b,1 <.refs-temp >.refs-before"
112 svn
://* | svn
+http
://* | svn
+https
://*)
113 [ -n "$cfg_mirror_svn" ] ||
{ echo "Mirroring svn is disabled" >&2; exit 0; }
114 # Update the git svn url to match baseurl but be cognizant of any
115 # needed prefix changes. See the comments in taskd/clone.sh about
116 # why we need to put up with a prefix in the first place.
119 svnurlold
="$(config_get svnurl || :)"
120 if [ "$svnurl" != "$svnurlold" ]; then
121 # We better already have an svn-remote.svn.fetch setting
122 bang
test -n "$(git config --get-all svn-remote.svn.fetch || :)"
123 # the only way to truly know what the proper prefix is
124 # is to attempt a fresh git-svn init -s on the new url
125 rm -rf svn-new-url ||
:
126 # We require svn info to succeed on the URL otherwise it's
127 # simply not a valid URL and without using -s on the init it
128 # will not otherwise be tested until the fetch
129 bang
eval 'svn --non-interactive info "$svnurl" > /dev/null'
130 bang mkdir svn-new-url
131 GIT_DIR
=svn-new-url bang git init
--bare --quiet
132 # We initially use -s for the init which will possibly shorten
133 # the URL. However, the shortening can fail if a password is
134 # not required for the longer version but is for the shorter,
135 # so try again without -s if the -s version fails.
136 cmdstr
='git svn init --prefix "" -s "$svnurl" < /dev/null > /dev/null 2>&1 || '
137 cmdstr
="$cmdstr"'git svn init --prefix "" "$svnurl" < /dev/null > /dev/null 2>&1'
138 GIT_DIR
=svn-new-url bang
eval "$cmdstr"
139 gitsvnurl
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url || :)"
140 gitsvnfetch
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch || :)"
141 gitsvnprefixnew
="${gitsvnfetch%%:*}"
142 gitsvnsuffixnew
="${gitsvnprefixnew##*/}"
143 gitsvnprefixnew
="${gitsvnprefixnew%$gitsvnsuffixnew}"
144 rm -rf svn-new-url ||
:
145 # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to .
147 if [ "$gitsvnurl" != "$(git config --get svn-remote.svn.url || :)" ]; then
148 # The url has been changed.
149 # We must update the url and replace the prefix on all config items
150 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | head -1 || :)"
151 gitsvnprefixold
="${gitsvnfetch%%:*}"
152 gitsvnsuffixold
="${gitsvnprefixold##*/}"
153 gitsvnprefixold
="${gitsvnprefixold%$gitsvnsuffixold}"
154 git config
--remove-section 'svn-remote.svnnew' 2>/dev
/null ||
:
155 git config
'svn-remote.svnnew.url' "$gitsvnurl"
156 { git config
--get-regexp '^svn-remote\.svn\.' ||
:; } | \
157 { while read sname sval
; do
159 svn-remote.svn.fetch|svn-remote.svn.branches|svn-remote.svn.tags
)
160 sname
="${sname#svn-remote.svn.}"
161 sval
="${sval#$gitsvnprefixold}"
162 bang git config
--add "svn-remote.svnnew.$sname" "${gitsvnprefixnew}$sval"
165 bang git config
-f svn
/.metadata svn-remote.svn.reposRoot
"$gitsvnurl"
166 bang git config
--remove-section svn-remote.svn
167 bang git config
--rename-section svn-remote.svnnew svn-remote.svn
169 bang config_set svnurl
"$svnurl"
171 # remove any stale *.lock files greater than 1 hour old in case
172 # git-svn was killed on the last update because it took too long
173 find svn
-type f
-name '*.lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
174 GIT_DIR
=. bang git svn fetch
--quiet < /dev
/null
175 # git svn does not preserve group permissions in the svn subdirectory
176 chmod -R ug
+rw
,o
+r svn
177 # git svn also leaves behind ref turds that end with @nnn
178 # We get rid of them now
180 { while read sha1 ref
; do
182 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
183 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
184 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
185 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
186 git update-ref
-d "$ref"
191 [ -n "$cfg_mirror_darcs" ] ||
{ echo "Mirroring darcs is disabled" >&2; exit 0; }
192 httpurl
="http://${url#darcs://}"
193 # remove any stale lock files greater than 1 hour old in case
194 # darcs_fast_export was killed on the last update because it took too long
195 find *.darcs
-maxdepth 2 -type f
-name 'lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
196 bang git_darcs_fetch
"$httpurl"
199 [ -n "$cfg_mirror_bzr" ] ||
{ echo "Mirroring bzr is disabled" >&2; exit 0; }
200 bzrurl
="${url#bzr://}"
201 bang git_bzr_fetch
"$bzrurl"
203 hg
+http
://* | hg
+https
://*)
204 [ -n "$cfg_mirror_hg" ] ||
{ echo "Mirroring hg is disabled" >&2; exit 0; }
205 # We just remove hg+ here, so hg+http://... becomes http://...
207 # Fetch any new updates
208 bang hg
-R "$(pwd)/repo.hg" pull
209 # Do the fast-export | fast-import
213 [ "$url" = "$(git config --get remote.origin.url || :)" ] || bang config_set_raw remote.origin.url
"$url"
214 GIT_SSL_NO_VERIFY
=1 bang git remote update
215 GIT_SSL_NO_VERIFY
=1 bang git remote prune origin
219 # The objects subdirectories permissions must be updated now.
220 # In the case of a dumb http clone, the permissions will not be correct
221 # (missing group write) despite the core.sharedrepository=1 setting!
222 # The objects themselves seem to have the correct permissions.
223 # This problem appears to have been fixed in the most recent git versions.
225 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
226 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
228 bang git update-server-info
229 bang config_set lastrefresh
"$(date "$datefmt")"
231 # Look at which refs changed and trigger ref-change for these
232 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
233 bang_eval
"LC_ALL=C sort -k1b,1 <.refs-temp >.refs-after"
234 sockpath
="$cfg_chroot/etc/taskd.socket"
235 if ! cmp -s .refs-before .refs-after
; then
236 bang config_set lastreceive
"$(date '+%a, %d %b %Y %T %z')"
237 if [ -S "$sockpath" ]; then
238 join -j 1 .refs-before .refs-after |
239 while read ref old new
; do
240 [ "$old" != "$new" ] ||
continue
241 echo "ref-change %$proj% $proj $old $new $ref" | nc_openbsd
-w 1 -U "$sockpath"
243 join -j 1 -v 1 .refs-before .refs-after |
244 while read ref old
; do
245 echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | \
246 nc_openbsd
-w 1 -U "$sockpath"
248 join -j 1 -v 2 .refs-before .refs-after |
249 while read ref new
; do
250 echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | \
251 nc_openbsd
-w 1 -U "$sockpath"
254 bang config_set lastchange
"$(date '+%a, %d %b %Y %T %z')"
255 bang_eval
"git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
256 --count=1 refs/heads > info/lastactivity"
259 rm -f .refs-before .refs-after .refs-temp
261 if [ -e .banged
]; then
262 [ -z "$mailaddrs" ] ||
264 echo "$proj update succeeded - failure recovery"
265 echo "this status message may be disabled on the project admin page"
266 } |
mail -s "[$cfg_name] $proj update succeeded" "$mailaddrs" ||
:
267 rm -f .banged .bangagain
270 progress
"- [$proj] update (`date`)"