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 tool to manage all your version control repos
9 B<mr> [options] checkout
11 B<mr> [options] update
13 B<mr> [options] status
15 B<mr> [options] commit [-m "message"]
17 B<mr> [options] record [-m "message"]
27 B<mr> [options] grep pattern
29 B<mr> [options] run command [param ...]
31 B<mr> [options] bootstrap url [directory]
33 B<mr> [options] register [repository]
35 B<mr> [options] config section ["parameter=[value]" ...]
37 B<mr> [options] action [params ...]
39 B<mr> [options] [online|offline]
41 B<mr> [options] remember action [params ...]
45 B<mr> is a tool to manage all your version control repos. It can checkout,
46 update, or perform other actions on a set of repositories as if they were
47 one combined repository. It supports any combination of subversion, git,
48 cvs, mercurial, bzr, darcs, fossil and veracity repositories, and support
49 for other version control systems can easily be added.
51 B<mr> cds into and operates on all registered repositories at or below your
52 working directory. Or, if you are in a subdirectory of a repository that
53 contains no other registered repositories, it will stay in that directory,
54 and work on only that repository,
56 B<mr> is configured by .mrconfig files, which list the repositories. It
57 starts by reading the .mrconfig file in your home directory, and this can
58 in turn chain load .mrconfig files from repositories. It also automatically
59 looks for a .mrconfig file in the current directory, or in one of its
62 These predefined commands should be fairly familiar to users of any version
67 =item checkout (or co)
69 Checks out any repositories that are not already checked out.
73 Updates each repository from its configured remote repository.
75 If a repository isn't checked out yet, it will first check it out.
79 Displays a status report for each repository, showing what
80 uncommitted changes are present in the repository. For distributed version
81 control systems, also shows unpushed local branches.
85 Commits changes to each repository. (By default, changes are pushed to the
86 remote repository too, when using distributed systems like git. If you
87 don't like this default, you can change it in your .mrconfig, or use record
90 The optional -m parameter allows specifying a commit message.
94 Records changes to the local repository, but does not push them to the
95 remote repository. Only supported for distributed version control systems.
97 The optional -m parameter allows specifying a commit message.
101 Fetches from each repository's remote repository, but does not
102 update the working copy. Only supported for some distributed version
107 Pushes committed local changes to the remote repository. A no-op for
108 centralized version control systems.
112 Show a diff of uncommitted changes.
120 Searches for a pattern in each repository using the grep subcommand. Uses
121 ack-grep on VCS that do not have their own.
123 =item run command [param ...]
125 Runs the specified command in each repository.
129 These commands are also available:
133 =item bootstrap url [directory]
135 Causes mr to download the url, and use it as a .mrconfig file to checkout
136 the repositories listed in it, into the specified directory.
138 To use scp to download, the url may have the form ssh://[user@]host:file
140 The directory will be created if it does not exist. If no directory is
141 specified, the current directory will be used.
143 If the .mrconfig file includes a repository named ".", that
144 is checked out into the top of the specified directory.
148 List the repositories that mr will act on.
152 Register an existing repository in a mrconfig file. By default, the
153 repository in the current directory is registered, or you can specify a
154 directory to register.
156 The mrconfig file that is modified is chosen by either the -c option, or by
157 looking for the closest known one at or in a parent of the current directory.
161 Adds, modifies, removes, or prints a value from a mrconfig file. The next
162 parameter is the name of the section the value is in. To add or modify
163 values, use one or more instances of "parameter=value". Use "parameter=" to
164 remove a parameter. Use just "parameter" to get the value of a parameter.
166 For example, to add (or edit) a repository in src/foo:
168 mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
170 To show the command that mr uses to update the repository in src/foo:
172 mr config src/foo update
174 To see the built-in library of shell functions contained in mr:
176 mr config DEFAULT lib
178 The mrconfig file that is used is chosen by either the -c option, or by
179 looking for the closest known one at or in a parent of the current directory.
183 Advises mr that it is in offline mode. Any commands that fail in
184 offline mode will be remembered, and retried when mr is told it's online.
188 Advices mr that it is in online mode again. Commands that failed while in
189 offline mode will be re-run.
193 Remember a command, to be run later when mr re-enters online mode. This
194 implicitly puts mr into offline mode. The command can be any regular mr
195 command. This is useful when you know that a command will fail due to being
196 offline, and so don't want to run it right now at all, but just remember
197 to run it when you go back online.
205 Actions can be abbreviated to any unambiguous substring, so
206 "mr st" is equivalent to "mr status", and "mr up" is equivalent to "mr
209 Additional parameters can be passed to most commands, and are passed on
210 unchanged to the underlying version control system. This is mostly useful
211 if the repositories mr will act on all use the same version control
220 =item --directory directory
222 Specifies the topmost directory that B<mr> should work in. The default is
223 the current working directory.
227 =item --config mrconfig
229 Use the specified mrconfig file. The default is to use both F<~/.mrconfig>
230 as well as look for a F<.mrconfig> file in the current directory, or in one
231 of its parent directories.
237 Force mr to act on repositories that would normally be skipped due to their
250 Be quiet. This suppresses mr's usual output, as well as any output from
251 commands that are run (including stderr output). If a command fails,
252 the output will be shown.
258 Accept untrusted SSL certificates when bootstrapping.
264 Expand the statistics line displayed at the end to include information
265 about exactly which repositories failed and were skipped, if any.
271 Interactive mode. If a repository fails to be processed, a subshell will be
272 started which you can use to resolve or investigate the problem. Exit the
273 subshell to continue the mr run.
277 =item --no-recurse [number]
279 If no number if specified, just operate on the repository for the current
280 directory, do not recurse into deeper repositories.
282 If a number is specified, will recurse into repositories at most that many
283 subdirectories deep. For example, with -n 2 it would recurse into ./src/foo,
284 but not ./src/packages/bar.
288 =item --jobs [number]
290 Run the specified number of jobs in parallel, or an unlimited number of jobs
291 with no number specified. This can greatly speed up operations such as updates.
292 It is not recommended for interactive operations.
294 Note that running more than 10 jobs at a time is likely to run afoul of
295 ssh connection limits. Running between 3 and 5 jobs at a time will yield
296 a good speedup in updates without loading the machine too much.
302 Trust all mrconfig files even if they are not listed in F<~/.mrtrust>.
309 This obsolete flag is ignored.
313 =head1 MRCONFIG FILES
315 Here is an example F<.mrconfig> file:
318 checkout = svn checkout svn://svn.example.com/src/trunk src
322 checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git &&
324 git checkout -b mybranch origin/master
326 The F<.mrconfig> file uses a variant of the INI file format. Lines
327 starting with "#" are comments. Values can be continued to the
328 following line by indenting the line with whitespace.
330 The C<DEFAULT> section allows setting default values for the sections that
333 The C<ALIAS> section allows adding aliases for actions. Each parameter
334 is an alias, and its value is the action to use.
336 All other sections add repositories. The section header specifies the
337 directory where the repository is located. This is relative to the directory
338 that contains the mrconfig file, but you can also choose to use absolute
339 paths. (Note that you can use environment variables in section names; they
340 will be passed through the shell for expansion. For example,
341 C<[$HOSTNAME]>, or C<[${HOSTNAME}foo]>).
343 Within a section, each parameter defines a shell command to run to handle a
344 given action. mr contains default handlers for "update", "status",
345 "commit", and other standard actions.
347 Normally you only need to specify what to do for "checkout". Here you
348 specify the command to run in order to create a checkout of the repository.
349 The command will be run in the parent directory, and must create the
350 repository's directory. So use C<git clone>, C<svn checkout>, C<bzr branch>
351 or C<bzr checkout> (for a bound branch), etc.
353 Note that these shell commands are run in a C<set -e> shell
354 environment, where any additional parameters you pass are available in
355 C<$@>. All commands other than "checkout" are run inside the repository,
356 though not necessarily at the top of it.
358 The C<MR_REPO> environment variable is set to the path to the top of the
359 repository. (For the "register" action, "MR_REPO" is instead set to the
360 basename of the directory that should be created when checking the
363 The C<MR_CONFIG> environment variable is set to the .mrconfig file
364 that defines the repo being acted on, or, if the repo is not yet in a config
365 file, the F<.mrconfig> file that should be modified to register the repo.
367 The C<MR_ACTION> environment variable is set to the command being run
368 (update, checkout, etc).
370 A few parameters have special meanings:
376 If the "skip" parameter is set and its command returns true, then B<mr>
377 will skip acting on that repository. The command is passed the action
380 Here are two examples. The first skips the repo unless
381 mr is run by joey. The second uses the hours_since function
382 (included in mr's built-in library) to skip updating the repo unless it's
383 been at least 12 hours since the last update.
387 skip = test `whoami` != joey
391 skip = [ "$1" = update ] && ! hours_since "$1" 12
393 Another way to use skip is for a lazy checkout. This makes mr skip
394 operating on a repo unless it already exists. To enable the
395 repo, you have to explicitly check it out (using "mr --force -d foo checkout").
403 The "order" parameter can be used to override the default ordering of
404 repositories. The default order value is 10. Use smaller values to make
405 repositories be processed earlier, and larger values to make repositories
408 Note that if a repository is located in a subdirectory of another
409 repository, ordering it to be processed earlier is not recommended.
413 If the "chain" parameter is set and its command returns true, then B<mr>
414 will try to load a F<.mrconfig> file from the root of the repository.
418 If the "include" parameter is set, its command is ran, and should output
419 additional mrconfig file content. The content is included as if it were
420 part of the including file.
422 Unlike all other parameters, this parameter does not need to be placed
425 B<mr> ships several libraries that can be included to add support for
426 additional version control type things (unison, git-svn, git-fake-bare,
427 git-subtree). To include them all, you could use:
429 include = cat /usr/share/mr/*
431 See the individual files for details.
435 If the "deleted" parameter is set and its command returns true, then
436 B<mr> will treat the repository as deleted. It won't ever actually delete
437 the repository, but it will warn if it sees the repository's directory.
438 This is useful when one mrconfig file is shared among multiple machines,
439 to keep track of and remember to delete old repositories.
443 The "lib" parameter can specify some shell code that will be run
444 before each command, this can be a useful way to define shell
445 functions for other commands to use.
447 Unlike most other parameters, this can be specified multiple times, in
448 which case the chunks of shell code are accumulatively concatenated
453 If the "fixups" parameter is set, its command is run whenever a repository
454 is checked out, or updated. This provides an easy way to do things
455 like permissions fixups, or other tweaks to the repository content,
456 whenever the repository is changed.
460 When looking for a command to run for a given action, mr first looks for
461 a parameter with the same name as the action. If that is not found, it
462 looks for a parameter named "VCS_action" (substituting in the name of the
463 version control system and the action).
465 Internally, mr has settings for "git_update", "svn_update", etc. To change
466 the action that is performed for a given version control system, you can
467 override these VCS specific actions. To add a new version control system,
468 you can just add VCS specific actions for it.
472 If a "pre_action" parameter is set, its command is run before mr performs the
473 specified action. Similarly, "post_action" parameters are run after mr
474 successfully performs the specified action. For example, "pre_commit" is
475 run before committing; "post_update" is run after updating.
479 Any parameter can be suffixed with C<_append>, to add an additional value
480 to the existing value of the parameter. In this way, actions
481 can be constructed accumulatively.
485 The name of the version control system is itself determined by
486 running each defined "VCS_test" action, until one succeeds.
490 =head1 UNTRUSTED MRCONFIG FILES
492 Since mrconfig files can contain arbitrary shell commands, they can do
493 anything. This flexibility is good, but it also allows a malicious mrconfig
494 file to delete your whole home directory. Such a file might be contained
495 inside a repository that your main F<~/.mrconfig> checks out. To
496 avoid worries about evil commands in a mrconfig file, mr defaults to
497 reading all mrconfig files other than the main F<~/.mrconfig> in untrusted
498 mode. In untrusted mode, mrconfig files are limited to running only known
499 safe commands (like "git clone") in a carefully checked manner.
501 To configure mr to trust other mrconfig files, list them in F<~/.mrtrust>.
502 One mrconfig file should be listed per line. Either the full pathname
503 should be listed, or the pathname can start with F<~/> to specify a file
504 relative to your home directory.
506 =head1 OFFLINE LOG FILE
508 The F<~/.mrlog> file contains commands that mr has remembered to run later,
509 due to being offline. You can delete or edit this file to remove commands,
510 or even to add other commands for 'mr online' to run. If the file is
511 present, mr assumes it is in offline mode.
515 mr can be extended to support things such as unison and git-svn. Some
516 files providing such extensions are available in F</usr/share/mr/>. See
517 the documentation in the files for details about using them.
521 mr returns nonzero if a command failed in any of the repositories.
525 Copyright 2007-2011 Joey Hess <joey@kitenet.net>
527 Licensed under the GNU GPL version 2 or higher.
529 http://kitenet.net/~joey/code/mr/
536 use Cwd qw(getcwd abs_path);
538 # things that can happen when mr runs a command
547 my $config_overridden=0;
558 my $directory=getcwd();
560 my $HOME_MR_CONFIG = "$ENV{HOME}/.mrconfig";
561 $ENV{MR_CONFIG}=find_mrconfig();
568 my (@ok, @failed, @skipped);
578 # Runs a shell command using a supplied function.
579 # The lib will be included in the shell command line, and any params
580 # will be available in the shell as $1, $2, etc.
583 my ($action, $topdir, $subdir, $command, $params, $runner) = @_;
585 # optimisation: avoid running the shell for true and false
586 if ($command =~ /^\s*true\s*$/) {
590 elsif ($command =~ /^\s*false\s*$/) {
595 my $quotedparams=join(" ", (map { shellquote($_) } @$params));
596 my $lib=exists $config{$topdir}{$subdir}{lib} ?
597 $config{$topdir}{$subdir}{lib}."\n" : "";
598 if ($verbose && (! defined $lastlib || $lastlib ne $lib)) {
599 print "mr library now: >>$lib<<\n";
602 my $shellcode="set -e;".$lib.
603 "my_sh(){ $command\n }; my_sh $quotedparams";
604 print "mr $action: running $action >>$command<<\n" if $verbose;
605 $runner->($shellcode);
612 if ($s =~ m/^perl:\s+(.*)/s) {
613 return $perl_cache{$1} if exists $perl_cache{$1};
614 my $sub=eval "sub {$1}";
615 if (! defined $sub) {
616 print STDERR "mr: bad perl code in $id: $@\n";
618 return $perl_cache{$1} = $sub;
625 my ($action, $dir, $topdir, $subdir) = @_;
627 if (exists $vcs{$dir}) {
633 foreach my $vcs_test (
635 length $a <=> length $b
638 } grep { /_test$/ } keys %{$config{$topdir}{$subdir}}) {
639 my ($vcs)=$vcs_test =~ /(.*)_test/;
640 my $p=perl($vcs_test, $config{$topdir}{$subdir}{$vcs_test});
645 $test="my_$vcs_test() {\n$config{$topdir}{$subdir}{$vcs_test}\n}\n".$test;
646 $test.="if my_$vcs_test; then echo $vcs; fi\n";
651 foreach my $vcs (keys %perltest) {
652 if ($perltest{$vcs}->()) {
657 push @vcs, split(/\n/,
658 runsh("vcs test", $topdir, $subdir, $test, [], sub {
664 print STDERR "mr $action: found multiple possible repository types (@vcs) for ".fulldir($topdir, $subdir)."\n";
668 return $vcs{$dir}=undef;
671 return $vcs{$dir}=$vcs[0];
676 my ($action, $dir, $topdir, $subdir, $is_checkout) = @_;
678 if (exists $config{$topdir}{$subdir}{$action}) {
679 return $config{$topdir}{$subdir}{$action};
686 my $vcs=vcs_test(@_);
689 exists $config{$topdir}{$subdir}{$vcs."_".$action}) {
690 return $config{$topdir}{$subdir}{$vcs."_".$action};
698 my ($topdir, $subdir) = @_;
699 return $subdir =~ /^\// ? $subdir : $topdir.$subdir;
703 my ($action, $dir, $topdir, $subdir, $force_checkout) = @_;
704 my $fulldir=fulldir($topdir, $subdir);
707 $ENV{MR_CONFIG}=$configfiles{$topdir};
708 my $is_checkout=($action eq 'checkout');
709 my $is_update=($action =~ /update/);
711 ($ENV{MR_REPO}=$dir) =~ s!/$!!;
712 $ENV{MR_ACTION}=$action;
714 foreach my $testname ("skip", "deleted") {
715 next if $force && $testname eq "skip";
717 my $testcommand=findcommand($testname, $dir, $topdir, $subdir, $is_checkout);
719 if (defined $testcommand) {
720 my $ret=runsh "$testname test", $topdir, $subdir,
721 $testcommand, [$action],
722 sub { system(shift()) };
724 if (($? & 127) == 2) {
725 print STDERR "mr $action: interrupted\n";
729 print STDERR "mr $action: $testname test received signal ".($? & 127)."\n";
733 if ($ret >> 8 == 0) {
734 if ($testname eq "deleted") {
736 print STDERR "mr error: $dir should be deleted yet still exists\n";
740 print "mr $action: skip $dir skipped\n" if $verbose;
748 if (! $force_checkout) {
750 print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
754 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
759 return action("checkout", $dir, $topdir, $subdir);
763 my $command=findcommand($action, $dir, $topdir, $subdir, $is_checkout);
765 if ($is_checkout && ! -d $dir) {
766 print "mr $action: creating parent directory $dir\n" if $verbose;
767 system("mkdir", "-p", $dir);
770 if (! $no_chdir && ! chdir($dir)) {
771 print STDERR "mr $action: failed to chdir to $dir: $!\n";
774 elsif (! defined $command) {
775 my $vcs=vcs_test(@_);
776 if (! defined $vcs) {
777 print STDERR "mr $action: unknown repository type and no defined $action command for $fulldir\n";
781 print STDERR "mr $action: no defined action for $vcs repository $fulldir, skipping\n";
788 $actionmsg="mr $action: $fulldir";
792 $s=~s/^\Q$fulldir\E\/?//;
793 $actionmsg="mr $action: $fulldir (in subdir $s)";
795 print "$actionmsg\n" unless $quiet;
797 my $hookret=hook("pre_$action", $topdir, $subdir);
798 return $hookret if $hookret != OK;
800 my $ret=runsh $action, $topdir, $subdir,
801 $command, \@ARGV, sub {
804 my $output = qx/$sh 2>&1/;
807 print "$actionmsg\n";
808 print STDERR $output;
817 if (($? & 127) == 2) {
818 print STDERR "mr $action: interrupted\n";
822 print STDERR "mr $action: received signal ".($? & 127)."\n";
825 print STDERR "mr $action: failed ($ret)\n" if $verbose;
826 if ($ret >> 8 != 0) {
827 print STDERR "mr $action: command failed\n";
828 if (-e "$ENV{HOME}/.mrlog" && $action ne 'remember') {
829 # recreate original command line to
830 # remember, and avoid recursing
832 @ARGV=('-n', $action, @orig);
833 action("remember", $dir, $topdir, $subdir);
838 print STDERR "mr $action: command died ($ret)\n";
843 if ($is_checkout && ! -d $dir) {
844 print STDERR "mr $action: $dir missing after checkout\n";;
848 my $ret=hook("post_$action", $topdir, $subdir);
849 return $ret if $ret != OK;
851 if ($is_checkout || $is_update) {
852 if ($is_checkout && ! $no_chdir) {
853 if (! chdir($checkout_dir)) {
854 print STDERR "mr $action: failed to chdir to $checkout_dir: $!\n";
858 my $ret=hook("fixups", $topdir, $subdir);
859 return $ret if $ret != OK;
868 my ($hook, $topdir, $subdir) = @_;
870 my $command=$config{$topdir}{$subdir}{$hook};
871 return OK unless defined $command;
872 my $ret=runsh $hook, $topdir, $subdir, $command, [], sub {
875 my $output = qx/$sh 2>&1/;
878 print STDERR $output;
887 if (($? & 127) == 2) {
888 print STDERR "mr $hook: interrupted\n";
892 print STDERR "mr $hook: received signal ".($? & 127)."\n";
903 # run actions on multiple repos, in parallel
913 while (@fhs or @repos) {
914 while ((!$jobs || $running < $jobs) && @repos) {
916 my $repo = shift @repos;
917 pipe(my $outfh, CHILD_STDOUT);
918 pipe(my $errfh, CHILD_STDERR);
920 unless ($pid = fork) {
921 die "mr $action: cannot fork: $!" unless defined $pid;
922 open(STDOUT, ">&CHILD_STDOUT") || die "mr $action cannot reopen stdout: $!";
923 open(STDERR, ">&CHILD_STDERR") || die "mr $action cannot reopen stderr: $!";
928 exit action($action, @$repo);
932 push @active, [$pid, $repo];
933 push @fhs, [$outfh, $errfh];
936 my ($rin, $rout) = ('','');
938 foreach my $fh (@fhs) {
939 next unless defined $fh;
940 vec($rin, fileno($fh->[0]), 1) = 1 if defined $fh->[0];
941 vec($rin, fileno($fh->[1]), 1) = 1 if defined $fh->[1];
943 $nfound = select($rout=$rin, undef, undef, 1);
944 foreach my $channel (0, 1) {
945 foreach my $i (0..$#fhs) {
946 next unless defined $fhs[$i];
947 my $fh = $fhs[$i][$channel];
948 next unless defined $fh;
949 if (vec($rout, fileno($fh), 1) == 1) {
951 if (sysread($fh, $r, 1024) == 0) {
953 $fhs[$i][$channel] = undef;
954 if (! defined $fhs[$i][0] &&
955 ! defined $fhs[$i][1]) {
956 waitpid($active[$i][0], 0);
957 print STDOUT $out[$i][0];
958 print STDERR $out[$i][1];
959 record($active[$i][1], $? >> 8);
961 splice(@active, $i, 1);
966 $out[$i][$channel] .= $r;
974 my $dir=shift()->[0];
979 print "\n" unless $quiet;
981 elsif ($ret == FAILED) {
983 chdir($dir) unless $no_chdir;
984 print STDERR "mr: Starting interactive shell. Exit shell to continue.\n";
985 system((getpwuid($<))[8], "-i");
988 print "\n" unless $quiet;
990 elsif ($ret == SKIPPED) {
993 elsif ($ret == ABORT) {
997 die "unknown exit status $ret";
1003 if (! @ok && ! @failed && ! @skipped) {
1004 die "mr $action: no repositories found to work on\n";
1006 print "mr $action: finished (".join("; ",
1007 showstat($#ok+1, "ok", "ok"),
1008 showstat($#failed+1, "failed", "failed"),
1009 showstat($#skipped+1, "skipped", "skipped"),
1010 ).")\n" unless $quiet;
1013 print "mr $action: (skipped: ".join(" ", @skipped).")\n" unless $quiet;
1016 print STDERR "mr $action: (failed: ".join(" ", @failed).")\n";
1026 return "$count ".($count > 1 ? $plural : $singular);
1031 # an ordered list of repos
1034 foreach my $topdir (sort keys %config) {
1035 foreach my $subdir (sort keys %{$config{$topdir}}) {
1039 order => $config{$topdir}{$subdir}{order},
1044 $a->{order} <=> $b->{order}
1046 $a->{topdir} cmp $b->{topdir}
1048 $a->{subdir} cmp $b->{subdir}
1054 my $topdir=$repo->{topdir};
1055 my $subdir=$repo->{subdir};
1056 my $ret=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
1061 # Figure out which repos to act on. Returns a list of array refs
1064 # [ "$full_repo_path/", "$mr_config_path/", $section_header ]
1067 foreach my $repo (repolist()) {
1068 my $topdir=$repo->{topdir};
1069 my $subdir=$repo->{subdir};
1071 next if $subdir eq 'DEFAULT';
1072 my $dir=repodir($repo);
1074 $dir.="/" unless $dir=~/\/$/;
1075 $d.="/" unless $d=~/\/$/;
1076 next if $dir ne $d && $dir !~ /^\Q$d\E/;
1077 if (defined $max_depth) {
1078 my @a=split('/', $dir);
1079 my @b=split('/', $d);
1080 do { } while (@a && @b && shift(@a) eq shift(@b));
1081 next if @a > $max_depth || @b > $max_depth;
1083 push @repos, [$dir, $topdir, $subdir];
1086 # fallback to find a leaf repo
1087 foreach my $repo (reverse repolist()) {
1088 my $topdir=$repo->{topdir};
1089 my $subdir=$repo->{subdir};
1091 next if $subdir eq 'DEFAULT';
1092 my $dir=repodir($repo);
1094 $dir.="/" unless $dir=~/\/$/;
1095 $d.="/" unless $d=~/\/$/;
1096 if ($d=~/^\Q$dir\E/) {
1097 push @repos, [$dir, $topdir, $subdir];
1119 sub is_trusted_config {
1120 my $config=shift; # must be abs_pathed already
1122 # We always trust ~/.mrconfig.
1123 return 1 if $config eq abs_path($HOME_MR_CONFIG);
1125 return 1 if $trust_all;
1127 my $trustfile=$ENV{HOME}."/.mrtrust";
1130 $trusted{$HOME_MR_CONFIG}=1;
1131 if (open (TRUST, "<", $trustfile)) {
1134 s/^~\//$ENV{HOME}\//;
1135 $trusted{abs_path($_)}=1;
1141 return $trusted{$config};
1145 sub is_trusted_repo {
1148 # Tightly limit what is allowed in a repo name.
1149 # No ../, no absolute paths, and no unusual filenames
1150 # that might try to escape to the shell.
1151 return $repo =~ /^[-_.+\/A-Za-z0-9]+$/ &&
1152 $repo !~ /\.\./ && $repo !~ /^\//;
1155 sub is_trusted_checkout {
1158 # To determine if the command is safe, compare it with the
1159 # *_trusted_checkout config settings. Those settings are
1160 # templates for allowed commands, so make sure that each word
1161 # of the command matches the corresponding word of the template.
1164 foreach my $word (split(' ', $command)) {
1166 if ($word=~/^'(.*)'$/) {
1169 elsif ($word=~/^"(.*)"$/) {
1176 foreach my $key (grep { /_trusted_checkout$/ }
1177 keys %{$config{''}{DEFAULT}}) {
1178 my @twords=split(' ', $config{''}{DEFAULT}{$key});
1179 next if @words > @twords;
1183 for (my $c=0; $c < @twords && $match; $c++) {
1184 if ($twords[$c] eq '$url') {
1185 # Match all the typical characters found in
1186 # urls, plus @ which svn can use. Note
1187 # that the "url" might also be a local
1190 defined $words[$c] &&
1191 $words[$c] =~ /^[-_.+:@\/A-Za-z0-9]+$/
1195 elsif ($twords[$c] eq '$repo') {
1196 # If a repo is not specified, assume it
1197 # will be the last path component of the
1198 # url, or something derived from it, and
1200 if (! defined $words[$c] && defined $url) {
1201 ($words[$c])=$url=~/\/([^\/]+)\/?$/;
1205 defined $words[$c] &&
1206 is_trusted_repo($words[$c])
1209 elsif (defined $words[$c] && $words[$c]=~/^($twords[$c])$/) {
1226 my $bootstrap_url=shift;
1232 if (ref $f eq 'GLOB') {
1238 my $absf=abs_path($f);
1239 if ($loaded{$absf}) {
1244 $trusted=is_trusted_config($absf);
1246 if (! defined $dir) {
1247 ($dir)=$f=~/^(.*\/)[^\/]+$/;
1248 if (! defined $dir) {
1253 $dir=abs_path($dir)."/";
1255 if (! exists $configfiles{$dir}) {
1256 $configfiles{$dir}=$f;
1259 # copy in defaults from first parent
1261 while ($parent=~s/^(.*\/)[^\/]+\/?$/$1/) {
1262 if ($parent eq '/') {
1265 if (exists $config{$parent} &&
1266 exists $config{$parent}{DEFAULT}) {
1267 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
1276 print "mr: loading config $f\n" if $verbose;
1277 open($in, "<", $f) || die "mr: open $f: $!\n";
1280 close $in unless ref $f eq 'GLOB';
1284 # Keep track of the current line in the config file;
1285 # when a file is included track the current line from the include.
1290 my $nextline = sub {
1302 my $lineerror = sub {
1304 if (defined $included) {
1305 die "mr: $msg at $f line $lineno, included line: $line\n";
1308 die "mr: $msg at $f line $lineno\n";
1311 my $trusterror = sub {
1314 if (defined $bootstrap_url) {
1315 die "mr: $msg in untrusted $bootstrap_url line $lineno\n".
1316 "(To trust this url, --trust-all can be used; but please use caution;\n".
1317 "this can allow arbitrary code execution!)\n";
1320 die "mr: $msg in untrusted $f line $lineno\n".
1321 "(To trust this file, list it in ~/.mrtrust.)\n";
1328 if (! $trusted && /[[:cntrl:]]/) {
1329 $trusterror->("illegal control character");
1332 next if /^\s*\#/ || /^\s*$/;
1333 if (/^\[([^\]]*)\]\s*$/) {
1337 if (! is_trusted_repo($section) ||
1338 $section eq 'ALIAS' ||
1339 $section eq 'DEFAULT') {
1340 $trusterror->("illegal section \"[$section]\"");
1343 $section=expandenv($section) if $trusted;
1344 if ($section ne 'ALIAS' &&
1345 ! exists $config{$dir}{$section} &&
1346 exists $config{$dir}{DEFAULT}) {
1348 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
1351 elsif (/^(\w+)\s*=\s*(.*)/) {
1356 while (@lines && $lines[0]=~/^\s(.+)/) {
1363 # Untrusted files can only contain a few
1364 # settings in specific known-safe formats.
1365 if ($parameter eq 'checkout') {
1366 if (! is_trusted_checkout($value)) {
1367 $trusterror->("illegal checkout command \"$value\"");
1370 elsif ($parameter eq 'order') {
1371 # not interpreted as a command, so
1374 elsif ($value eq 'true' || $value eq 'false') {
1375 # skip=true , deleted=true etc are
1379 $trusterror->("illegal setting \"$parameter=$value\"");
1383 if ($parameter eq "include") {
1384 print "mr: including output of \"$value\"\n" if $verbose;
1387 print STDERR "mr: include command exited nonzero ($?)\n";
1390 unshift @lines, @inc;
1394 if (! defined $section) {
1395 $lineerror->("parameter ($parameter) not in section");
1397 if ($section eq 'ALIAS') {
1398 $alias{$parameter}=$value;
1400 elsif ($parameter eq 'lib' or $parameter =~ s/_append$//) {
1401 $config{$dir}{$section}{$parameter}.="\n".$value."\n";
1404 $config{$dir}{$section}{$parameter}=$value;
1405 if ($parameter =~ /.*_(.*)/) {
1406 $knownactions{$1}=1;
1409 $knownactions{$parameter}=1;
1411 if ($parameter eq 'chain' &&
1412 length $dir && $section ne "DEFAULT") {
1413 my $chaindir="$section";
1414 if ($chaindir !~ m!^/!) {
1415 $chaindir=$dir.$chaindir;
1417 if (-e "$chaindir/.mrconfig") {
1418 my $ret=system($value);
1420 if (($? & 127) == 2) {
1421 print STDERR "mr: chain test interrupted\n";
1425 print STDERR "mr: chain test received signal ".($? & 127)."\n";
1429 push @toload, ["$chaindir/.mrconfig", $chaindir];
1436 $lineerror->("parse error");
1440 foreach my $c (@toload) {
1445 sub startingconfig {
1446 %alias=%config=%configfiles=%knownactions=%loaded=();
1447 my $datapos=tell(DATA);
1449 seek(DATA,$datapos,0); # rewind
1454 # the section to modify or add
1455 my $targetsection=shift;
1456 # fields to change in the section
1457 # To remove a field, set its value to "".
1458 my %changefields=@_;
1464 open(my $in, "<", $f) || die "mr: open $f: $!\n";
1469 my $formatfield=sub {
1471 my @value=split(/\n/, shift);
1473 return "$field = ".shift(@value)."\n".
1474 join("", map { "\t$_\n" } @value);
1478 while ($out[$#out] =~ /^\s*$/) {
1479 unshift @blanks, pop @out;
1481 foreach my $field (sort keys %changefields) {
1482 if (length $changefields{$field}) {
1483 push @out, "$field = $changefields{$field}\n";
1484 delete $changefields{$field};
1494 if (/^\s*\#/ || /^\s*$/) {
1497 elsif (/^\[([^\]]*)\]\s*$/) {
1498 if (defined $section &&
1499 $section eq $targetsection) {
1503 $section=expandenv($1);
1507 elsif (/^(\w+)\s*=\s(.*)/) {
1512 while (@lines && $lines[0]=~/^\s(.+)/) {
1518 if ($section eq $targetsection) {
1519 if (exists $changefields{$parameter}) {
1520 if (length $changefields{$parameter}) {
1521 $value=$changefields{$parameter};
1523 delete $changefields{$parameter};
1527 push @out, $formatfield->($parameter, $value);
1531 if (defined $section &&
1532 $section eq $targetsection) {
1535 elsif (%changefields) {
1536 push @out, "\n[$targetsection]\n";
1537 foreach my $field (sort keys %changefields) {
1538 if (length $changefields{$field}) {
1539 push @out, $formatfield->($field, $changefields{$field});
1544 open(my $out, ">", $f) || die "mr: write $f: $!\n";
1552 # actions that do not operate on all repos
1553 if ($action eq 'help') {
1556 elsif ($action eq 'config') {
1559 elsif ($action eq 'register') {
1562 elsif ($action eq 'bootstrap') {
1565 elsif ($action eq 'remember' ||
1566 $action eq 'offline' ||
1567 $action eq 'online') {
1568 my @repos=selectrepos;
1569 action($action, @{$repos[0]}) if @repos;
1573 if (!$jobs || $jobs > 1) {
1574 mrs($action, selectrepos());
1577 foreach my $repo (selectrepos()) {
1578 record($repo, action($action, @$repo));
1584 exec($config{''}{DEFAULT}{help}) || die "exec: $!";
1589 die "mr config: not enough parameters\n";
1592 if ($section=~/^\//) {
1593 # try to convert to a path relative to the config file
1594 my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
1595 $dir=abs_path($dir);
1596 $dir.="/" unless $dir=~/\/$/;
1597 if ($section=~/^\Q$dir\E(.*)/) {
1603 if (/^([^=]+)=(.*)$/) {
1604 $changefields{$1}=$2;
1608 foreach my $topdir (sort keys %config) {
1609 if (exists $config{$topdir}{$section} &&
1610 exists $config{$topdir}{$section}{$_}) {
1611 print $config{$topdir}{$section}{$_}."\n";
1613 last if $section eq 'DEFAULT';
1617 die "mr config: $section $_ not set\n";
1621 modifyconfig($ENV{MR_CONFIG}, $section, %changefields) if %changefields;
1626 if ($config_overridden) {
1627 # Find the directory that the specified config file is
1629 ($directory)=abs_path($ENV{MR_CONFIG})=~/^(.*\/)[^\/]+$/;
1632 # Find the closest known mrconfig file to the current
1634 $directory.="/" unless $directory=~/\/$/;
1636 foreach my $topdir (reverse sort keys %config) {
1637 next unless length $topdir;
1638 if ($directory=~/^\Q$topdir\E/) {
1639 $ENV{MR_CONFIG}=$configfiles{$topdir};
1645 if (! $foundconfig) {
1646 $directory=""; # no config file, use builtin
1650 my $subdir=shift @ARGV;
1651 if (! chdir($subdir)) {
1652 print STDERR "mr register: failed to chdir to $subdir: $!\n";
1656 $ENV{MR_REPO}=getcwd();
1657 my $command=findcommand("register", $ENV{MR_REPO}, $directory, 'DEFAULT', 0);
1658 if (! defined $command) {
1659 die "mr register: unknown repository type\n";
1662 $ENV{MR_REPO}=~s/.*\/(.*)/$1/;
1663 $command="set -e; ".$config{$directory}{DEFAULT}{lib}."\n".
1664 "my_action(){ $command\n }; my_action ".
1665 join(" ", map { s/\\/\\\\/g; s/"/\"/g; '"'.$_.'"' } @ARGV);
1666 print "mr register: running >>$command<<\n" if $verbose;
1667 exec($command) || die "exec: $!";
1671 my $url=shift @ARGV;
1672 my $dir=shift @ARGV || ".";
1674 if (! defined $url || ! length $url) {
1675 die "mr: bootstrap requires url\n";
1678 # Download the config file to a temporary location.
1679 eval q{use File::Temp};
1681 my $tmpconfig=File::Temp->new();
1683 if ($url =~ m!^ssh://(.*)!) {
1684 @downloader = ("scp", $1, $tmpconfig);
1687 @downloader = ("curl", "-A", "mr", "-L", "-s", $url, "-o", $tmpconfig);
1688 push(@downloader, "-k") if $insecure;
1690 my $status = system(@downloader);
1691 die "mr bootstrap: invalid SSL certificate for $url (consider -k)\n"
1692 if $downloader[0] eq 'curl' && $status >> 8 == 60;
1693 die "mr bootstrap: download of $url failed\n" if $status != 0;
1696 system("mkdir", "-p", $dir);
1698 chdir($dir) || die "chdir $dir: $!";
1700 # Special case to handle checkout of the "." repo, which
1701 # would normally be skipped.
1702 my $topdir=abs_path(".")."/";
1703 my @repo=($topdir, $topdir, ".");
1704 loadconfig($tmpconfig, $topdir, $url);
1705 record(\@repo, action("checkout", @repo, 1))
1706 if exists $config{$topdir}{"."}{"checkout"};
1708 if (-e ".mrconfig") {
1709 print STDERR "mr bootstrap: .mrconfig file already exists, not overwriting with $url\n";
1712 eval q{use File::Copy};
1714 move($tmpconfig, ".mrconfig") || die "rename: $!";
1717 # Reload the config file (in case we got a different version)
1718 # and checkout everything else.
1720 loadconfig(".mrconfig");
1721 dispatch("checkout");
1722 @skipped=grep { abs_path($_) ne abs_path($topdir) } @skipped;
1723 showstats("bootstrap");
1727 # alias expansion and command stemming
1730 if (exists $alias{$action}) {
1731 $action=$alias{$action};
1733 if (! exists $knownactions{$action}) {
1734 my @matches = grep { /^\Q$action\E/ }
1735 keys %knownactions, keys %alias;
1736 if (@matches == 1) {
1737 $action=$matches[0];
1739 elsif (@matches == 0) {
1740 die "mr: unknown action \"$action\" (known actions: ".
1741 join(", ", sort keys %knownactions).")\n";
1744 die "mr: ambiguous action \"$action\" (matches: ".
1745 join(", ", @matches).")\n";
1753 while (length $dir) {
1754 if (-e "$dir/.mrconfig") {
1755 return "$dir/.mrconfig";
1757 $dir=~s/\/[^\/]*$//;
1759 return $HOME_MR_CONFIG;
1764 Getopt::Long::Configure("bundling", "no_permute");
1765 my $result=GetOptions(
1766 "d|directory=s" => sub { $directory=abs_path($_[1]) },
1767 "c|config=s" => sub { $ENV{MR_CONFIG}=$_[1]; $config_overridden=1 },
1768 "p|path" => sub { }, # now default, ignore
1769 "f|force" => \$force,
1770 "v|verbose" => \$verbose,
1771 "q|quiet" => \$quiet,
1772 "s|stats" => \$stats,
1773 "k|insecure" => \$insecure,
1774 "i|interactive" => \$interactive,
1775 "n|no-recurse:i" => \$max_depth,
1776 "j|jobs:i" => \$jobs,
1777 "t|trust-all" => \$trust_all,
1779 if (! $result || @ARGV < 1) {
1780 die("Usage: mr [options] action [params ...]\n".
1781 "(Use mr help for man page.)\n");
1784 $ENV{MR_SWITCHES}="";
1785 foreach my $option (@saved) {
1786 last if $option eq $ARGV[0];
1787 $ENV{MR_SWITCHES}.="$option ";
1793 print STDERR "mr: interrupted\n";
1797 # This can happen if it's run in a directory that was removed
1798 # or other strangeness.
1799 if (! defined $directory) {
1800 die("mr: failed to determine working directory\n");
1802 # Make sure MR_CONFIG is an absolute path, but don't use abs_path since
1803 # the config file might be a symlink to elsewhere, and the directory it's
1804 # in is significant.
1805 if ($ENV{MR_CONFIG} !~ /^\//) {
1806 $ENV{MR_CONFIG}=getcwd()."/".$ENV{MR_CONFIG};
1808 # Try to set MR_PATH to the path to the program.
1810 use FindBin qw($Bin $Script);
1811 $ENV{MR_PATH}=$Bin."/".$Script;
1829 loadconfig($HOME_MR_CONFIG);
1830 loadconfig($ENV{MR_CONFIG});
1831 #use Data::Dumper; print Dumper(\%config);
1833 my $action=expandaction(shift @ARGV);
1840 # Finally, some useful actions that mr knows about by default.
1841 # These can be overridden in ~/.mrconfig.
1856 echo "mr (warning): $@" >&2
1862 if [ -z "$1" ] || [ -z "$2" ]; then
1863 error "mr: usage: hours_since action num"
1865 for dir in .git .svn .bzr CVS .hg _darcs _FOSSIL_; do
1866 if [ -e "$MR_REPO/$dir" ]; then
1867 flagfile="$MR_REPO/$dir/.mr_last$1"
1871 if [ -z "$flagfile" ]; then
1872 error "cannot determine flag filename"
1874 delta=`perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile"`
1875 if [ "$delta" -lt "$2" ]; then
1883 LANG=C bzr info | egrep -q '^Checkout'
1886 if [ -d "$MR_REPO" ]; then
1893 svn_test = perl: -d "$ENV{MR_REPO}/.svn"
1894 git_test = perl: -e "$ENV{MR_REPO}/.git"
1895 bzr_test = perl: -d "$ENV{MR_REPO}/.bzr"
1896 cvs_test = perl: -d "$ENV{MR_REPO}/CVS"
1897 hg_test = perl: -d "$ENV{MR_REPO}/.hg"
1898 darcs_test = perl: -d "$ENV{MR_REPO}/_darcs"
1899 fossil_test = perl: -f "$ENV{MR_REPO}/_FOSSIL_"
1900 git_bare_test = perl:
1901 -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
1902 -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
1903 `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get core.bare` =~ /true/
1905 -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
1906 -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
1907 `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get vcsh.vcsh` =~ /true/
1908 veracity_test = perl: -d "$ENV{MR_REPO}/.sgdrawer"
1910 svn_update = svn update "$@"
1911 git_update = git pull "$@"
1913 if is_bzr_checkout; then
1916 bzr merge --pull "$@"
1918 cvs_update = cvs -q update "$@"
1919 hg_update = hg pull "$@"; hg update "$@"
1920 darcs_update = darcs pull -a "$@"
1921 fossil_update = fossil pull "$@"
1922 vcsh_update = vcsh run "$MR_REPO" git pull "$@"
1923 veracity_update = vv pull "$@" && vv update "$@"
1925 git_fetch = git fetch --all --prune --tags
1926 git_svn_fetch = git svn fetch
1927 darcs_fetch = darcs fetch
1930 svn_status = svn status "$@"
1931 git_status = git status -s "$@" || true; git --no-pager log --branches --not --remotes --simplify-by-decoration --decorate --oneline || true
1932 bzr_status = bzr status --short "$@"; bzr missing
1933 cvs_status = cvs -q status | grep -E '^(File:.*Status:|\?)' | grep -v 'Status: Up-to-date'
1934 hg_status = hg status "$@"; hg summary --quiet | grep -v 'parent: 0:'
1935 darcs_status = darcs whatsnew -ls "$@" || true
1936 fossil_status = fossil changes "$@"
1937 vcsh_status = vcsh run "$MR_REPO" git -c status.relativePaths=false status -s "$@" || true
1938 veracity_status = vv status "$@"
1940 svn_commit = svn commit "$@"
1941 git_commit = git commit -a "$@" && git push --all
1943 if is_bzr_checkout; then
1946 bzr commit "$@" && bzr push
1948 cvs_commit = cvs commit "$@"
1949 hg_commit = hg commit "$@" && hg push
1950 darcs_commit = darcs record -a "$@" && darcs push -a
1951 fossil_commit = fossil commit "$@"
1952 vcsh_commit = vcsh run "$MR_REPO" git commit -a "$@" && vcsh run "$MR_REPO" git push --all
1953 veracity_commit = vv commit "$@" && vv push
1955 git_record = git commit -a "$@"
1957 if is_bzr_checkout; then
1958 bzr commit --local "$@"
1962 hg_record = hg commit "$@"
1963 darcs_record = darcs record -a "$@"
1964 fossil_record = fossil commit "$@"
1965 vcsh_record = vcsh run "$MR_REPO" git commit -a "$@"
1966 veracity_record = vv commit "$@"
1969 git_push = git push "$@"
1970 bzr_push = bzr push "$@"
1972 hg_push = hg push "$@"
1973 darcs_push = darcs push -a "$@"
1974 fossil_push = fossil push "$@"
1975 vcsh_push = vcsh run "$MR_REPO" git push "$@"
1976 veracity_push = vv push "$@"
1978 svn_diff = svn diff "$@"
1979 git_diff = git diff "$@"
1980 bzr_diff = bzr diff "$@"
1981 cvs_diff = cvs -q diff "$@"
1982 hg_diff = hg diff "$@"
1983 darcs_diff = darcs diff -u "$@"
1984 fossil_diff = fossil diff "$@"
1985 vcsh_diff = vcsh run "$MR_REPO" git diff "$@"
1986 veracity_diff = vv diff "$@"
1988 svn_log = svn log "$@"
1989 git_log = git log "$@"
1990 bzr_log = bzr log "$@"
1991 cvs_log = cvs log "$@"
1992 hg_log = hg log "$@"
1993 darcs_log = darcs changes "$@"
1994 git_bare_log = git log "$@"
1995 fossil_log = fossil timeline "$@"
1996 vcsh_log = vcsh run "$MR_REPO" git log "$@"
1997 veracity_log = vv log "$@"
1999 hg_grep = hg grep "$@"
2000 cvs_grep = ack-grep "$@"
2001 svn_grep = ack-grep "$@"
2002 git_svn_grep = git grep "$@"
2003 git_grep = git grep "$@"
2004 bzr_grep = ack-grep "$@"
2009 url=`LC_ALL=C svn info . | grep -i '^URL:' | cut -d ' ' -f 2`
2010 if [ -z "$url" ]; then
2011 error "cannot determine svn url"
2013 echo "Registering svn url: $url in $MR_CONFIG"
2014 mr -c "$MR_CONFIG" config "`pwd`" checkout="svn co '$url' '$MR_REPO'"
2016 url="`LC_ALL=C git config --get remote.origin.url`" || true
2017 if [ -z "$url" ]; then
2018 error "cannot determine git url"
2020 echo "Registering git url: $url in $MR_CONFIG"
2021 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone '$url' '$MR_REPO'"
2023 url="`LC_ALL=C bzr info . | egrep -i 'checkout of branch|parent branch' | awk '{print $NF}' | head -n 1`"
2024 if [ -z "$url" ]; then
2025 error "cannot determine bzr url"
2027 echo "Registering bzr url: $url in $MR_CONFIG"
2028 mr -c "$MR_CONFIG" config "`pwd`" checkout="bzr branch '$url' '$MR_REPO'"
2030 repo=`cat CVS/Repository`
2032 if [ -z "$root" ]; then
2033 error "cannot determine cvs root"
2035 echo "Registering cvs repository $repo at root $root"
2036 mr -c "$MR_CONFIG" config "`pwd`" checkout="cvs -d '$root' co -d '$MR_REPO' '$repo'"
2038 url=`hg showconfig paths.default`
2039 echo "Registering mercurial repo url: $url in $MR_CONFIG"
2040 mr -c "$MR_CONFIG" config "`pwd`" checkout="hg clone '$url' '$MR_REPO'"
2042 url=`cat _darcs/prefs/defaultrepo`
2043 echo "Registering darcs repository $url in $MR_CONFIG"
2044 mr -c "$MR_CONFIG" config "`pwd`" checkout="darcs get '$url' '$MR_REPO'"
2046 url="`LC_ALL=C GIT_CONFIG=config git config --get remote.origin.url`" || true
2047 if [ -z "$url" ]; then
2048 error "cannot determine git url"
2050 echo "Registering git url: $url in $MR_CONFIG"
2051 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone --bare '$url' '$MR_REPO'"
2053 url="`LC_ALL=C vcsh run "$MR_REPO" git config --get remote.origin.url`" || true
2054 if [ -z "$url" ]; then
2055 error "cannot determine git url"
2057 echo "Registering git url: $url in $MR_CONFIG"
2058 mr -c "$MR_CONFIG" config "`pwd`" checkout="vcsh clone '$url' '$MR_REPO'"
2060 url=`fossil remote-url`
2061 repo=`fossil info | grep repository | sed -e 's/repository:*.//g' -e 's/ //g'`
2062 echo "Registering fossil repository $url in $MR_CONFIG"
2063 mr -c "$MR_CONFIG" config "`pwd`" checkout="mkdir -p '$MR_REPO' && cd '$MR_REPO' && fossil open '$repo'"
2065 url=`vv config | grep sync_targets | sed -e 's/sync_targets:*.//g' -e 's/ //g'`
2066 repo=`vv repo info | grep repository | sed -e 's/Current repository:*.//g' -e 's/ //g'`
2067 echo "Registering veracity repository $url in $MR_CONFIG"
2068 mr -c "$MR_CONFIG" config "`pwd`" checkout="mkdir -p '$MR_REPO' && cd '$MR_REPO' && vv checkout '$repo'"
2070 svn_trusted_checkout = svn co $url $repo
2071 svn_alt_trusted_checkout = svn checkout $url $repo
2072 git_trusted_checkout = git clone $url $repo
2073 bzr_trusted_checkout = bzr checkout|clone|branch|get $url $repo
2075 hg_trusted_checkout = hg clone $url $repo
2076 darcs_trusted_checkout = darcs get $url $repo
2077 git_bare_trusted_checkout = git clone --bare $url $repo
2078 vcsh_trusted_checkout = vcsh run "$MR_REPO" git clone $url $repo
2079 # fossil: messy to do
2080 veracity_trusted_checkout = vv clone $url $repo
2086 SHOWMANFILE="man -f"
2095 if [ ! -e "$MR_PATH" ]; then
2096 error "cannot find program path"
2098 tmp=$(mktemp -t mr.XXXXXXXXXX) || error "mktemp failed"
2099 trap "rm -f $tmp" exit
2100 pod2man -c mr "$MR_PATH" > "$tmp" || error "pod2man failed"
2101 $SHOWMANFILE "$tmp" || error "man failed"
2107 if [ -s ~/.mrlog ]; then
2108 info "running offline commands"
2109 mv -f ~/.mrlog ~/.mrlog.old
2110 if ! sh -e ~/.mrlog.old; then
2111 error "offline command failed; left in ~/.mrlog.old"
2115 info "no offline commands to run"
2120 info "offline mode enabled"
2122 info "remembering command: 'mr $@'"
2123 command="mr -d '$(pwd)' $MR_SWITCHES"
2125 command="$command '$w'"
2127 if [ ! -e ~/.mrlog ] || ! grep -q -F "$command" ~/.mrlog; then
2128 echo "$command" >> ~/.mrlog
2131 ed = echo "A horse is a horse, of course, of course.."
2132 T = echo "I pity the fool."
2133 right = echo "Not found."
2135 # vim:sw=8:sts=0:ts=8:noet
2137 # indent-tabs-mode: t
2138 # cperl-indent-level: 8