From 15db108e459ac0786fd60bc4ca3c3228aab8c3fb Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 12 Aug 2011 21:59:10 +0530 Subject: [PATCH] (new mirroring) helpers, hostname, detect use of older RC variables, delete mirror-sync --- conf/example.gitolite.rc | 1 + src/gitolite.pm | 46 ++++++++++++++++++++++++++++++++++++++++ src/gitolite_rc.pm | 6 ++++++ src/gl-mirror-sync | 38 --------------------------------- 4 files changed, 53 insertions(+), 38 deletions(-) delete mode 100755 src/gl-mirror-sync diff --git a/conf/example.gitolite.rc b/conf/example.gitolite.rc index 29272dc..b80d0ba 100644 --- a/conf/example.gitolite.rc +++ b/conf/example.gitolite.rc @@ -67,6 +67,7 @@ $SVNSERVE = ""; # PLEASE USE SINGLE QUOTES ABOVE, NOT DOUBLE QUOTES $GL_WILDREPOS_PERM_CATS = "READERS WRITERS"; # $GL_SITE_INFO = "XYZ.COM DEVELOPERS: PLEASE SEE http://xyz.com/gitolite/help first"; +# $GL_HOSTNAME = "frodo"; # read doc/mirroring.mkd COMPLETELY before setting this # ------------------------------------------------------------------------------ # rarely changed variables diff --git a/src/gitolite.pm b/src/gitolite.pm index 191cbfa..8345f32 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -22,11 +22,16 @@ use Exporter 'import'; setup_git_configs setup_gitweb_access shell_out + slurp special_cmd try_adc wrap_chdir wrap_open wrap_print + + mirror_mode + mirror_listslaves + mirror_redirectOK ); @EXPORT_OK = qw( %repos @@ -1182,6 +1187,47 @@ sub ext_cmd_svnserve die "svnserve exec failed\n"; } +# ---------------------------------------------------------------------------- +# MIRRORING HELPERS +# ---------------------------------------------------------------------------- + +sub mirror_mode { + my $repo = shift; + + # 'local' is the default if the config is empty or not set + my $gmm = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.master` || 'local'; + chomp $gmm; + return 'local' if $gmm eq 'local'; + return 'master' if $gmm eq ( $GL_HOSTNAME || '' ); + return "slave of $gmm"; +} + +sub mirror_listslaves { + my $repo = shift; + + return ( `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.slaves` || '' ); +} + +sub mirror_redirectOK { + my $repo = shift; + my $slave = shift || ''; + + my $gmrOK = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.redirectOK` || ''; + chomp $gmrOK; + my $slavelist = mirror_listslaves($repo); + + # if gmrOK is 'true', any valid slave can redirect + return 1 if $gmrOK eq 'true' and $slavelist =~ /(^|\s)$slave(\s|$)/; + # otherwise, gmrOK is a list of slaves who can redirect + return 1 if $gmrOK =~ /(^|\s)$slave(\s|$)/; + + return 0; + + # LATER/NEVER: include a call to an external program to override a 'true', + # based on, say, the time of day or network load etc. Cons: shelling out, + # deciding the name of the program (yet another rc var?) +} + # ------------------------------------------------------------------------------ # per perl rules, this should be the last line in such a file: 1; diff --git a/src/gitolite_rc.pm b/src/gitolite_rc.pm index f055f65..4316215 100644 --- a/src/gitolite_rc.pm +++ b/src/gitolite_rc.pm @@ -23,6 +23,7 @@ use Exporter 'import'; $GL_SLAVE_MODE $GL_WILDREPOS $GL_WILDREPOS_DEFPERMS $GL_WILDREPOS_PERM_CATS $HTPASSWD_FILE $PROJECTS_LIST $REPO_BASE $REPO_UMASK $RSYNC_BASE $SVNSERVE $UPDATE_CHAINS_TO $AUTH_OPTIONS + $GL_HOSTNAME $GL_HTTP_ANON_USER ); @@ -72,6 +73,11 @@ do $ENV{GL_RC} or die "error parsing $ENV{GL_RC}\n"; # fix up REPO_BASE $REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $REPO_BASE =~ m(^/); +# backward incompat detection for mirroring. Normally I wouldn't do +# this but this is *important* +die "$ABRT Mirroring has completely changed in this version.\tYou need to check the documentation for how to upgrade\n" + if (defined $GL_SLAVE_MODE or exists $ENV{GL_SLAVES}); + # ------------------------------------------------------------------------------ # per perl rules, this should be the last line in such a file: 1; diff --git a/src/gl-mirror-sync b/src/gl-mirror-sync deleted file mode 100755 index e946ec0..0000000 --- a/src/gl-mirror-sync +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -mirror=$1 -[ -z "$1" ] && { echo need \"user@host\" or ssh hostalias; exit 1; } -ssh -o PasswordAuthentication=no $mirror echo hello-there | grep hello-there >/dev/null || - { echo I cant ssh to $mirror; exit 1; } - -cd $HOME -REPO_BASE=`${0%/*}/gl-query-rc REPO_BASE` -cd $REPO_BASE - -ssh $mirror cat \$HOME/.gitolite.rc | expand | egrep '^ *\$GL_SLAVE_MODE *= *1; *$' >/dev/null || { - echo $mirror does not seem to be in slave mode - exit 1; -} - -find . -type d -name "*.git" -prune | cut -c3- | sort | while read r -do - cd $HOME; cd $REPO_BASE; cd $r - printf "$r " - - if [ `git rev-parse HEAD` = "HEAD" ] - then - echo is empty\; skipping - continue - fi - - # this is essentially the same code as in the post-receive hook - if git push --mirror $mirror:$r - then - : - else - ssh $mirror mkdir -p $r - ssh $mirror git init --bare $r - git push --mirror $mirror:$r || - echo "WARNING: mirror push to $mirror failed" - fi < /dev/null -done