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