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
13 "$cfg_basedir"/bin
/darcs-fast-export
--export-marks=$
(pwd)/dfe-marks
--import-marks=$
(pwd)/dfe-marks
"$1" | \
14 git fast-import
--export-marks=$
(pwd)/gfi-marks
--import-marks=$
(pwd)/gfi-marks
15 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
19 # bzr fast-export | git fast-import with error handling
21 bzr fast-export
--export-marks=$
(pwd)/dfe-marks
--import-marks=$
(pwd)/dfe-marks
"$1" | \
22 git fast-import
--export-marks=$
(pwd)/gfi-marks
--import-marks=$
(pwd)/gfi-marks
23 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
27 trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
30 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
33 cd "$cfg_reporoot/$proj.git"
35 if check_interval lastrefresh
$cfg_min_mirror_interval; then
36 progress
"= [$proj] update skip (last at $(config_get lastrefresh))"
39 progress
"+ [$proj] update (`date`)"
45 url
="$(config_get baseurl)"
46 mail="$(config_get owner)"
47 statusok
="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
49 [ "$statusok" = "false" -o -z "$mail" ] || mailaddrs
="$mail"
50 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] ||
51 if [ -z "$mailaddrs" ]; then mailaddrs
="$cfg_admin"; else mailaddrs
="$mailaddrs,$cfg_admin"; fi
53 show_progress
=1 bang git for-each-ref
--format '%(refname) %(objectname)' |
sort -k1b,1 >.refs-before
56 svn
://* | svn
+http
://* | svn
+https
://*)
57 # Update the git svn url to match baseurl but be cognizant of any
58 # needed prefix changes. See the comments in taskd/clone.sh about
59 # why we need to put up with a prefix in the first place.
62 svnurlold
="$(config_get svnurl)"
63 if [ "$svnurl" != "$svnurlold" ]; then
64 # We better already have an svn-remote.svn.fetch setting
65 bang
test -n "$(git config --get-all svn-remote.svn.fetch || :)"
66 # the only way to truly know what the proper prefix is
67 # is to attempt a fresh git-svn init -s on the new url
68 rm -rf svn-new-url ||
:
69 bang mkdir svn-new-url
70 GIT_DIR
=svn-new-url bang git init
--bare --quiet
71 GIT_DIR
=svn-new-url bang git svn init
-s "$svnurl" > /dev
/null
2>&1
72 gitsvnurl
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url || :)"
73 gitsvnfetch
="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch || :)"
74 gitsvnprefixnew
="${gitsvnfetch%trunk:refs/remotes/trunk}"
75 rm -rf svn-new-url ||
:
76 # Using GIT_DIR= with bang leaves it set to svn-new-url, so reset it to .
78 if [ "$gitsvnurl" != "$(git config --get svn-remote.svn.url || :)" ]; then
79 # The url has been changed.
80 # We must update the url and replace the prefix on all config items
81 gitsvnfetch
="$(git config --get-all svn-remote.svn.fetch | head -1 || :)"
82 gitsvnprefixold
="${gitsvnfetch%%:*}"
83 gitsvnprefixold
="${gitsvnprefixold%/*}"
84 [ -z "$gitsvnprefixold" ] || gitsvnprefixold
="$gitsvnprefixold/"
85 git config
--remove-section 'svn-remote.svnnew' 2>/dev
/null ||
:
86 git config
'svn-remote.svnnew.url' "$gitsvnurl"
87 { git config
--get-regexp '^svn-remote\.svn\.' ||
:; } | \
88 { while read sname sval
; do
90 svn-remote.svn.fetch|svn-remote.svn.branches|svn-remote.svn.tags
)
91 sname
="${sname#svn-remote.svn.}"
92 sval
="${sval#$gitsvnprefixold}"
93 bang git config
--add "svn-remote.svnnew.$sname" "${gitsvnprefixnew}$sval"
96 bang git config
-f svn
/.metadata svn-remote.svn.reposRoot
"$gitsvnurl"
97 bang git config
--remove-section svn-remote.svn
98 bang git config
--rename-section svn-remote.svnnew svn-remote.svn
100 bang config_set svnurl
"$svnurl"
102 # remove any stale *.lock files greater than 1 hour old in case
103 # git-svn was killed on the last update because it took too long
104 find svn
-type f
-name '*.lock' -mmin +60 -print0 |
xargs -0 rm -f
105 GIT_DIR
=. bang git svn fetch
--quiet
106 # git svn does not preserve group permissions in the svn subdirectory
107 chmod -R ug
+rw
,o
+r svn
108 # git svn also leaves behind ref turds that end with @nnn
109 # We get rid of them now
111 { while read sha1 ref
; do
113 ?
*@
[1-9]|?
*@
[1-9][0-9]|?
*@
[1-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9]|\
114 ?
*@
[1-9][0-9][0-9][0-9][0-9]|?
*@
[1-9][0-9][0-9][0-9][0-9][0-9]|\
115 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|\
116 ?
*@
[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])
117 git update-ref
-d "$ref"
122 httpurl
="${url/darcs:\/\//http://}"
123 bang git_darcs_fetch
"$httpurl"
126 bzrurl
="${url#bzr://}"
127 bang git_bzr_fetch
"$bzrurl"
130 [ "$url" = "$(git config --get remote.origin.url || :)" ] || bang config_set_raw remote.origin.url
"$url"
131 GIT_SSL_NO_VERIFY
=1 bang git remote update
132 GIT_SSL_NO_VERIFY
=1 bang git remote prune origin
136 # The objects subdirectories permissions must be updated now.
137 # In the case of a dumb http clone, the permissions will not be correct
138 # (missing group write) despite the core.sharedrepository=1 setting!
139 # The objects themselves seem to have the correct permissions.
140 # This problem appears to have been fixed in the most recent git versions.
142 [ "$cfg_permission_control" != "Hooks" ] || perms
=go
+w
143 chmod $perms $
(find objects
-maxdepth 1 -type d
) 2>/dev
/null ||
:
145 bang git update-server-info
146 bang config_set lastrefresh
"$(date "$datefmt")"
148 # Look at which refs changed and trigger ref-change for these
149 show_progress
=1 bang git for-each-ref
--format '%(refname) %(objectname)' |
sort -k1b,1 >.refs-after
150 sockpath
="$cfg_chroot/etc/taskd.socket"
151 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after
; then
152 join -j 1 .refs-before .refs-after |
153 while read ref old new
; do
154 [ "$old" != "$new" ] ||
continue
155 echo "ref-change %$proj% $proj $old $new $ref" | nc.openbsd
-w 1 -U "$sockpath"
157 join -j 1 -v 1 .refs-before .refs-after |
158 while read ref old
; do
159 echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd
-w 1 -U "$sockpath"
161 join -j 1 -v 2 .refs-before .refs-after |
162 while read ref new
; do
163 echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd
-w 1 -U "$sockpath"
165 git config gitweb.lastchange
"$(date '+%a, %d %b %Y %T %z')"
166 git for-each-ref
--sort=-committerdate --format='%(committerdate:iso8601)' \
167 --count=1 refs
/heads
> info
/lastactivity
170 rm -f .refs-before .refs-after
172 if [ -e .banged
]; then
173 [ -z "$mailaddrs" ] ||
175 echo "$proj update succeeded - failure recovery"
176 echo "this status message may be disabled on the project admin page"
177 } |
mail -s "[$cfg_name] $proj update succeeded" "$mailaddrs"
181 progress
"- [$proj] update (`date`)"