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 next if /^\s*\#/ || /^\s*$/;
1330 if (! $trusted && /[[:cntrl:]]/) {
1331 $trusterror->("illegal control character");
1334 if (/^\[([^\]]*)\]\s*$/) {
1338 if (! is_trusted_repo($section) ||
1339 $section eq 'ALIAS' ||
1340 $section eq 'DEFAULT') {
1341 $trusterror->("illegal section \"[$section]\"");
1344 $section=expandenv($section) if $trusted;
1345 if ($section ne 'ALIAS' &&
1346 ! exists $config{$dir}{$section} &&
1347 exists $config{$dir}{DEFAULT}) {
1349 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
1352 elsif (/^(\w+)\s*=\s*(.*)/) {
1357 while (@lines && $lines[0]=~/^\s(.+)/) {
1364 # Untrusted files can only contain a few
1365 # settings in specific known-safe formats.
1366 if ($parameter eq 'checkout') {
1367 if (! is_trusted_checkout($value)) {
1368 $trusterror->("illegal checkout command \"$value\"");
1371 elsif ($parameter eq 'order') {
1372 # not interpreted as a command, so
1375 elsif ($value eq 'true' || $value eq 'false') {
1376 # skip=true , deleted=true etc are
1380 $trusterror->("illegal setting \"$parameter=$value\"");
1384 if ($parameter eq "include") {
1385 print "mr: including output of \"$value\"\n" if $verbose;
1388 print STDERR "mr: include command exited nonzero ($?)\n";
1391 unshift @lines, @inc;
1395 if (! defined $section) {
1396 $lineerror->("parameter ($parameter) not in section");
1398 if ($section eq 'ALIAS') {
1399 $alias{$parameter}=$value;
1401 elsif ($parameter eq 'lib' or $parameter =~ s/_append$//) {
1402 $config{$dir}{$section}{$parameter}.="\n".$value."\n";
1405 $config{$dir}{$section}{$parameter}=$value;
1406 if ($parameter =~ /.*_(.*)/) {
1407 $knownactions{$1}=1;
1410 $knownactions{$parameter}=1;
1412 if ($parameter eq 'chain' &&
1413 length $dir && $section ne "DEFAULT") {
1414 my $chaindir="$section";
1415 if ($chaindir !~ m!^/!) {
1416 $chaindir=$dir.$chaindir;
1418 if (-e "$chaindir/.mrconfig") {
1419 my $ret=system($value);
1421 if (($? & 127) == 2) {
1422 print STDERR "mr: chain test interrupted\n";
1426 print STDERR "mr: chain test received signal ".($? & 127)."\n";
1430 push @toload, ["$chaindir/.mrconfig", $chaindir];
1437 $lineerror->("parse error");
1441 foreach my $c (@toload) {
1446 sub startingconfig {
1447 %alias=%config=%configfiles=%knownactions=%loaded=();
1448 my $datapos=tell(DATA);
1450 seek(DATA,$datapos,0); # rewind
1455 # the section to modify or add
1456 my $targetsection=shift;
1457 # fields to change in the section
1458 # To remove a field, set its value to "".
1459 my %changefields=@_;
1465 open(my $in, "<", $f) || die "mr: open $f: $!\n";
1470 my $formatfield=sub {
1472 my @value=split(/\n/, shift);
1474 return "$field = ".shift(@value)."\n".
1475 join("", map { "\t$_\n" } @value);
1479 while ($out[$#out] =~ /^\s*$/) {
1480 unshift @blanks, pop @out;
1482 foreach my $field (sort keys %changefields) {
1483 if (length $changefields{$field}) {
1484 push @out, "$field = $changefields{$field}\n";
1485 delete $changefields{$field};
1495 if (/^\s*\#/ || /^\s*$/) {
1498 elsif (/^\[([^\]]*)\]\s*$/) {
1499 if (defined $section &&
1500 $section eq $targetsection) {
1504 $section=expandenv($1);
1508 elsif (/^(\w+)\s*=\s(.*)/) {
1513 while (@lines && $lines[0]=~/^\s(.+)/) {
1519 if ($section eq $targetsection) {
1520 if (exists $changefields{$parameter}) {
1521 if (length $changefields{$parameter}) {
1522 $value=$changefields{$parameter};
1524 delete $changefields{$parameter};
1528 push @out, $formatfield->($parameter, $value);
1532 if (defined $section &&
1533 $section eq $targetsection) {
1536 elsif (%changefields) {
1537 push @out, "\n[$targetsection]\n";
1538 foreach my $field (sort keys %changefields) {
1539 if (length $changefields{$field}) {
1540 push @out, $formatfield->($field, $changefields{$field});
1545 open(my $out, ">", $f) || die "mr: write $f: $!\n";
1553 # actions that do not operate on all repos
1554 if ($action eq 'help') {
1557 elsif ($action eq 'config') {
1560 elsif ($action eq 'register') {
1563 elsif ($action eq 'bootstrap') {
1566 elsif ($action eq 'remember' ||
1567 $action eq 'offline' ||
1568 $action eq 'online') {
1569 my @repos=selectrepos;
1570 action($action, @{$repos[0]}) if @repos;
1574 if (!$jobs || $jobs > 1) {
1575 mrs($action, selectrepos());
1578 foreach my $repo (selectrepos()) {
1579 record($repo, action($action, @$repo));
1585 exec($config{''}{DEFAULT}{help}) || die "exec: $!";
1590 die "mr config: not enough parameters\n";
1593 if ($section=~/^\//) {
1594 # try to convert to a path relative to the config file
1595 my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
1596 $dir=abs_path($dir);
1597 $dir.="/" unless $dir=~/\/$/;
1598 if ($section=~/^\Q$dir\E(.*)/) {
1604 if (/^([^=]+)=(.*)$/) {
1605 $changefields{$1}=$2;
1609 foreach my $topdir (sort keys %config) {
1610 if (exists $config{$topdir}{$section} &&
1611 exists $config{$topdir}{$section}{$_}) {
1612 print $config{$topdir}{$section}{$_}."\n";
1614 last if $section eq 'DEFAULT';
1618 die "mr config: $section $_ not set\n";
1622 modifyconfig($ENV{MR_CONFIG}, $section, %changefields) if %changefields;
1627 if ($config_overridden) {
1628 # Find the directory that the specified config file is
1630 ($directory)=abs_path($ENV{MR_CONFIG})=~/^(.*\/)[^\/]+$/;
1633 # Find the closest known mrconfig file to the current
1635 $directory.="/" unless $directory=~/\/$/;
1637 foreach my $topdir (reverse sort keys %config) {
1638 next unless length $topdir;
1639 if ($directory=~/^\Q$topdir\E/) {
1640 $ENV{MR_CONFIG}=$configfiles{$topdir};
1646 if (! $foundconfig) {
1647 $directory=""; # no config file, use builtin
1651 my $subdir=shift @ARGV;
1652 if (! chdir($subdir)) {
1653 print STDERR "mr register: failed to chdir to $subdir: $!\n";
1657 $ENV{MR_REPO}=getcwd();
1658 my $command=findcommand("register", $ENV{MR_REPO}, $directory, 'DEFAULT', 0);
1659 if (! defined $command) {
1660 die "mr register: unknown repository type\n";
1663 $ENV{MR_REPO}=~s/.*\/(.*)/$1/;
1664 $command="set -e; ".$config{$directory}{DEFAULT}{lib}."\n".
1665 "my_action(){ $command\n }; my_action ".
1666 join(" ", map { s/\\/\\\\/g; s/"/\"/g; '"'.$_.'"' } @ARGV);
1667 print "mr register: running >>$command<<\n" if $verbose;
1668 exec($command) || die "exec: $!";
1672 my $url=shift @ARGV;
1673 my $dir=shift @ARGV || ".";
1675 if (! defined $url || ! length $url) {
1676 die "mr: bootstrap requires url\n";
1679 # Download the config file to a temporary location.
1680 eval q{use File::Temp};
1682 my $tmpconfig=File::Temp->new();
1684 if ($url =~ m!^ssh://(.*)!) {
1685 @downloader = ("scp", $1, $tmpconfig);
1688 @downloader = ("curl", "-A", "mr", "-L", "-s", $url, "-o", $tmpconfig);
1689 push(@downloader, "-k") if $insecure;
1691 my $status = system(@downloader);
1692 die "mr bootstrap: invalid SSL certificate for $url (consider -k)\n"
1693 if $downloader[0] eq 'curl' && $status >> 8 == 60;
1694 die "mr bootstrap: download of $url failed\n" if $status != 0;
1697 system("mkdir", "-p", $dir);
1699 chdir($dir) || die "chdir $dir: $!";
1701 # Special case to handle checkout of the "." repo, which
1702 # would normally be skipped.
1703 my $topdir=abs_path(".")."/";
1704 my @repo=($topdir, $topdir, ".");
1705 loadconfig($tmpconfig, $topdir, $url);
1706 record(\@repo, action("checkout", @repo, 1))
1707 if exists $config{$topdir}{"."}{"checkout"};
1709 if (-e ".mrconfig") {
1710 print STDERR "mr bootstrap: .mrconfig file already exists, not overwriting with $url\n";
1713 eval q{use File::Copy};
1715 move($tmpconfig, ".mrconfig") || die "rename: $!";
1718 # Reload the config file (in case we got a different version)
1719 # and checkout everything else.
1721 loadconfig(".mrconfig");
1722 dispatch("checkout");
1723 @skipped=grep { abs_path($_) ne abs_path($topdir) } @skipped;
1724 showstats("bootstrap");
1728 # alias expansion and command stemming
1731 if (exists $alias{$action}) {
1732 $action=$alias{$action};
1734 if (! exists $knownactions{$action}) {
1735 my @matches = grep { /^\Q$action\E/ }
1736 keys %knownactions, keys %alias;
1737 if (@matches == 1) {
1738 $action=$matches[0];
1740 elsif (@matches == 0) {
1741 die "mr: unknown action \"$action\" (known actions: ".
1742 join(", ", sort keys %knownactions).")\n";
1745 die "mr: ambiguous action \"$action\" (matches: ".
1746 join(", ", @matches).")\n";
1754 while (length $dir) {
1755 if (-e "$dir/.mrconfig") {
1756 return "$dir/.mrconfig";
1758 $dir=~s/\/[^\/]*$//;
1760 return $HOME_MR_CONFIG;
1765 Getopt::Long::Configure("bundling", "no_permute");
1766 my $result=GetOptions(
1767 "d|directory=s" => sub { $directory=abs_path($_[1]) },
1768 "c|config=s" => sub { $ENV{MR_CONFIG}=$_[1]; $config_overridden=1 },
1769 "p|path" => sub { }, # now default, ignore
1770 "f|force" => \$force,
1771 "v|verbose" => \$verbose,
1772 "q|quiet" => \$quiet,
1773 "s|stats" => \$stats,
1774 "k|insecure" => \$insecure,
1775 "i|interactive" => \$interactive,
1776 "n|no-recurse:i" => \$max_depth,
1777 "j|jobs:i" => \$jobs,
1778 "t|trust-all" => \$trust_all,
1780 if (! $result || @ARGV < 1) {
1781 die("Usage: mr [options] action [params ...]\n".
1782 "(Use mr help for man page.)\n");
1785 $ENV{MR_SWITCHES}="";
1786 foreach my $option (@saved) {
1787 last if $option eq $ARGV[0];
1788 $ENV{MR_SWITCHES}.="$option ";
1794 print STDERR "mr: interrupted\n";
1798 # This can happen if it's run in a directory that was removed
1799 # or other strangeness.
1800 if (! defined $directory) {
1801 die("mr: failed to determine working directory\n");
1803 # Make sure MR_CONFIG is an absolute path, but don't use abs_path since
1804 # the config file might be a symlink to elsewhere, and the directory it's
1805 # in is significant.
1806 if ($ENV{MR_CONFIG} !~ /^\//) {
1807 $ENV{MR_CONFIG}=getcwd()."/".$ENV{MR_CONFIG};
1809 # Try to set MR_PATH to the path to the program.
1811 use FindBin qw($Bin $Script);
1812 $ENV{MR_PATH}=$Bin."/".$Script;
1830 loadconfig($HOME_MR_CONFIG);
1831 loadconfig($ENV{MR_CONFIG});
1832 #use Data::Dumper; print Dumper(\%config);
1834 my $action=expandaction(shift @ARGV);
1841 # Finally, some useful actions that mr knows about by default.
1842 # These can be overridden in ~/.mrconfig.
1857 echo "mr (warning): $@" >&2
1863 if [ -z "$1" ] || [ -z "$2" ]; then
1864 error "mr: usage: hours_since action num"
1866 for dir in .git .svn .bzr CVS .hg _darcs _FOSSIL_; do
1867 if [ -e "$MR_REPO/$dir" ]; then
1868 flagfile="$MR_REPO/$dir/.mr_last$1"
1872 if [ -z "$flagfile" ]; then
1873 error "cannot determine flag filename"
1875 delta=`perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile"`
1876 if [ "$delta" -lt "$2" ]; then
1884 LANG=C bzr info | egrep -q '^Checkout'
1887 if [ -d "$MR_REPO" ]; then
1894 svn_test = perl: -d "$ENV{MR_REPO}/.svn"
1895 git_test = perl: -e "$ENV{MR_REPO}/.git"
1896 bzr_test = perl: -d "$ENV{MR_REPO}/.bzr"
1897 cvs_test = perl: -d "$ENV{MR_REPO}/CVS"
1898 hg_test = perl: -d "$ENV{MR_REPO}/.hg"
1899 darcs_test = perl: -d "$ENV{MR_REPO}/_darcs"
1900 fossil_test = perl: -f "$ENV{MR_REPO}/_FOSSIL_"
1901 git_bare_test = perl:
1902 -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
1903 -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
1904 `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get core.bare` =~ /true/
1906 -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
1907 -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
1908 `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get vcsh.vcsh` =~ /true/
1909 veracity_test = perl: -d "$ENV{MR_REPO}/.sgdrawer"
1911 svn_update = svn update "$@"
1912 git_update = git pull "$@"
1914 if is_bzr_checkout; then
1917 bzr merge --pull "$@"
1919 cvs_update = cvs -q update "$@"
1920 hg_update = hg pull "$@"; hg update "$@"
1921 darcs_update = darcs pull -a "$@"
1922 fossil_update = fossil pull "$@"
1923 vcsh_update = vcsh run "$MR_REPO" git pull "$@"
1924 veracity_update = vv pull "$@" && vv update "$@"
1926 git_fetch = git fetch --all --prune --tags
1927 git_svn_fetch = git svn fetch
1928 darcs_fetch = darcs fetch
1931 svn_status = svn status "$@"
1932 git_status = git status -s "$@" || true; git --no-pager log --branches --not --remotes --simplify-by-decoration --decorate --oneline || true
1933 bzr_status = bzr status --short "$@"; bzr missing
1934 cvs_status = cvs -q status | grep -E '^(File:.*Status:|\?)' | grep -v 'Status: Up-to-date'
1935 hg_status = hg status "$@"; hg summary --quiet | grep -v 'parent: 0:'
1936 darcs_status = darcs whatsnew -ls "$@" || true
1937 fossil_status = fossil changes "$@"
1938 vcsh_status = vcsh run "$MR_REPO" git -c status.relativePaths=false status -s "$@" || true
1939 veracity_status = vv status "$@"
1941 svn_commit = svn commit "$@"
1942 git_commit = git commit -a "$@" && git push --all
1944 if is_bzr_checkout; then
1947 bzr commit "$@" && bzr push
1949 cvs_commit = cvs commit "$@"
1950 hg_commit = hg commit "$@" && hg push
1951 darcs_commit = darcs record -a "$@" && darcs push -a
1952 fossil_commit = fossil commit "$@"
1953 vcsh_commit = vcsh run "$MR_REPO" git commit -a "$@" && vcsh run "$MR_REPO" git push --all
1954 veracity_commit = vv commit "$@" && vv push
1956 git_record = git commit -a "$@"
1958 if is_bzr_checkout; then
1959 bzr commit --local "$@"
1963 hg_record = hg commit "$@"
1964 darcs_record = darcs record -a "$@"
1965 fossil_record = fossil commit "$@"
1966 vcsh_record = vcsh run "$MR_REPO" git commit -a "$@"
1967 veracity_record = vv commit "$@"
1970 git_push = git push "$@"
1971 bzr_push = bzr push "$@"
1973 hg_push = hg push "$@"
1974 darcs_push = darcs push -a "$@"
1975 fossil_push = fossil push "$@"
1976 vcsh_push = vcsh run "$MR_REPO" git push "$@"
1977 veracity_push = vv push "$@"
1979 svn_diff = svn diff "$@"
1980 git_diff = git diff "$@"
1981 bzr_diff = bzr diff "$@"
1982 cvs_diff = cvs -q diff "$@"
1983 hg_diff = hg diff "$@"
1984 darcs_diff = darcs diff -u "$@"
1985 fossil_diff = fossil diff "$@"
1986 vcsh_diff = vcsh run "$MR_REPO" git diff "$@"
1987 veracity_diff = vv diff "$@"
1989 svn_log = svn log "$@"
1990 git_log = git log "$@"
1991 bzr_log = bzr log "$@"
1992 cvs_log = cvs log "$@"
1993 hg_log = hg log "$@"
1994 darcs_log = darcs changes "$@"
1995 git_bare_log = git log "$@"
1996 fossil_log = fossil timeline "$@"
1997 vcsh_log = vcsh run "$MR_REPO" git log "$@"
1998 veracity_log = vv log "$@"
2000 hg_grep = hg grep "$@"
2001 cvs_grep = ack-grep "$@"
2002 svn_grep = ack-grep "$@"
2003 git_svn_grep = git grep "$@"
2004 git_grep = git grep "$@"
2005 bzr_grep = ack-grep "$@"
2010 url=`LC_ALL=C svn info . | grep -i '^URL:' | cut -d ' ' -f 2`
2011 if [ -z "$url" ]; then
2012 error "cannot determine svn url"
2014 echo "Registering svn url: $url in $MR_CONFIG"
2015 mr -c "$MR_CONFIG" config "`pwd`" checkout="svn co '$url' '$MR_REPO'"
2017 url="`LC_ALL=C git config --get remote.origin.url`" || true
2018 if [ -z "$url" ]; then
2019 error "cannot determine git url"
2021 echo "Registering git url: $url in $MR_CONFIG"
2022 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone '$url' '$MR_REPO'"
2024 url="`LC_ALL=C bzr info . | egrep -i 'checkout of branch|parent branch' | awk '{print $NF}' | head -n 1`"
2025 if [ -z "$url" ]; then
2026 error "cannot determine bzr url"
2028 echo "Registering bzr url: $url in $MR_CONFIG"
2029 mr -c "$MR_CONFIG" config "`pwd`" checkout="bzr branch '$url' '$MR_REPO'"
2031 repo=`cat CVS/Repository`
2033 if [ -z "$root" ]; then
2034 error "cannot determine cvs root"
2036 echo "Registering cvs repository $repo at root $root"
2037 mr -c "$MR_CONFIG" config "`pwd`" checkout="cvs -d '$root' co -d '$MR_REPO' '$repo'"
2039 url=`hg showconfig paths.default`
2040 echo "Registering mercurial repo url: $url in $MR_CONFIG"
2041 mr -c "$MR_CONFIG" config "`pwd`" checkout="hg clone '$url' '$MR_REPO'"
2043 url=`cat _darcs/prefs/defaultrepo`
2044 echo "Registering darcs repository $url in $MR_CONFIG"
2045 mr -c "$MR_CONFIG" config "`pwd`" checkout="darcs get '$url' '$MR_REPO'"
2047 url="`LC_ALL=C GIT_CONFIG=config git config --get remote.origin.url`" || true
2048 if [ -z "$url" ]; then
2049 error "cannot determine git url"
2051 echo "Registering git url: $url in $MR_CONFIG"
2052 mr -c "$MR_CONFIG" config "`pwd`" checkout="git clone --bare '$url' '$MR_REPO'"
2054 url="`LC_ALL=C vcsh run "$MR_REPO" git config --get remote.origin.url`" || true
2055 if [ -z "$url" ]; then
2056 error "cannot determine git url"
2058 echo "Registering git url: $url in $MR_CONFIG"
2059 mr -c "$MR_CONFIG" config "`pwd`" checkout="vcsh clone '$url' '$MR_REPO'"
2061 url=`fossil remote-url`
2062 repo=`fossil info | grep repository | sed -e 's/repository:*.//g' -e 's/ //g'`
2063 echo "Registering fossil repository $url in $MR_CONFIG"
2064 mr -c "$MR_CONFIG" config "`pwd`" checkout="mkdir -p '$MR_REPO' && cd '$MR_REPO' && fossil open '$repo'"
2066 url=`vv config | grep sync_targets | sed -e 's/sync_targets:*.//g' -e 's/ //g'`
2067 repo=`vv repo info | grep repository | sed -e 's/Current repository:*.//g' -e 's/ //g'`
2068 echo "Registering veracity repository $url in $MR_CONFIG"
2069 mr -c "$MR_CONFIG" config "`pwd`" checkout="mkdir -p '$MR_REPO' && cd '$MR_REPO' && vv checkout '$repo'"
2071 svn_trusted_checkout = svn co $url $repo
2072 svn_alt_trusted_checkout = svn checkout $url $repo
2073 git_trusted_checkout = git clone $url $repo
2074 bzr_trusted_checkout = bzr checkout|clone|branch|get $url $repo
2076 hg_trusted_checkout = hg clone $url $repo
2077 darcs_trusted_checkout = darcs get $url $repo
2078 git_bare_trusted_checkout = git clone --bare $url $repo
2079 vcsh_trusted_checkout = vcsh run "$MR_REPO" git clone $url $repo
2080 # fossil: messy to do
2081 veracity_trusted_checkout = vv clone $url $repo
2087 SHOWMANFILE="man -f"
2096 if [ ! -e "$MR_PATH" ]; then
2097 error "cannot find program path"
2099 tmp=$(mktemp -t mr.XXXXXXXXXX) || error "mktemp failed"
2100 trap "rm -f $tmp" exit
2101 pod2man -c mr "$MR_PATH" > "$tmp" || error "pod2man failed"
2102 $SHOWMANFILE "$tmp" || error "man failed"
2108 if [ -s ~/.mrlog ]; then
2109 info "running offline commands"
2110 mv -f ~/.mrlog ~/.mrlog.old
2111 if ! sh -e ~/.mrlog.old; then
2112 error "offline command failed; left in ~/.mrlog.old"
2116 info "no offline commands to run"
2121 info "offline mode enabled"
2123 info "remembering command: 'mr $@'"
2124 command="mr -d '$(pwd)' $MR_SWITCHES"
2126 command="$command '$w'"
2128 if [ ! -e ~/.mrlog ] || ! grep -q -F "$command" ~/.mrlog; then
2129 echo "$command" >> ~/.mrlog
2132 ed = echo "A horse is a horse, of course, of course.."
2133 T = echo "I pity the fool."
2134 right = echo "Not found."
2136 # vim:sw=8:sts=0:ts=8:noet
2138 # indent-tabs-mode: t
2139 # cperl-indent-level: 8