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.
7 mr - a Multiple Repository management tool
11 B<mr> [options] checkout
13 B<mr> [options] update
15 B<mr> [options] status
17 B<mr> [options] commit [-m "message"]
19 B<mr> [options] record [-m "message"]
25 B<mr> [options] register [repository]
27 B<mr> [options] config section ["parameter=[value]" ...]
29 B<mr> [options] action [params ...]
31 B<mr> [options] [online|offline]
33 B<mr> [options] remember action [params ...]
37 B<mr> is a Multiple Repository management tool. It can checkout, update, or
38 perform other actions on a set of repositories as if they were one combined
39 repository. It supports any combination of subversion, git, cvs, mecurial,
40 bzr and darcs repositories, and support for other revision control systems can
43 B<mr> cds into and operates on all registered repositories at or below your
44 working directory. Or, if you are in a subdirectory of a repository that
45 contains no other registered repositories, it will stay in that directory,
46 and work on only that repository,
48 These predefined commands should be fairly familiar to users of any revision
53 =item checkout (or co)
55 Checks out any repositories that are not already checked out.
59 Updates each repository from its configured remote repository.
61 If a repository isn't checked out yet, it will first check it out.
65 Displays a status report for each repository, showing what
66 uncommitted changes are present in the repository.
70 Commits changes to each repository. (By default, changes are pushed to the
71 remote repository too, when using distributed systems like git. If you
72 don't like this default, you can change it in your .mrconfig, or use record
75 The optional -m parameter allows specifying a commit message.
79 Records changes to the local repository, but does not push them to the
80 remote repository. Only supported for distributed revision control systems.
82 The optional -m parameter allows specifying a commit message.
86 Pushes committed local changes to the remote repository. A no-op for
87 centralized revision control systems.
91 Show a diff of uncommitted changes.
99 These commands are also available:
105 List the repositories that mr will act on.
109 Register an existing repository in a mrconfig file. By default, the
110 repository in the current directory is registered, or you can specify a
111 directory to register.
113 The mrconfig file that is modified is chosen by either the -c option, or by
114 looking for the closest known one at or below the current directory.
118 Adds, modifies, removes, or prints a value from a mrconfig file. The next
119 parameter is the name of the section the value is in. To add or modify
120 values, use one or more instances of "parameter=value". Use "parameter=" to
121 remove a parameter. Use just "parameter" to get the value of a parameter.
123 For example, to add (or edit) a repository in src/foo:
125 mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
127 To show the command that mr uses to update the repository in src/foo:
129 mr config src/foo update
131 To see the built-in library of shell functions contained in mr:
133 mr config DEFAULT lib
135 The ~/.mrconfig file is used by default. To use a different config file,
140 Advises mr that it is in offline mode. Any commands that fail in
141 offline mode will be remembered, and retried when mr is told it's online.
145 Advices mr that it is in online mode again. Commands that failed while in
146 offline mode will be re-run.
150 Remember a command, to be run later when mr re-enters online mode. This
151 implicitly puts mr into offline mode. The command can be any regular mr
152 command. This is useful when you know that a command will fail due to being
153 offline, and so don't want to run it right now at all, but just remember
154 to run it when you go back online.
162 Actions can be abbreviated to any unambiguous substring, so
163 "mr st" is equivalent to "mr status", and "mr up" is equivalent to "mr
166 Additional parameters can be passed to most commands, and are passed on
167 unchanged to the underlying revision control system. This is mostly useful
168 if the repositories mr will act on all use the same revision control
177 Specifies the topmost directory that B<mr> should work in. The default is
178 the current working directory.
182 Use the specified mrconfig file. The default is B<~/.mrconfig>
194 Expand the statistics line displayed at the end to include information
195 about exactly which repositories failed and were skipped, if any.
199 Interactive mode. If a repository fails to be processed, a subshell will be
200 started which you can use to resolve or investigate the problem. Exit the
201 subshell to continue the mr run.
205 If no number if specified, just operate on the repository for the current
206 directory, do not recurse into deeper repositories.
208 If a number is specified, will recurse into repositories at most that many
209 subdirectories deep. For example, with -n 2 it would recurse into ./src/foo,
210 but not ./src/packages/bar.
214 Run the specified number of jobs in parallel, or an unlimited number of jobs
215 with no number specified. This can greatly speed up operations such as updates.
216 It is not recommended for interactive operations.
218 Note that running more than 10 jobs at a time is likely to run afoul of
219 ssh connection limits. Running between 3 and 5 jobs at a time will yeild
220 a good speedup in updates without loading the machine too much.
226 The ~/.mrlog file contains commands that mr has remembered to run later,
227 due to being offline. You can delete or edit this file to remove commands,
228 or even to add other commands for 'mr online' to run. If the file is
229 present, mr assumes it is in offline mode.
231 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
232 file in your home directory, and this can in turn chain load .mrconfig files
235 Here is an example .mrconfig file:
238 checkout = svn co svn://svn.example.com/src/trunk src
242 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git &&
244 git checkout -b mybranch origin/master
246 The .mrconfig file uses a variant of the INI file format. Lines starting with
247 "#" are comments. Values can be continued to the following line by
248 indenting the line with whitespace.
250 The "DEFAULT" section allows setting default values for the sections that
253 The "ALIAS" section allows adding aliases for actions. Each parameter
254 is an alias, and its value is the action to use.
256 All other sections add repositories. The section header specifies the
257 directory where the repository is located. This is relative to the directory
258 that contains the mrconfig file, but you can also choose to use absolute
259 paths. (Note that you can use environment variables in section names; they
260 will be passed through the shell for expansion. For example,
261 "[$HOSTNAME]", or "[${HOSTNAME}foo]")
263 Within a section, each parameter defines a shell command to run to handle a
264 given action. mr contains default handlers for "update", "status",
265 "commit", and other standard actions. Normally you only need to specify what
266 to do for "checkout".
268 Note that these shell commands are run in a "set -e" shell
269 environment, where any additional parameters you pass are available in
270 "$@". The "checkout" command is run in the parent of the repository
271 directory, since the repository isn't checked out yet. All other commands
272 are run inside the repository, though not necessarily at the top of it.
274 The "MR_REPO" environment variable is set to the path to the top of the
275 repository. (For the "register" action, "MR_REPO" is instead set to the
276 basename of the directory that should be created when checking the
279 The "MR_CONFIG" environment variable is set to the .mrconfig file
280 that defines the repo being acted on, or, if the repo is not yet in a config
281 file, the .mrconfig file that should be modified to register the repo.
283 A few parameters have special meanings:
289 If the "skip" parameter is set and its command returns true, then B<mr>
290 will skip acting on that repository. The command is passed the action
293 Here are two examples. The first skips the repo unless
294 mr is run by joey. The second uses the hours_since function
295 (included in mr's built-in library) to skip updating the repo unless it's
296 been at least 12 hours since the last update.
298 skip = test `whoami` != joey
299 skip = [ "$1" = update ] && ! hours_since "$1" 12
303 The "order" parameter can be used to override the default ordering of
304 repositories. The default order value is 10. Use smaller values to make
305 repositories be processed earlier, and larger values to make repositories
308 Note that if a repository is located in a subdirectory of another
309 repository, ordering it to be processed earlier is not recommended.
313 If the "chain" parameter is set and its command returns true, then B<mr>
314 will try to load a .mrconfig file from the root of the repository. (You
315 should avoid chaining from repositories with untrusted committers.)
319 If the "include" parameter is set, its command is ran, and should output
320 additional mrconfig file content. The content is included as if it were
321 part of the including file.
323 Unlike all other parameters, this parameter does not need to be placed
328 The "lib" parameter can specify some shell code that will be run before each
329 command, this can be a useful way to define shell functions for other commands
334 When looking for a command to run for a given action, mr first looks for
335 a parameter with the same name as the action. If that is not found, it
336 looks for a parameter named "rcs_action" (substituting in the name of the
337 revision control system and the action). The name of the revision control
338 system is itself determined by running each defined "rcs_test" action,
341 Internally, mr has settings for "git_update", "svn_update", etc. To change
342 the action that is performed for a given revision control system, you can
343 override these rcs specific actions. To add a new revision control system,
344 you can just add rcs specific actions for it.
348 Copyright 2007 Joey Hess <joey@kitenet.net>
350 Licensed under the GNU GPL version 2 or higher.
352 http://kitenet.net/~joey/code/mr/
361 use Cwd qw(getcwd abs_path);
363 # things that can happen when mr runs a command
372 my $config_overridden=0;
380 my $directory=getcwd();
381 $ENV{MR_CONFIG}="$ENV{HOME}/.mrconfig";
388 my (@ok, @failed, @skipped);
394 my ($action, $dir, $topdir, $subdir) = @_;
396 if (exists $rcs{$dir}) {
401 foreach my $rcs_test (
403 length $a <=> length $b
406 } grep { /_test$/ } keys %{$config{$topdir}{$subdir}}) {
407 my ($rcs)=$rcs_test=~/(.*)_test/;
408 $test="my_$rcs_test() {\n$config{$topdir}{$subdir}{$rcs_test}\n}\n".$test;
409 $test.="if my_$rcs_test; then echo $rcs; fi\n";
411 $test=$config{$topdir}{$subdir}{lib}."\n".$test
412 if exists $config{$topdir}{$subdir}{lib};
414 print "mr $action: running rcs test >>$test<<\n" if $verbose;
419 print STDERR "mr $action: found multiple possible repository types ($rcs) for $topdir$subdir\n";
423 return $rcs{$dir}=undef;
426 return $rcs{$dir}=$rcs;
430 sub findcommand { #{{{
431 my ($action, $dir, $topdir, $subdir, $is_checkout) = @_;
433 if (exists $config{$topdir}{$subdir}{$action}) {
434 return $config{$topdir}{$subdir}{$action};
441 my $rcs=rcs_test(@_);
444 exists $config{$topdir}{$subdir}{$rcs."_".$action}) {
445 return $config{$topdir}{$subdir}{$rcs."_".$action};
453 my ($action, $dir, $topdir, $subdir) = @_;
455 $ENV{MR_CONFIG}=$configfiles{$topdir};
456 my $lib=exists $config{$topdir}{$subdir}{lib} ?
457 $config{$topdir}{$subdir}{lib}."\n" : "";
458 my $is_checkout=($action eq 'checkout');
464 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
468 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
470 elsif ($action =~ /update/) {
472 return action("checkout", $dir, $topdir, $subdir);
476 my $skiptest=findcommand("skip", $dir, $topdir, $subdir, $is_checkout);
477 my $command=findcommand($action, $dir, $topdir, $subdir, $is_checkout);
479 if (defined $skiptest) {
480 my $test="set -e;".$lib.
481 "my_action(){ $skiptest\n }; my_action '$action'";
482 print "mr $action: running skip test >>$test<<\n" if $verbose;
483 my $ret=system($test);
485 if (($? & 127) == 2) {
486 print STDERR "mr $action: interrupted\n";
490 print STDERR "mr $action: skip test received signal ".($? & 127)."\n";
494 if ($ret >> 8 == 0) {
495 print "mr $action: $dir skipped per config file\n" if $verbose;
500 if ($is_checkout && ! -d $dir) {
501 print "mr $action: creating parent directory $dir\n" if $verbose;
502 system("mkdir", "-p", $dir);
505 if (! $no_chdir && ! chdir($dir)) {
506 print STDERR "mr $action: failed to chdir to $dir: $!\n";
509 elsif (! defined $command) {
510 my $rcs=rcs_test(@_);
511 if (! defined $rcs) {
512 print STDERR "mr $action: unknown repository type and no defined $action command for $topdir$subdir\n";
516 print STDERR "mr $action: no defined action for $rcs repository $topdir$subdir, skipping\n";
522 print "mr $action: $topdir$subdir\n" unless $quiet;
526 $s=~s/^\Q$topdir$subdir\E\/?//;
527 print "mr $action: $topdir$subdir (in subdir $s)\n" unless $quiet;
529 $command="set -e; ".$lib.
530 "my_action(){ $command\n }; my_action ".
531 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
532 print "mr $action: running >>$command<<\n" if $verbose;
533 my $ret=system($command);
535 if (($? & 127) == 2) {
536 print STDERR "mr $action: interrupted\n";
540 print STDERR "mr $action: received signal ".($? & 127)."\n";
543 print STDERR "mr $action: failed ($ret)\n" if $verbose;
544 if ($ret >> 8 != 0) {
545 print STDERR "mr $action: command failed\n";
546 if (-e "$ENV{HOME}/.mrlog" && $action ne 'remember') {
547 # recreate original command line to
548 # remember, and avoid recursing
550 @ARGV=('-n', $action, @orig);
551 action("remember", $dir, $topdir, $subdir);
556 print STDERR "mr $action: command died ($ret)\n";
561 if ($action eq 'checkout' && ! -d $dir) {
562 print STDERR "mr $action: $dir missing after checkout\n";;
571 # run actions on multiple repos, in parallel
581 while (@fhs or @repos) {
582 while ((!$jobs || $running < $jobs) && @repos) {
584 my $repo = shift @repos;
585 pipe(my $outfh, CHILD_STDOUT);
586 pipe(my $errfh, CHILD_STDERR);
588 unless ($pid = fork) {
589 die "mr $action: cannot fork: $!" unless defined $pid;
590 open(STDOUT, ">&CHILD_STDOUT") || die "mr $action cannot reopen stdout: $!";
591 open(STDERR, ">&CHILD_STDERR") || die "mr $action cannot reopen stderr: $!";
596 exit action($action, @$repo);
600 push @active, [$pid, $repo];
601 push @fhs, [$outfh, $errfh];
604 my ($rin, $rout) = ('','');
606 foreach my $fh (@fhs) {
607 next unless defined $fh;
608 vec($rin, fileno($fh->[0]), 1) = 1 if defined $fh->[0];
609 vec($rin, fileno($fh->[1]), 1) = 1 if defined $fh->[1];
611 $nfound = select($rout=$rin, undef, undef, 1);
612 foreach my $channel (0, 1) {
613 foreach my $i (0..$#fhs) {
614 next unless defined $fhs[$i];
615 my $fh = $fhs[$i][$channel];
616 next unless defined $fh;
617 if (vec($rout, fileno($fh), 1) == 1) {
619 if (sysread($fh, $r, 1024) == 0) {
621 $fhs[$i][$channel] = undef;
622 if (! defined $fhs[$i][0] &&
623 ! defined $fhs[$i][1]) {
624 waitpid($active[$i][0], 0);
625 print STDOUT $out[$i][0];
626 print STDERR $out[$i][1];
627 record($active[$i][1], $? >> 8);
629 splice(@active, $i, 1);
634 $out[$i][$channel] .= $r;
642 my $dir=shift()->[0];
649 elsif ($ret == FAILED) {
651 chdir($dir) unless $no_chdir;
652 print STDERR "mr: Starting interactive shell. Exit shell to continue.\n";
653 system((getpwuid($<))[8]);
658 elsif ($ret == SKIPPED) {
661 elsif ($ret == ABORT) {
665 die "unknown exit status $ret";
671 if (! @ok && ! @failed && ! @skipped) {
672 die "mr $action: no repositories found to work on\n";
674 print "mr $action: finished (".join("; ",
675 showstat($#ok+1, "ok", "ok"),
676 showstat($#failed+1, "failed", "failed"),
677 showstat($#skipped+1, "skipped", "skipped"),
678 ).")\n" unless $quiet;
681 print "mr $action: (skipped: ".join(" ", @skipped).")\n" unless $quiet;
684 print STDERR "mr $action: (failed: ".join(" ", @failed).")\n";
694 return "$count ".($count > 1 ? $plural : $singular);
699 # an ordered list of repos
702 foreach my $topdir (sort keys %config) {
703 foreach my $subdir (sort keys %{$config{$topdir}}) {
707 order => $config{$topdir}{$subdir}{order},
712 $a->{order} <=> $b->{order}
714 $a->{topdir} cmp $b->{topdir}
716 $a->{subdir} cmp $b->{subdir}
720 # figure out which repos to act on
721 sub selectrepos { #{{{
723 foreach my $repo (repolist()) {
724 my $topdir=$repo->{topdir};
725 my $subdir=$repo->{subdir};
727 next if $subdir eq 'DEFAULT';
728 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
730 $dir.="/" unless $dir=~/\/$/;
731 $d.="/" unless $d=~/\/$/;
732 next if $dir ne $d && $dir !~ /^\Q$d\E/;
733 if (defined $max_depth) {
734 my @a=split('/', $dir);
735 my @b=split('/', $d);
736 do { } while (@a && @b && shift(@a) eq shift(@b));
737 next if @a > $max_depth || @b > $max_depth;
739 push @repos, [$dir, $topdir, $subdir];
742 # fallback to find a leaf repo
743 foreach my $repo (reverse repolist()) {
744 my $topdir=$repo->{topdir};
745 my $subdir=$repo->{subdir};
747 next if $subdir eq 'DEFAULT';
748 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
750 $dir.="/" unless $dir=~/\/$/;
751 $d.="/" unless $d=~/\/$/;
752 if ($d=~/^\Q$dir\E/) {
753 push @repos, [$dir, $topdir, $subdir];
775 sub loadconfig { #{{{
782 if (ref $f eq 'GLOB') {
791 my $absf=abs_path($f);
792 if ($loaded{$absf}) {
797 ($dir)=$f=~/^(.*\/)[^\/]+$/;
798 if (! defined $dir) {
801 $dir=abs_path($dir)."/";
803 if (! exists $configfiles{$dir}) {
804 $configfiles{$dir}=$f;
807 # copy in defaults from first parent
809 while ($parent=~s/^(.*\/)[^\/]+\/?$/$1/) {
810 if ($parent eq '/') {
813 if (exists $config{$parent} &&
814 exists $config{$parent}{DEFAULT}) {
815 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
820 print "mr: loading config $f\n" if $verbose;
821 open($in, "<", $f) || die "mr: open $f: $!\n";
832 next if /^\s*\#/ || /^\s*$/;
833 if (/^\[([^\]]*)\]\s*$/) {
834 $section=expandenv($1);
836 elsif (/^(\w+)\s*=\s*(.*)/) {
841 while (@lines && $lines[0]=~/^\s(.+)/) {
848 if ($parameter eq "include") {
849 print "mr: including output of \"$value\"\n" if $verbose;
850 unshift @lines, `$value`;
852 print STDERR "mr: include command exited nonzero ($?)\n";
857 if (! defined $section) {
858 die "$f line $.: parameter ($parameter) not in section\n";
860 if ($section ne 'ALIAS' &&
861 ! exists $config{$dir}{$section} &&
862 exists $config{$dir}{DEFAULT}) {
864 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
866 if ($section eq 'ALIAS') {
867 $alias{$parameter}=$value;
869 elsif ($parameter eq 'lib') {
870 $config{$dir}{$section}{lib}.=$value."\n";
873 $config{$dir}{$section}{$parameter}=$value;
874 if ($parameter =~ /.*_(.*)/) {
878 $knownactions{$parameter}=1;
880 if ($parameter eq 'chain' &&
881 length $dir && $section ne "DEFAULT" &&
882 -e $dir.$section."/.mrconfig") {
883 my $ret=system($value);
885 if (($? & 127) == 2) {
886 print STDERR "mr: chain test interrupted\n";
890 print STDERR "mr: chain test received signal ".($? & 127)."\n";
894 push @toload, $dir.$section."/.mrconfig";
900 die "$f line $line: parse error\n";
909 sub modifyconfig { #{{{
911 # the section to modify or add
912 my $targetsection=shift;
913 # fields to change in the section
914 # To remove a field, set its value to "".
921 open(my $in, "<", $f) || die "mr: open $f: $!\n";
926 my $formatfield=sub {
928 my @value=split(/\n/, shift);
930 return "$field = ".shift(@value)."\n".
931 join("", map { "\t$_\n" } @value);
935 while ($out[$#out] =~ /^\s*$/) {
936 unshift @blanks, pop @out;
938 foreach my $field (sort keys %changefields) {
939 if (length $changefields{$field}) {
940 push @out, "$field = $changefields{$field}\n";
941 delete $changefields{$field};
951 if (/^\s*\#/ || /^\s*$/) {
954 elsif (/^\[([^\]]*)\]\s*$/) {
955 if (defined $section &&
956 $section eq $targetsection) {
960 $section=expandenv($1);
964 elsif (/^(\w+)\s*=\s(.*)/) {
969 while (@lines && $lines[0]=~/^\s(.+)/) {
975 if ($section eq $targetsection) {
976 if (exists $changefields{$parameter}) {
977 if (length $changefields{$parameter}) {
978 $value=$changefields{$parameter};
980 delete $changefields{$parameter};
984 push @out, $formatfield->($parameter, $value);
988 if (defined $section &&
989 $section eq $targetsection) {
992 elsif (%changefields) {
993 push @out, "\n[$targetsection]\n";
994 foreach my $field (sort keys %changefields) {
995 if (length $changefields{$field}) {
996 push @out, $formatfield->($field, $changefields{$field});
1001 open(my $out, ">", $f) || die "mr: write $f: $!\n";
1009 # actions that do not operate on all repos
1010 if ($action eq 'help') {
1013 elsif ($action eq 'config') {
1016 elsif ($action eq 'register') {
1019 elsif ($action eq 'remember' ||
1020 $action eq 'offline' ||
1021 $action eq 'online') {
1022 my @repos=selectrepos;
1023 action($action, @{$repos[0]}) if @repos;
1027 if (!$jobs || $jobs > 1) {
1028 mrs($action, selectrepos());
1031 foreach my $repo (selectrepos()) {
1032 record($repo, action($action, @$repo));
1038 exec($config{''}{DEFAULT}{help}) || die "exec: $!";
1043 die "mr config: not enough parameters\n";
1046 if ($section=~/^\//) {
1047 # try to convert to a path relative to the config file
1048 my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
1049 $dir=abs_path($dir);
1050 $dir.="/" unless $dir=~/\/$/;
1051 if ($section=~/^\Q$dir\E(.*)/) {
1057 if (/^([^=]+)=(.*)$/) {
1058 $changefields{$1}=$2;
1062 foreach my $topdir (sort keys %config) {
1063 if (exists $config{$topdir}{$section} &&
1064 exists $config{$topdir}{$section}{$_}) {
1065 print $config{$topdir}{$section}{$_}."\n";
1067 last if $section eq 'DEFAULT';
1071 die "mr config: $section $_ not set\n";
1075 modifyconfig($ENV{MR_CONFIG}, $section, %changefields) if %changefields;
1080 if ($config_overridden) {
1081 # Find the directory that the specified config file is
1083 ($directory)=abs_path($ENV{MR_CONFIG})=~/^(.*\/)[^\/]+$/;
1086 # Find the closest known mrconfig file to the current
1088 $directory.="/" unless $directory=~/\/$/;
1090 foreach my $topdir (reverse sort keys %config) {
1091 next unless length $topdir;
1092 if ($directory=~/^\Q$topdir\E/) {
1093 $ENV{MR_CONFIG}=$configfiles{$topdir};
1099 if (! $foundconfig) {
1100 $directory=""; # no config file, use builtin
1104 my $subdir=shift @ARGV;
1105 if (! chdir($subdir)) {
1106 print STDERR "mr register: failed to chdir to $subdir: $!\n";
1110 $ENV{MR_REPO}=getcwd();
1111 my $command=findcommand("register", $ENV{MR_REPO}, $directory, 'DEFAULT', 0);
1112 if (! defined $command) {
1113 die "mr register: unknown repository type\n";
1116 $ENV{MR_REPO}=~s/.*\/(.*)/$1/;
1117 $command="set -e; ".$config{$directory}{DEFAULT}{lib}."\n".
1118 "my_action(){ $command\n }; my_action ".
1119 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
1120 print "mr register: running >>$command<<\n" if $verbose;
1121 exec($command) || die "exec: $!";
1124 # alias expansion and command stemming
1125 sub expandaction { #{{{
1127 if (exists $alias{$action}) {
1128 $action=$alias{$action};
1130 if (! exists $knownactions{$action}) {
1131 my @matches = grep { /^\Q$action\E/ }
1132 keys %knownactions, keys %alias;
1133 if (@matches == 1) {
1134 $action=$matches[0];
1136 elsif (@matches == 0) {
1137 die "mr: unknown action \"$action\" (known actions: ".
1138 join(", ", sort keys %knownactions).")\n";
1141 die "mr: ambiguous action \"$action\" (matches: ".
1142 join(", ", @matches).")\n";
1150 Getopt::Long::Configure("bundling", "no_permute");
1151 my $result=GetOptions(
1152 "d|directory=s" => sub { $directory=abs_path($_[1]) },
1153 "c|config=s" => sub { $ENV{MR_CONFIG}=$_[1]; $config_overridden=1 },
1154 "v|verbose" => \$verbose,
1155 "q|quiet" => \$quiet,
1156 "s|stats" => \$stats,
1157 "i|interactive" => \$interactive,
1158 "n|no-recurse:i" => \$max_depth,
1159 "j|jobs:i" => \$jobs,
1161 if (! $result || @ARGV < 1) {
1162 die("Usage: mr [-d directory] action [params ...]\n".
1163 "(Use mr help for man page.)\n");
1166 $ENV{MR_SWITCHES}="";
1167 foreach my $option (@saved) {
1168 last if $option eq $ARGV[0];
1169 $ENV{MR_SWITCHES}.="$option ";
1175 print STDERR "mr: interrupted\n";
1179 # This can happen if it's run in a directory that was removed
1180 # or other strangeness.
1181 if (! defined $directory) {
1182 die("mr: failed to determine working directory\n");
1184 # Make sure MR_CONFIG is an absolute path, but don't use abs_path since
1185 # the config file might be a symlink to elsewhere, and the directory it's
1186 # in is significant.
1187 if ($ENV{MR_CONFIG} !~ /^\//) {
1188 $ENV{MR_CONFIG}=getcwd()."/".$ENV{MR_CONFIG};
1190 # Try to set MR_PATH to the path to the program.
1192 use FindBin qw($Bin $Script);
1193 $ENV{MR_PATH}=$Bin."/".$Script;
1202 loadconfig($ENV{MR_CONFIG});
1203 #use Data::Dumper; print Dumper(\%config);
1205 my $action=expandaction(shift @ARGV);
1212 elsif (! @ok && @skipped) {
1220 # Finally, some useful actions that mr knows about by default.
1221 # These can be overridden in ~/.mrconfig.
1237 echo "mr (warning): $@" >&2
1243 if [ -z "$1" ] || [ -z "$2" ]; then
1244 error "mr: usage: hours_since action num"
1246 for dir in .git .svn .bzr CVS .hg _darcs; do
1247 if [ -e "$MR_REPO/$dir" ]; then
1248 flagfile="$MR_REPO/$dir/.mr_last$1"
1252 if [ -z "$flagfile" ]; then
1253 error "cannot determine flag filename"
1255 delta=`perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile"`
1256 if [ "$delta" -lt "$2" ]; then
1264 svn_test = test -d "$MR_REPO"/.svn
1265 git_test = test -d "$MR_REPO"/.git
1266 bzr_test = test -d "$MR_REPO"/.bzr
1267 cvs_test = test -d "$MR_REPO"/CVS
1268 hg_test = test -d "$MR_REPO"/.hg
1269 darcs_test = test -d "$MR_REPO"/_darcs
1271 test -d "$MR_REPO"/refs/heads && test -d "$MR_REPO"/refs/tags &&
1272 test -d "$MR_REPO"/objects && test -f "$MR_REPO"/config &&
1273 test "`GIT_CONFIG="$MR_REPO"/config git config --get core.bare`" = true
1275 svn_update = svn update "$@"
1276 git_update = git pull "$@"
1277 bzr_update = bzr merge "$@"
1278 cvs_update = cvs update "$@"
1279 hg_update = hg pull "$@" && hg update "$@"
1280 darcs_update = darcs pull -a "$@"
1282 svn_status = svn status "$@"
1283 git_status = git status "$@" || true
1284 bzr_status = bzr status "$@"
1285 cvs_status = cvs status "$@"
1286 hg_status = hg status "$@"
1287 darcs_status = darcs whatsnew -ls "$@" || true
1289 svn_commit = svn commit "$@"
1290 git_commit = git commit -a "$@" && git push --all
1291 bzr_commit = bzr commit "$@" && bzr push
1292 cvs_commit = cvs commit "$@"
1293 hg_commit = hg commit -m "$@" && hg push
1294 darcs_commit = darcs record -a -m "$@" && darcs push -a
1296 git_record = git commit -a "$@"
1297 bzr_record = bzr commit "$@"
1298 hg_record = hg commit -m "$@"
1299 darcs_record = darcs record -a -m "$@"
1302 git_push = git push "$@"
1303 bzr_push = bzr push "$@"
1305 hg_push = hg push "$@"
1306 darcs_push = darcs push -a
1308 svn_diff = svn diff "$@"
1309 git_diff = git diff "$@"
1310 bzr_diff = bzr diff "$@"
1311 cvs_diff = cvs diff "$@"
1312 hg_diff = hg diff "$@"
1313 darcs_diff = darcs diff -u "$@"
1315 svn_log = svn log "$@"
1316 git_log = git log "$@"
1317 bzr_log = bzr log "$@"
1318 cvs_log = cvs log "$@"
1319 hg_log = hg log "$@"
1320 darcs_log = darcs changes "$@"
1321 git_bare_log = git log "$@"
1324 url=`LC_ALL=C svn info . | grep -i '^URL:' | cut -d ' ' -f 2`
1325 if [ -z "$url" ]; then
1326 error "cannot determine svn url"
1328 echo "Registering svn url: $url in $MR_CONFIG"
1329 mr -c "$MR_CONFIG" config "`pwd`" checkout="svn co '$url' '$MR_REPO'"
1331 url="`LC_ALL=C git config --get remote.origin.url`" || true
1332 if [ -z "$url" ]; then
1333 error "cannot determine git url"
1335 echo "Registering git url: $url in $MR_CONFIG"
1336 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone '$url' '$MR_REPO'"
1338 url="`LC_ALL=C bzr info . | egrep -i 'checkout of branch|parent branch' | awk '{print $NF}'`"
1339 if [ -z "$url" ]; then
1340 error "cannot determine bzr url"
1342 echo "Registering bzr url: $url in $MR_CONFIG"
1343 mr -c "$MR_CONFIG" config "`pwd`" checkout="bzr clone '$url' '$MR_REPO'"
1345 repo=`cat CVS/Repository`
1347 if [ -z "$root" ]; then
1348 error "cannot determine cvs root"
1350 echo "Registering cvs repository $repo at root $root"
1351 mr -c "$MR_CONFIG" config "`pwd`" checkout="cvs -d '$root' co -d '$MR_REPO' '$repo'"
1353 url=`hg showconfig paths.default`
1354 echo "Registering mercurial repo url: $url in $MR_CONFIG"
1355 mr -c "$MR_CONFIG" config "`pwd`" checkout="hg clone '$url' '$MR_REPO'"
1357 url=`cat _darcs/prefs/defaultrepo`
1358 echo "Registering darcs repository $url in $MR_CONFIG"
1359 mr -c "$MR_CONFIG" config "`pwd`" checkout="darcs get '$url' '$MR_REPO'"
1361 url="`LC_ALL=C GIT_CONFIG=config git config --get remote.origin.url`" || true
1362 if [ -z "$url" ]; then
1363 error "cannot determine git url"
1365 echo "Registering git url: $url in $MR_CONFIG"
1366 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone --bare '$url' '$MR_REPO'"
1369 if [ ! -e "$MR_PATH" ]; then
1370 error "cannot find program path"
1372 tmp=$(mktemp -t mr.XXXXXXXXXX) || error "mktemp failed"
1373 trap "rm -f $tmp" exit
1374 pod2man -c mr "$MR_PATH" > "$tmp" || error "pod2man failed"
1375 man -l "$tmp" || error "man failed"
1380 if [ -s ~/.mrlog ]; then
1381 info "running offline commands"
1382 mv -f ~/.mrlog ~/.mrlog.old
1383 if ! sh -e ~/.mrlog.old; then
1384 error "offline command failed; left in ~/.mrlog.old"
1388 info "no offline commands to run"
1392 info "offline mode enabled"
1394 info "remembering command: 'mr $@'"
1395 command="mr -d '$(pwd)' $MR_SWITCHES"
1397 command="$command '$w'"
1399 if [ ! -e ~/.mrlog ] || ! grep -q -F "$command" ~/.mrlog; then
1400 echo "$command" >> ~/.mrlog
1403 ed = echo "A horse is a horse, of course, of course.."
1404 T = echo "I pity the fool."
1405 right = echo "Not found."
1408 # vim:sw=8:sts=0:ts=8:noet