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>&-
19 { _e1=0; "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" 3>&- || _e1=$?; echo $_e1 >&3; } | \
20 { _e2=0; git fast-import --force --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks 3>&- || _e2=$?; echo $_e2 >&3; }
24 [ "$_err1" = 0 -a "$_err2" = 0 ]
28 # bzr fast-export | git fast-import with error handling
33 { read -r _err1 ||
:; read -r _err2 ||
:; } <<-EOT
35 exec 4>&3 3>&1 1>&4 4>&-
36 { _e1=0; bzr fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" 3>&- || _e1=$?; echo $_e1 >&3; } | \
37 { _e2=0; git fast-import --force --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks 3>&- || _e2=$?; echo $_e2 >&3; }
41 [ "$_err1" = 0 -a "$_err2" = 0 ]
46 [ -n "$cfg_mirror" ] ||
{ echo "Mirroring is disabled" >&2; exit 0; }
47 trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
50 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
53 cd "$cfg_reporoot/$proj.git"
55 if check_interval lastrefresh
$cfg_min_mirror_interval; then
56 progress
"= [$proj] update skip (last at $(config_get lastrefresh))"
59 progress
"+ [$proj] update (`date`)"
65 url
="$(config_get baseurl)"
66 mail="$(config_get owner || :)"
67 statusok
="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
69 [ "$statusok" = "false" -o -z "$mail" ] || mailaddrs
="$mail"
70 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \
71 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
73 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
74 bang_eval
"sort -k1b,1 <.refs-temp >.refs-before"
77 svn
://* | svn
+http
://* | svn
+https
://*)
78 [ -n "$cfg_mirror_svn" ] ||
{ echo "Mirroring svn is disabled" >&2; exit 0; }
79 # Update the git svn url to match baseurl but be cognizant of any
80 # needed prefix changes. See the comments in taskd/clone.sh about
81 # why we need to put up with a prefix in the first place.
84 svnurlold
="$(config_get svnurl || :)"
85 if [ "$svnurl" != "$svnurlold" ]; then
86 # We better already have an svn-remote.svn.fetch setting
87 bang
test -n "$(git config --get-all svn-remote.svn.fetch || :)"
88 # the only way to truly know what the proper prefix is
89 # is to attempt a fresh git-svn init -s on the new url
90 rm -rf svn-new-url ||
:
91 # We require svn info to succeed on the URL otherwise it's
92 # simply not a valid URL and without using -s on the init it
93 # will not otherwise be tested until the fetch
94 bang
eval 'svn --non-interactive info "$svnurl" > /dev/null'
95 bang mkdir svn-new-url
96 GIT_DIR
=svn-new-url bang git init
--bare --quiet
97 # We initially use -s for the init which will possibly shorten
98 # the URL. However, the shortening can fail if a password is
99 # not required for the longer version but is for the shorter,
100 # so try again without -s if the -s version fails.
101 cmdstr
='git svn init --prefix= -s "$svnurl" < /dev/null > /dev/null 2>&1 || '
102 cmdstr
="$cmdstr"'git svn init --prefix= "$svnurl" < /dev/null > /dev/null 2>&1'
103 GIT_DIR
=svn-new-url bang
eval "$cmdstr"
104 gitsvnurl
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url || :)"
105 gitsvnfetch
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch || :)"
106 gitsvnprefixnew
="${gitsvnfetch%%:*}"
107 gitsvnsuffixnew
="${gitsvnprefixnew##*/}"
108 gitsvnprefixnew
="${gitsvnprefixnew%$gitsvnsuffixnew}"
109 rm -rf svn-new-url ||
:
110 # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to .
112 if [ "$gitsvnurl" != "$(git config --get svn-remote.svn.url || :)" ]; then
113 # The url has been changed.
114 # We must update the url and replace the prefix on all config items
115 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | head -1 || :)"
116 gitsvnprefixold
="${gitsvnfetch%%:*}"
117 gitsvnsuffixold
="${gitsvnprefixold##*/}"
118 gitsvnprefixold
="${gitsvnprefixold%$gitsvnsuffixold}"
119 git config
--remove-section 'svn-remote.svnnew' 2>/dev
/null ||
:
120 git config
'svn-remote.svnnew.url' "$gitsvnurl"
121 { git config
--get-regexp '^svn-remote\.svn\.' ||
:; } | \
122 { while read sname sval
; do
124 svn-remote.svn.fetch|svn-remote.svn.branches|svn-remote.svn.tags
)
125 sname
="${sname#svn-remote.svn.}"
126 sval
="${sval#$gitsvnprefixold}"
127 bang git config
--add "svn-remote.svnnew.$sname" "${gitsvnprefixnew}$sval"
130 bang git config
-f svn
/.metadata svn-remote.svn.reposRoot
"$gitsvnurl"
131 bang git config
--remove-section svn-remote.svn
132 bang git config
--rename-section svn-remote.svnnew svn-remote.svn
134 bang config_set svnurl
"$svnurl"
136 # remove any stale *.lock files greater than 1 hour old in case
137 # git-svn was killed on the last update because it took too long
138 find svn
-type f
-name '*.lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
139 GIT_DIR
=. bang git svn fetch
--quiet < /dev
/null
140 # git svn does not preserve group permissions in the svn subdirectory
141 chmod -R ug
+rw
,o
+r svn
142 # git svn also leaves behind ref turds that end with @nnn
143 # We get rid of them now
145 { while read sha1 ref
; do
147 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
148 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
149 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
150 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
151 git update-ref
-d "$ref"
156 [ -n "$cfg_mirror_darcs" ] ||
{ echo "Mirroring darcs is disabled" >&2; exit 0; }
157 httpurl
="http://${url#darcs://}"
158 # remove any stale lock files greater than 1 hour old in case
159 # darcs_fast_export was killed on the last update because it took too long
160 find *.darcs
-maxdepth 2 -type f
-name 'lock' -mmin +60 -print0 2>/dev
/null |
xargs -0 rm -f
161 bang git_darcs_fetch
"$httpurl"
164 [ -n "$cfg_mirror_bzr" ] ||
{ echo "Mirroring bzr is disabled" >&2; exit 0; }
165 bzrurl
="${url#bzr://}"
166 bang git_bzr_fetch
"$bzrurl"
169 [ "$url" = "$(git config --get remote.origin.url || :)" ] || bang config_set_raw remote.origin.url
"$url"
170 GIT_SSL_NO_VERIFY
=1 bang git remote update
171 GIT_SSL_NO_VERIFY
=1 bang git remote prune origin
175 # The objects subdirectories permissions must be updated now.
176 # In the case of a dumb http clone, the permissions will not be correct
177 # (missing group write) despite the core.sharedrepository=1 setting!
178 # The objects themselves seem to have the correct permissions.
179 # This problem appears to have been fixed in the most recent git versions.
181 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
182 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
184 bang git update-server-info
185 bang config_set lastrefresh
"$(date "$datefmt")"
187 # Look at which refs changed and trigger ref-change for these
188 bang_eval
"git for-each-ref --format '%(refname) %(objectname)' >.refs-temp"
189 bang_eval
"sort -k1b,1 <.refs-temp >.refs-after"
190 sockpath
="$cfg_chroot/etc/taskd.socket"
191 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after
; then
192 join -j 1 .refs-before .refs-after |
193 while read ref old new
; do
194 [ "$old" != "$new" ] ||
continue
195 echo "ref-change %$proj% $proj $old $new $ref" | nc_openbsd
-w 1 -U "$sockpath"
197 join -j 1 -v 1 .refs-before .refs-after |
198 while read ref old
; do
199 echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | nc_openbsd
-w 1 -U "$sockpath"
201 join -j 1 -v 2 .refs-before .refs-after |
202 while read ref new
; do
203 echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | nc_openbsd
-w 1 -U "$sockpath"
205 git config gitweb.lastchange
"$(date '+%a, %d %b %Y %T %z')"
206 git for-each-ref
--sort=-committerdate --format='%(committerdate:iso8601)' \
207 --count=1 refs
/heads
> info
/lastactivity
210 rm -f .refs-before .refs-after .refs-temp
212 if [ -e .banged
]; then
213 [ -z "$mailaddrs" ] ||
215 echo "$proj update succeeded - failure recovery"
216 echo "this status message may be disabled on the project admin page"
217 } |
mail -s "[$cfg_name] $proj update succeeded" "$mailaddrs" ||
:
221 progress
"- [$proj] update (`date`)"