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] register [repository]
23 B<mr> [options] config section [parameter=[value] ...]
25 B<mr> [options] action [params ...]
29 B<mr> is a Multiple Repository management tool. It allows you to register a
30 set of repositories in a .mrconfig file, and then checkout, update, or
31 perform other actions on the repositories as if they were one big
34 Any mix of revision control systems can be used with B<mr>, and you can
35 define arbitrary actions for commands like "update", "checkout", or "commit".
37 B<mr> cds into and operates on all registered repsitories at or below your
38 working directory. Or, if you are in a subdirectory of a repository that
39 contains no other registered repositories, it will stay in that directory,
40 and work on only that repository,
42 The predefined commands should be fairly familiar to users of any revision
47 =item checkout (or co)
49 Checks out any repositories that are not already checked out.
53 Updates each repository from its configured remote repository.
55 If a repository isn't checked out yet, it will first check it out.
59 Displays a status report for each repository, showing what
60 uncommitted changes are present in the repository.
64 Commits changes to each repository. (By default, changes are pushed to the
65 remote repository too, when using distributed systems like git.)
67 The optional -m parameter allows specifying a commit message.
71 Show a diff of uncommitted changes.
79 List the repositories that mr will act on.
83 Register an existing repository in the mrconfig file. By default, the
84 epository in the current directory is registered, or you can specify a
85 directory to register.
89 Adds, modifies, removed, or prints a value from the mrconfig file. The next
90 parameter is the name of the section the value is in. To add or modify a
91 value, follow it by one or more instances of "parameter=value". Use
92 "parameter=" to remove a parameter. Use just "parameter" to get the value
95 For example, to add (or edit) a repository in src/foo:
97 mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
105 Actions can be abbreviated to any unambiguous subsctring, so
106 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
109 Additional parameters can be passed to most commands, and are passed on
110 unchanged to the underlying revision control system. This is mostly useful
111 if the repositories mr will act on all use the same revision control
120 Specifies the topmost directory that B<mr> should work in. The default is
121 the current working directory.
125 Use the specified mrconfig file, instead of looking for one in your home
136 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
137 file in your home directory, and this can in turn chain load .mrconfig files
140 Here is an example .mrconfig file:
143 checkout = svn co svn://svn.example.com/src/trunk src
147 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
149 The .mrconfig file uses a variant of the INI file format. Lines starting with
150 "#" are comments. Lines ending with "\" are continued on to the next line.
152 The "DEFAULT" section allows setting default values for the sections that
155 The "ALIAS" section allows adding aliases for actions. Each parameter
156 is an alias, and its value is the action to use.
158 All other sections add repositories. The section header specifies the
159 directory where the repository is located. This is relative to the directory
160 that contains the mrconfig file, but you can also choose to use absolute
163 Within a section, each parameter defines a shell command to run to handle a
164 given action. mr contains default handlers for the "update", "status", and
165 "commit" actions, so normally you only need to specify what to do for
168 Note that these shell commands are run in a "set -e" shell
169 environment, where any additional parameters you pass are available in
170 "$@". The "checkout" command is run in the parent of the repository
171 directory, since the repository isn't checked out yet. All other commands
172 are run inside the repository, though not necessarily at the top of it.
173 The "MR_REPO" environment variable is set to the path to the top of the
176 A few parameters have special meanings:
182 If the "skip" parameter is set and its command returns nonzero, then B<mr>
183 will skip acting on that repository. The command is passed the action
186 Here are two examples. The first skips the repo unless
187 mr is run by joey. The second uses the hours_since function
188 (included in mr's built-in library) to skip updating the repo unless it's
189 been at least 12 hours since the last update.
191 skip = test $(whoami) != joey
192 skip = [ "$1" = update ] && [ $(hours_since "$1") -lt 12 ]
196 If the "chain" parameter is set and its command returns nonzero, then B<mr>
197 will try to load a .mrconfig file from the root of the repository. (You
198 should avoid chaining from repositories with untrusted committers.)
202 If the "deleted" parameter is set and its command returns nonzero, then
203 B<mr> will treat the repository as deleted. It won't ever actually delete
204 the repository, but it will warn if it sees the repsoitory's directory.
205 This is useful when one mrconfig file is shared amoung multiple machines,
206 to keep track of and remember to delete old repositories.
210 The "lib" parameter can specify some shell code that will be run before each
211 command, this can be a useful way to define shell functions for other commands
218 Copyright 2007 Joey Hess <joey@kitenet.net>
220 Licensed under the GNU GPL version 2 or higher.
222 http://kitenet.net/~joey/code/mr/
229 use Cwd qw(getcwd abs_path);
231 my $directory=getcwd();
232 my $config="$ENV{HOME}/.mrconfig";
238 Getopt::Long::Configure("no_permute");
239 my $result=GetOptions(
240 "d|directory=s" => sub { $directory=abs_path($_[1]) },
241 "c|config=s" => \$config,
242 "verbose" => \$verbose,
244 if (! $result || @ARGV < 1) {
245 die("Usage: mr [-d directory] action [params ...]\n".
246 "(Use mr help for man page.)\n");
253 #print Dumper(\%config);
256 use FindBin qw($Bin $Script);
257 $ENV{MR_PATH}=$Bin."/".$Script;
260 # alias expansion and command stemming
261 my $action=shift @ARGV;
262 if (exists $alias{$action}) {
263 $action=$alias{$action};
265 if (! exists $knownactions{$action}) {
266 my @matches = grep { /^\Q$action\E/ }
267 keys %knownactions, keys %alias;
271 elsif (@matches == 0) {
272 die "mr: unknown action \"$action\" (known actions: ".
273 join(", ", sort keys %knownactions).")\n";
276 die "mr: ambiguous action \"$action\" (matches: ".
277 join(", ", @matches).")\n";
281 if ($action eq 'help') {
282 exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
284 elsif ($action eq 'config') {
286 die "mr config: not enough parameters\n";
289 if ($section=~/^\//) {
290 # try to convert to a path relative to $config's dir
291 my ($dir)=$config=~/^(.*\/)[^\/]+$/;
292 if ($section=~/^\Q$dir\E(.*)/) {
298 if (/^([^=]+)=(.*)$/) {
299 $changefields{$1}=$2;
302 foreach my $topdir (sort keys %config) {
303 if (exists $config{$topdir}{$section} &&
304 exists $config{$topdir}{$section}{$_}) {
305 print $config{$topdir}{$section}{$_}."\n";
310 modifyconfig($config, $section, %changefields) if %changefields;
313 elsif ($action eq 'register') {
314 my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
315 "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
316 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
317 print STDERR "mr $action: running >>$command<<\n" if $verbose;
318 exec($command) || die "exec: $!";
321 # work out what repos to act on
324 foreach my $topdir (sort keys %config) {
325 foreach my $subdir (sort keys %{$config{$topdir}}) {
326 next if $subdir eq 'DEFAULT';
327 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
329 $dir.="/" unless $dir=~/\/$/;
330 $d.="/" unless $d=~/\/$/;
331 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
332 push @repos, [$dir, $topdir, $subdir];
336 # fallback to find a leaf repo
337 LEAF: foreach my $topdir (reverse sort keys %config) {
338 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
339 next if $subdir eq 'DEFAULT';
340 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
342 $dir.="/" unless $dir=~/\/$/;
343 $d.="/" unless $d=~/\/$/;
344 if ($d=~/^\Q$dir\E/) {
345 push @repos, [$dir, $topdir, $subdir];
353 my (@failed, @successful, @skipped);
354 foreach my $repo (@repos) {
355 action($action, @$repo);
359 my ($action, $dir, $topdir, $subdir) = @_;
361 my $lib= exists $config{$topdir}{$subdir}{lib} ?
362 $config{$topdir}{$subdir}{lib}."\n" : "";
364 if (exists $config{$topdir}{$subdir}{deleted}) {
369 my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
370 print "mr $action: running deleted test >>$test<<\n" if $verbose;
371 my $ret=system($test);
372 if ($ret >> 8 == 0) {
373 print STDERR "mr error: $dir should be deleted yet still exists\n\n";
380 if ($action eq 'checkout') {
382 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
386 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
388 elsif ($action eq 'update') {
390 return action("checkout", $dir, $topdir, $subdir);
396 if (exists $config{$topdir}{$subdir}{skip}) {
397 my $test="set -e;".$lib.
398 "my_action(){ $config{$topdir}{$subdir}{skip}\n }; my_action '$action'";
399 print "mr $action: running skip test >>$test<<\n" if $verbose;
400 my $ret=system($test);
401 if ($ret >> 8 == 0) {
402 print "mr $action: $dir skipped per config file\n" if $verbose;
408 if (! $nochdir && ! chdir($dir)) {
409 print STDERR "mr $action: failed to chdir to $dir: $!\n";
412 elsif (! exists $config{$topdir}{$subdir}{$action}) {
413 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
418 print "mr $action: $topdir$subdir\n";
421 print "mr $action: $topdir$subdir (in subdir $directory)\n";
423 my $command="set -e; ".$lib.
424 "my_action(){ $config{$topdir}{$subdir}{$action}\n }; my_action ".
425 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
426 print STDERR "mr $action: running >>$command<<\n" if $verbose;
427 my $ret=system($command);
429 print STDERR "mr $action: failed ($ret)\n" if $verbose;
431 if ($ret >> 8 != 0) {
432 print STDERR "mr $action: command failed\n";
435 print STDERR "mr $action: command died ($ret)\n";
439 push @successful, $dir;
451 return "$count ".($count > 1 ? $plural : $singular);
455 if (! @successful && ! @failed && ! @skipped) {
456 die "mr $action: no repositories found to work on\n";
458 print "mr $action: finished (".join("; ",
459 showstat($#successful+1, "successful", "successful"),
460 showstat($#failed+1, "failed", "failed"),
461 showstat($#skipped+1, "skipped", "skipped"),
466 elsif (! @successful && @skipped) {
479 if (ref $f eq 'GLOB') {
488 my $absf=abs_path($f);
489 if ($loaded{$absf}) {
494 print "mr: loading config $f\n" if $verbose;
495 open($in, "<", $f) || die "mr: open $f: $!\n";
496 ($dir)=$f=~/^(.*\/)[^\/]+$/;
497 if (! defined $dir) {
500 $dir=abs_path($dir)."/";
502 # copy in defaults from first parent
504 while ($parent=~s/^(.*)\/[^\/]+\/?$/$1/) {
505 if (exists $config{$parent} &&
506 exists $config{$parent}{DEFAULT}) {
507 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
516 next if /^\s*\#/ || /^\s*$/;
517 if (/^\s*\[([^\]]*)\]\s*$/) {
520 elsif (/^\s*(\w+)\s*=\s*(.*)/) {
525 while ($value=~/(.*)\\$/s) {
526 $value=$1."\n".<$in>;
530 if (! defined $section) {
531 die "$f line $.: parameter ($parameter) not in section\n";
533 if ($section ne 'ALIAS' &&
534 ! exists $config{$dir}{$section} &&
535 exists $config{$dir}{DEFAULT}) {
537 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
539 if ($section eq 'ALIAS') {
540 $alias{$parameter}=$value;
542 elsif ($parameter eq 'lib') {
543 $config{$dir}{$section}{lib}.=$value."\n";
546 $config{$dir}{$section}{$parameter}=$value;
547 $knownactions{$parameter}=1;
548 if ($parameter eq 'chain' &&
549 length $dir && $section ne "DEFAULT" &&
550 -e $dir.$section."/.mrconfig" &&
551 system($value) >> 8 == 0) {
552 push @toload, $dir.$section."/.mrconfig";
557 die "$f line $.: parse error\n";
569 # the section to modify or add
570 my $targetsection=shift;
571 # fields to change in the section
572 # To remove a field, set its value to "".
579 open(my $in, "<", $f) || die "mr: open $f: $!\n";
586 while ($out[$#out] =~ /^\s*$/) {
587 unshift @blanks, pop @out;
589 foreach my $field (sort keys %changefields) {
590 if (length $changefields{$field}) {
591 push @out, "$field = $changefields{$field}\n";
601 if (/^\s*\#/ || /^\s*$/) {
604 elsif (/^\s*\[([^\]]*)\]\s*$/) {
605 if (defined $section &&
606 $section eq $targetsection) {
614 elsif (/^\s*(\w+)\s*=\s(.*)/) {
619 while ($value=~/(.*\\)$/s) {
620 $value=$1."\n".shift(@lines);
624 if ($section eq $targetsection) {
625 if (exists $changefields{$parameter}) {
626 if (length $changefields{$parameter}) {
627 $value=$changefields{$parameter};
629 delete $changefields{$parameter};
633 push @out, "$parameter = $value\n";
637 if (defined $section &&
638 $section eq $targetsection) {
641 elsif (%changefields) {
642 push @out, "\n[$targetsection]\n";
643 foreach my $field (sort keys %changefields) {
644 if (length $changefields{$field}) {
645 push @out, "$field = $changefields{$field}\n";
650 open(my $out, ">", $f) || die "mr: write $f: $!\n";
655 # Finally, some useful actions that mr knows about by default.
656 # These can be overridden in ~/.mrconfig.
670 for dir in .git .svn .bzr CVS; do \
671 if [ -e "$MR_REPO/$dir" ]; then \
672 flagfile="$MR_REPO/$dir/.mr_last$1" \
676 if [ -z "$flagfile" ]; then \
677 error "cannot determine flag filename" \
679 perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile" \
684 if [ -d "$MR_REPO"/.svn ]; then \
686 elif [ -d "$MR_REPO"/.git ]; then \
687 git pull origin master "$@" \
688 elif [ -d "$MR_REPO"/.bzr ]; then \
690 elif [ -d "$MR_REPO"/CVS ]; then \
693 error "unknown repo type" \
696 if [ -d "$MR_REPO"/.svn ]; then \
698 elif [ -d "$MR_REPO"/.git ]; then \
699 git status "$@" || true \
700 elif [ -d "$MR_REPO"/.bzr ]; then \
702 elif [ -d "$MR_REPO"/CVS ]; then \
705 error "unknown repo type" \
708 if [ -d "$MR_REPO"/.svn ]; then \
710 elif [ -d "$MR_REPO"/.git ]; then \
711 git commit -a "$@" && git push --all \
712 elif [ -d "$MR_REPO"/.bzr ]; then \
713 bzr commit "$@" && bzr push \
714 elif [ -d "$MR_REPO"/CVS ]; then \
717 error "unknown repo type" \
720 if [ -d "$MR_REPO"/.svn ]; then \
722 elif [ -d "$MR_REPO"/.git ]; then \
724 elif [ -d "$MR_REPO"/.bzr ]; then \
726 elif [ -d "$MR_REPO"/CVS ]; then \
729 error "unknown repo type" \
732 if [ -d "$MR_REPO"/.svn ]; then \
734 elif [ -d "$MR_REPO"/.git ]; then \
736 elif [ -d "$MR_REPO"/.bzr ]; then \
738 elif [ -d "$MR_REPO"/CVS ]; then \
741 error "unknown repo type" \
744 if [ -n "$1" ]; then \
747 basedir="$(basename $(pwd))" \
748 if [ -d .svn ]; then \
749 url=$(LANG=C svn info . | \
750 grep -i ^URL: | cut -d ' ' -f 2) \
751 if [ -z "$url" ]; then \
752 error "cannot determine svn url" \
754 echo "Registering svn url: $url" \
755 mr config "$(pwd)" checkout="svn co $url $basedir" \
756 elif [ -d .git ]; then \
757 url=$(LANG=C git-config --get remote.origin.url) \
758 if [ -z "$url" ]; then \
759 error "cannot determine git url" \
761 echo "Registering git url: $url" \
762 mr config "$(pwd)" checkout="git clone $url $basedir" \
763 elif [ -d .bzr ]; then \
764 url=$(cat .bzr/branch/parent) \
765 if [ -z "$url" ]; then \
766 error "cannot determine bzr url" \
768 echo "Registering bzr url: $url" \
769 mr config "$(pwd)" checkout="bzr clone $url $basedir" \
771 error "unable to register this repo type" \
776 if [ ! -e "$MR_PATH" ]; then \
777 error "cannot find program path" \
779 (pod2man -c mr "$MR_PATH" | man -l -) || \
780 error "pod2man or man failed"
782 ed = echo "A horse is a horse, of course, of course.."
783 T = echo "I pity the fool."