use User;
+use IO::File;
use vars qw($DEBUG);
-# XXX parse config file
-
my %options = (quick => 1,
- quiet => 0,
+ quiet => 1,
debug => 0,
help => 0,
man => 0,
);
-GetOptions(\%options,'debug|d+','help|h|?','man|m');
+GetOptions(\%options,'quick|Q+','quiet|q!','debug|d+','help|h|?','man|m');
pod2usage() if $options{help};
pod2usage({verbose=>2}) if $options{man};
+# parse configuration file
+
+=head1 CONFIGURATION
+
+Reads configuration information from Start by parsing /etc/sa.conf,
+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
+the command following the tab should be run after the svn directory is
+updated.
+
+The configuration files are read in the order given above.
+
+=cut
+
+sub parse_config_file {
+ my ($repos,$filename,$home) = @_;
+ return unless -e $filename and -r _;
+ my $fh = new IO::File $filename, 'r' or die "Unable to read configuration file $filename $!";
+ while (<$fh>) {
+ chomp;
+ 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 $HOSTNAME=qx(hostname);
+$HOSTNAME=~s/\n//g;
+my $CAN_IGNORE_EXTERNALS = 0;
+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 %repos;
+for ('/etc/sa.conf', available_config_files()) {
+ if (-e $_) {
+ parse_config_file(\%repos,$_,$HOME);
+ }
+}
+
$DEBUG = $options{debug};
my $command;
$command = 'status';
}
-my $HOME=User->Home;
-
-for my $dir (map{"${HOME}/$_"} '',qw(.hide bin lib)) {
- if (-e "$dir/.svn") {
- system('svn',$command,$dir);
+while (my ($repo,$run_after) = each(%repos)) {
+ if (-e "$repo/.svn") {
+ print "Checking [$repo]\n";
+ system('svn',
+ $command,
+ $options{quiet}?'-q':(),
+ ($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;
}
}