]> git.donarmstrong.com Git - bin.git/blob - sa
output repository names
[bin.git] / sa
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Getopt::Long;
7 use Pod::Usage;
8
9 =head1 NAME
10
11 sa - sync all
12
13 =head1 SYNOPSIS
14
15 sa [options] [status|update|checkout] [directories to sync]
16
17  Options:
18   --quick, -Q don't update external projects
19   --quiet, -q be quiet
20   --debug, -d debugging level (Default 0)
21   --help, -h display this help
22   --man, -m display manual
23
24 =head1 OPTIONS
25
26 =over
27
28 =item B<--debug, -d>
29
30 Debug verbosity. (Default 0)
31
32 =item B<--help, -h>
33
34 Display brief useage information.
35
36 =item B<--man, -m>
37
38 Display this manual.
39
40 =back
41
42 =head1 EXAMPLES
43
44 =cut
45
46
47
48 use User;
49 use IO::File;
50 use vars qw($DEBUG);
51
52 my %options = (quick           => 1,
53                quiet           => 1,
54                debug           => 0,
55                help            => 0,
56                man             => 0,
57               );
58
59 GetOptions(\%options,'quick|Q+','quiet|q!','debug|d+','help|h|?','man|m');
60
61 pod2usage() if $options{help};
62 pod2usage({verbose=>2}) if $options{man};
63
64 # parse configuration file
65
66 =head1 CONFIGURATION
67
68 Reads configuration information from Start by parsing /etc/sa.conf,
69 then ~/.sarc then ~/.sarc_$hostname, then ~/.sarc_local
70
71 The configuration file contains a list of svn repositories which
72 should be queried; each line can contain a tab, which indicates that
73 the command following the tab should be run fater the svn directory is
74 updated.
75
76 The configuration files are read in the order given above.
77
78 =cut
79
80 sub parse_config_file {
81      my ($repos,$filename,$home) = @_;
82      return unless -e $filename and -r _;
83      my $fh = new IO::File $filename, 'r' or die "Unable to read configuration file $filename $!";
84      while (<$fh>) {
85           chomp;
86           next if /^#/;
87           my ($repo,$command) = split /\t/,$_,2;
88           $repo =~ s/^\~/$home/;
89           $$repos{$repo} = $command;
90      }
91 }
92
93
94 my $HOME=User->Home;
95 my $HOSTNAME=qx(hostname);
96 $HOSTNAME=~s/\n//g;
97 my $CAN_IGNORE_EXTERNALS = 0;
98 qx(svn --version) =~ /\(r(\d+)\)/;
99 if ($1 > 13838) {
100      $CAN_IGNORE_EXTERNALS = 1;
101 }
102
103 my %repos;
104 for ('/etc/sa.conf', "${HOME}/.sarc", "${HOME}/.sarc_${HOSTNAME}", "${HOME}/.sarc_local") {
105      if (-e $_) {
106           parse_config_file(\%repos,$_,$HOME);
107      }
108 }
109
110 $DEBUG = $options{debug};
111
112 my $command;
113
114 if (@ARGV and $ARGV[0] =~ /^(st(?:atus)?|up(?:date)?|checkout)$/) {
115      $command = $ARGV[0];
116 }
117 else {
118      $command = 'status';
119 }
120
121 while (my ($repo,$run_after) = each(%repos)) {
122      if (-e "$repo/.svn") {
123           print "Checking [$repo]\n";
124           system('svn',
125                  $command,
126                  $options{quiet}?'-q':(),
127                  ($options{quick} and $CAN_IGNORE_EXTERNALS)?'--ignore-externals':(),
128                  $options{quick}>1?'-N':(),
129                  $repo,
130                 );
131      }
132      if ($command =~ /^up(?:date)|checkout$/) {
133           system($run_after,$repo) if defined $run_after and length $run_after;
134      }
135 }