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