X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=blobdiff_plain;f=sa;h=acf37dff3827ffc7d70ba98c366fa8920d2e39c0;hp=74af5e506a4b65274ff5e88d8d7274f71ba00de7;hb=HEAD;hpb=805f95d2018c1432f3c1d951ef70458a1a759e05 diff --git a/sa b/sa index 74af5e5..acf37df 100755 --- a/sa +++ b/sa @@ -16,6 +16,7 @@ sa [options] [status|update|checkout] [directories to sync] Options: --quick, -Q don't update external projects + --verbose, -v be more verbose --quiet, -q be quiet --debug, -d debugging level (Default 0) --help, -h display this help @@ -45,18 +46,20 @@ Display this manual. -use User; +#use User; use IO::File; -use vars qw($DEBUG); +use vars qw($DEBUG $VERBOSE); my %options = (quick => 1, quiet => 1, debug => 0, help => 0, man => 0, + verbose => 0, + hooks_only => 0, ); -GetOptions(\%options,'quick|Q+','quiet|q!','debug|d+','help|h|?','man|m'); +GetOptions(\%options,'quick|Q+','quiet|q!','debug|d+','help|h|?','man|m','verbose|v+','hooks_only|hooks-only'); pod2usage() if $options{help}; pod2usage({verbose=>2}) if $options{man}; @@ -66,7 +69,7 @@ pod2usage({verbose=>2}) if $options{man}; =head1 CONFIGURATION Reads configuration information from Start by parsing /etc/sa.conf, -then the contents of ~/sa.d/ which match ^[\w\d][\w\d_-.]+$ +then the contents of ~/sa.d/ which match ^[\w\d][\w\d_.-]+$ The configuration file contains a list of svn repositories which should be queried; each line can contain a tab, which indicates that @@ -86,29 +89,25 @@ sub parse_config_file { next if /^#/; my ($repo,$command) = split /\t/,$_,2; $repo =~ s/^\~/$home/; - $command =~ s/^\~/$home/ if defined $command; $$repos{$repo} = $command; } } -my $HOME=User->Home; +my $HOME=$ENV{HOME}; my $HOSTNAME=qx(hostname); $HOSTNAME=~s/\n//g; my $CAN_IGNORE_EXTERNALS = 0; -qx(svn --version) =~ /\(r(\d+)\)/; -if ($1 > 13838) { - $CAN_IGNORE_EXTERNALS = 1; +if (not $options{hooks_only}) { + qx(svn --version) =~ /\(r(\d+)\)/; + if ($1 > 13838) { + $CAN_IGNORE_EXTERNALS = 1; + } } sub available_config_files{ - my $dir = new IO::Dir "$HOME/.sa.d/"; - my @conffiles; - my $file; - while (defined($file = $dir->read)) { - next unless $file =~ /^[\w\d][\w\d_-.]+$/; - push @conffiles,$file; - } - return @conffiles; + my $dir; + opendir($dir, "$HOME/.sa.d/") or return (); + return map {"$HOME/.sa.d/$_"} grep /^[\w\d][\w\d_.-]+$/, readdir $dir; } my %repos; @@ -119,6 +118,7 @@ for ('/etc/sa.conf', available_config_files()) { } $DEBUG = $options{debug}; +$VERBOSE = $options{verbose}; my $command; @@ -130,17 +130,18 @@ else { } while (my ($repo,$run_after) = each(%repos)) { - if (-e "$repo/.svn") { - print "Checking [$repo]\n"; + print "Checking [$repo]\n"; + if (-e "$repo/.svn" and not $options{hooks_only}) { system('svn', $command, - $options{quiet}?'-q':(), + (not $VERBOSE and $options{quiet})?'-q':(), + ($VERBOSE >= 2)?'-v':(), ($options{quick} and $CAN_IGNORE_EXTERNALS)?'--ignore-externals':(), $options{quick}>1?'-N':(), $repo, ); } - if ($command =~ /^up(?:date)|checkout$/) { - system($run_after,$repo) if defined $run_after and length $run_after; + if ($command =~ /^up(?:date)?|checkout$/) { + system('sh', '-c',"$run_after $repo") if defined $run_after and length $run_after; } }