All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 mr - a Multiple Repository management tool
9 B<mr> [options] checkout
11 B<mr> [options] update
13 B<mr> [options] status
15 B<mr> [options] commit [-m "message"]
21 B<mr> [options] action [params ...]
25 B<mr> is a Multiple Repository management tool. It allows you to register a
26 set of repositories in a .mrconfig file, and then checkout, update, or
27 perform other actions on the repositories as if they were one big
30 Any mix of revision control systems can be used with B<mr>, and you can
31 define arbitrary actions for commands like "update", "checkout", or "commit".
33 B<mr> cds into and operates on all registered repsitories at or below your
34 working directory. Or, if you are in a subdirectory of a repository that
35 contains no other registered repositories, it will stay in that directory,
36 and work on only that repository,
38 The predefined commands should be fairly familiar to users of any revision
43 =item checkout (or co)
45 Checks out any repositories that are not already checked out.
49 Updates each repository from its configured remote repository.
51 If a repository isn't checked out yet, it will first check it out.
55 Displays a status report for each repository, showing what
56 uncommitted changes are present in the repository.
60 Commits changes to each repository. (By default, changes are pushed to the
61 remote repository too, when using distributed systems like git.)
63 The optional -m parameter allows specifying a commit message.
67 Show a diff of uncommitted changes.
75 List the repositories that mr will act on.
83 Actions can be abbreviated to any unambiguous subsctring, so
84 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
87 Additional parameters can be passed to other commands than "commit", they
88 will be passed on unchanged to the underlying revision control system.
89 This is mostly useful if the repositories mr will act on all use the same
90 revision control system.
98 Specifies the topmost directory that B<mr> should work in. The default is
99 the current working directory.
103 Use the specified mrconfig file, instead of looking for one in your home
114 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
115 file in your home directory, and this can in turn chain load .mrconfig files
118 Here is an example .mrconfig file:
121 checkout = svn co svn://svn.example.com/src/trunk src
125 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
127 The .mrconfig file uses a variant of the INI file format. Lines starting with
128 "#" are comments. Lines ending with "\" are continued on to the next line.
130 The "DEFAULT" section allows setting default values for the sections that
133 The "ALIAS" section allows adding aliases for actions. Each parameter
134 is an alias, and its value is the action to use.
136 All other sections add repositories. The section header specifies the
137 directory where the repository is located. This is relative to the directory
138 that contains the mrconfig file, but you can also choose to use absolute
141 Within a section, each parameter defines a shell command to run to handle a
142 given action. mr contains default handlers for the "update", "status", and
143 "commit" actions, so normally you only need to specify what to do for
146 Note that these shell commands are run in a "set -e" shell
147 environment, where any additional parameters you pass are available in
148 "$@". The "checkout" command is run in the parent of the repository
149 directory, since the repository isn't checked out yet. All other commands
150 are run inside the repository, though not necessarily at the top of it.
151 The "MR_REPO" environment variable is set to the path to the top of the
154 A few parameters have special meanings:
160 If the "skip" parameter is set and its command returns nonzero, then B<mr>
161 will skip acting on that repository.
165 If the "chain" parameter is set and its command returns nonzero, then B<mr>
166 will try to load a .mrconfig file from the root of the repository. (You
167 should avoid chaining from repositories with untrusted committers.)
171 The "lib" parameter can specify some shell code that will be run before each
172 command, this can be a useful way to define shell functions for other commands
179 Copyright 2007 Joey Hess <joey@kitenet.net>
181 Licensed under the GNU GPL version 2 or higher.
183 http://kitenet.net/~joey/code/mr/
190 use Cwd qw(getcwd abs_path);
192 my $directory=getcwd();
193 my $config="$ENV{HOME}/.mrconfig";
199 Getopt::Long::Configure("no_permute");
200 my $result=GetOptions(
201 "d|directory=s" => sub { $directory=abs_path($_[1]) },
202 "c|config=s" => \$config,
203 "verbose" => \$verbose,
205 if (! $result || @ARGV < 1) {
206 die("Usage: mr [-d directory] action [params ...]\n".
207 "(Use mr help for man page.)\n");
214 #print Dumper(\%config);
217 use FindBin qw($Bin $Script);
218 $ENV{MR_PATH}=$Bin."/".$Script;
221 # alias expansion and command stemming
222 my $action=shift @ARGV;
223 if (exists $alias{$action}) {
224 $action=$alias{$action};
226 if (! exists $knownactions{$action}) {
227 my @matches = grep { /^\Q$action\E/ }
228 keys %knownactions, keys %alias;
232 elsif (@matches == 0) {
233 die "mr: unknown action \"$action\" (known actions: ".
234 join(", ", sort keys %knownactions).")\n";
237 die "mr: ambiguous action \"$action\" (matches: ".
238 join(", ", @matches).")\n";
242 if ($action eq 'help') {
243 exec($config{''}{DEFAULT}{help});
246 # work out what repos to act on
249 foreach my $topdir (sort keys %config) {
250 foreach my $subdir (sort keys %{$config{$topdir}}) {
251 next if $subdir eq 'DEFAULT';
252 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
254 $dir.="/" unless $dir=~/\/$/;
255 $d.="/" unless $d=~/\/$/;
256 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
257 push @repos, [$dir, $topdir, $subdir];
261 # fallback to find a leaf repo
262 LEAF: foreach my $topdir (reverse sort keys %config) {
263 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
264 next if $subdir eq 'DEFAULT';
265 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
267 $dir.="/" unless $dir=~/\/$/;
268 $d.="/" unless $d=~/\/$/;
269 if ($d=~/^\Q$dir\E/) {
270 push @repos, [$dir, $topdir, $subdir];
278 my (@failed, @successful, @skipped);
279 foreach my $repo (@repos) {
280 action($action, @$repo);
284 my ($action, $dir, $topdir, $subdir) = @_;
286 my $lib= exists $config{$topdir}{$subdir}{lib} ?
287 $config{$topdir}{$subdir}{lib} : "";
289 if ($action eq 'checkout') {
291 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
295 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
297 elsif ($action eq 'update') {
299 return action("checkout", $dir, $topdir, $subdir);
305 if (exists $config{$topdir}{$subdir}{skip}) {
306 my $test="set -e;".$lib.$config{$topdir}{$subdir}{skip};
307 print "mr $action: running skip test $test\n" if $verbose;
308 my $ret=system($test);
309 if ($ret >> 8 == 0) {
310 print "mr $action: $dir skipped per config file\n" if $verbose;
316 if (! $nochdir && ! chdir($dir)) {
317 print STDERR "mr $action: failed to chdir to $dir: $!\n";
320 elsif (! exists $config{$topdir}{$subdir}{$action}) {
321 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
326 print "mr $action: $dir\n";
329 print "mr $action: $dir (in subdir $directory)\n";
331 my $command="set -e; ".$lib.
332 "my_action(){ $config{$topdir}{$subdir}{$action} ; }; my_action ".
333 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
334 print STDERR "mr $action: running $command\n" if $verbose;
335 my $ret=system($command);
337 print STDERR "mr $action: failed ($ret)\n" if $verbose;
339 if ($ret >> 8 != 0) {
340 print STDERR "mr $action: command failed\n";
343 print STDERR "mr $action: command died ($ret)\n";
347 push @successful, $dir;
359 return "$count ".($count > 1 ? $plural : $singular);
363 if (! @successful && ! @failed && ! @skipped) {
364 die "mr $action: no repositories found to work on\n";
366 print "mr $action: finished (".join("; ",
367 showstat($#successful+1, "successful", "successful"),
368 showstat($#failed+1, "failed", "failed"),
369 showstat($#skipped+1, "skipped", "skipped"),
374 elsif (! @successful && @skipped) {
387 if (ref $f eq 'GLOB') {
392 # $f might be a symlink
393 my $absf=abs_path($f);
394 if ($loaded{$absf}) {
399 print "mr: loading config $f\n" if $verbose;
400 open($in, "<", $f) || die "mr: open $f: $!\n";
401 ($dir)=$f=~/^(.*\/)[^\/]+$/;
402 if (! defined $dir) {
405 $dir=abs_path($dir)."/";
407 # copy in defaults from first parent
409 while ($parent=~s/^(.*)\/[^\/]+\/?$/$1/) {
410 if (exists $config{$parent} &&
411 exists $config{$parent}{DEFAULT}) {
412 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
421 next if /^\s*\#/ || /^\s*$/;
422 if (/^\s*\[([^\]]*)\]\s*$/) {
425 elsif (/^\s*(\w+)\s*=\s*(.*)/) {
430 while ($value=~/(.*)\\$/) {
435 if (! defined $section) {
436 die "$f line $.: parameter ($parameter) not in section\n";
438 if ($section ne 'ALIAS' &&
439 ! exists $config{$dir}{$section} &&
440 exists $config{$dir}{DEFAULT}) {
442 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
444 if ($section eq 'ALIAS') {
445 $alias{$parameter}=$value;
447 elsif ($parameter eq 'lib') {
448 $config{$dir}{$section}{lib}.=$value." ; ";
451 $config{$dir}{$section}{$parameter}=$value;
452 $knownactions{$parameter}=1;
453 if ($parameter eq 'chain' &&
454 length $dir && $section ne "DEFAULT" &&
455 -e $dir.$section."/.mrconfig" &&
456 system($value) >> 8 == 0) {
457 push @toload, $dir.$section."/.mrconfig";
462 die "$f line $.: parse error\n";
472 # Finally, some useful actions that mr knows about by default.
473 # These can be overridden in ~/.mrconfig.
488 if [ -d "$MR_REPO"/.svn ]; then \
490 elif [ -d "$MR_REPO"/.git ]; then \
491 git pull origin master "$@"; \
492 elif [ -d "$MR_REPO"/.bzr ]; then \
494 elif [ -d "$MR_REPO"/CVS ]; then \
497 error "unknown repo type"; \
500 if [ -d "$MR_REPO"/.svn ]; then \
502 elif [ -d "$MR_REPO"/.git ]; then \
503 git status "$@" || true; \
504 elif [ -d "$MR_REPO"/.bzr ]; then \
506 elif [ -d "$MR_REPO"/CVS ]; then \
509 error "unknown repo type"; \
512 if [ -d "$MR_REPO"/.svn ]; then \
514 elif [ -d "$MR_REPO"/.git ]; then \
515 git commit -a "$@" && git push --all; \
516 elif [ -d "$MR_REPO"/.bzr ]; then \
517 bzr commit "$@" && bzr push; \
518 elif [ -d "$MR_REPO"/CVS ]; then \
521 error "unknown repo type"; \
524 if [ -d "$MR_REPO"/.svn ]; then \
526 elif [ -d "$MR_REPO"/.git ]; then \
528 elif [ -d "$MR_REPO"/.bzr ]; then \
530 elif [ -d "$MR_REPO"/CVS ]; then \
533 error "unknown repo type"; \
536 if [ -d "$MR_REPO"/.svn ]; then \
538 elif [ -d "$MR_REPO"/.git ]; then \
540 elif [ -d "$MR_REPO"/.bzr ]; then \
542 elif [ -d "$MR_REPO"/CVS ]; then \
545 error "unknown repo type"; \
550 if [ ! -e "$MR_PATH" ]; then \
551 error "cannot find program path";\
553 (pod2man -c mr "$MR_PATH" | man -l -) || \
554 error "pod2man or man failed"
556 ed = echo "A horse is a horse, of course, of course.."
557 T = echo "I pity the fool."