From c4ada109aba074f2ae33162ad420cf703dea853a Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 19 Apr 2014 00:43:08 -0700 Subject: [PATCH] config: maintain a gitweb.lastreceive date Whenever the object store is modified, update the gitweb.lastreceive date. This information can be used to help avoid unnecessary gc runs. --- Girocco/Project.pm | 2 +- hooks/pre-receive | 14 ++++++++++++++ jobd/update.sh | 7 ++++--- taskd/clone.sh | 3 ++- toolbox/update-all-hooks.sh | 8 ++++++-- 5 files changed, 27 insertions(+), 7 deletions(-) create mode 100755 hooks/pre-receive diff --git a/Girocco/Project.pm b/Girocco/Project.pm index 4ed13ef..ff7c331 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -300,7 +300,7 @@ sub _hook_install { sub _hooks_install { my $self = shift; - foreach my $hook ('post-receive', 'update', 'post-update') { + foreach my $hook ('pre-receive', 'post-receive', 'update', 'post-update') { $self->_hook_install($hook); } } diff --git a/hooks/pre-receive b/hooks/pre-receive new file mode 100755 index 0000000..2950a2d --- /dev/null +++ b/hooks/pre-receive @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Keep track of the last time we modified the object store +# +# Beware, we MAY be running in a chroot! + +set -e + +git config gitweb.lastreceive "$(date '+%a, %d %b %Y %T %z')" + +# Read the incoming refs, but just ignore them +while read line; do + : +done diff --git a/jobd/update.sh b/jobd/update.sh index d9dc4d5..c0e283a 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -226,6 +226,7 @@ bang_eval "git for-each-ref --format '%(refname) %(objectname)' >.refs-temp" bang_eval "sort -k1b,1 <.refs-temp >.refs-after" sockpath="$cfg_chroot/etc/taskd.socket" if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then + bang config_set lastreceive "$(date '+%a, %d %b %Y %T %z')" join -j 1 .refs-before .refs-after | while read ref old new; do [ "$old" != "$new" ] || continue @@ -239,9 +240,9 @@ if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then while read ref new; do echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | nc_openbsd -w 1 -U "$sockpath" done - git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" - git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ - --count=1 refs/heads > info/lastactivity + bang config_set lastchange "$(date '+%a, %d %b %Y %T %z')" + bang_eval "git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ + --count=1 refs/heads > info/lastactivity" fi rm -f .refs-before .refs-after .refs-temp diff --git a/taskd/clone.sh b/taskd/clone.sh index 344a95c..993db74 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -214,7 +214,8 @@ perms=g+w [ "$cfg_permission_control" != "Hooks" ] || perms=go+w chmod $perms $(find objects -maxdepth 1 -type d) 2>/dev/null || : -# Initialize gitweb.lastchange and info/lastactivity +# Initialize gitweb.lastreceive, gitweb.lastchange and info/lastactivity +git config gitweb.lastreceive "$(date '+%a, %d %b %Y %T %z')" git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ --count=1 refs/heads > info/lastactivity diff --git a/toolbox/update-all-hooks.sh b/toolbox/update-all-hooks.sh index 4382dd0..20540bd 100755 --- a/toolbox/update-all-hooks.sh +++ b/toolbox/update-all-hooks.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Update all out-of-date hooks in all current projects +# Update all out-of-date hooks in all current projects and install missing ones set -e @@ -13,12 +13,16 @@ cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v _repo | \ while read proj; do projdir="$base/$proj.git" updates= - for hook in post-receive update post-update; do + for hook in pre-receive post-receive update post-update; do if [ -f "$projdir/hooks/$hook" ]; then if ! cmp -s "$hookbin/$hook" "$projdir/hooks/$hook"; then cat "$hookbin/$hook" > "$projdir/hooks/$hook" updates="$updates $hook" fi + elif [ -d "$projdir/hooks" -a ! -e "$projdir/hooks/$hook" ]; then + cat "$hookbin/$hook" > "$projdir/hooks/$hook" + chmod 0775 "$projdir/hooks/$hook" + updates="$updates +$hook" fi done [ -z "$updates" ] || echo "$proj:$updates" -- 2.11.4.GIT