]> git.madduck.net Git - code/myrepos.git/blob - mr

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

d170e67ff1430ca0433b8fea95892b51650a285b
[code/myrepos.git] / mr
1 #!/usr/bin/perl
2
3 #man{{{
4
5 =head1 NAME
6
7 mr - a Multiple Repository management tool
8
9 =head1 SYNOPSIS
10
11 B<mr> [options] checkout
12
13 B<mr> [options] update
14
15 B<mr> [options] status
16
17 B<mr> [options] commit [-m "message"]
18
19 B<mr> [options] diff
20
21 B<mr> [options] log
22
23 B<mr> [options] register [repository]
24
25 B<mr> [options] config section [parameter=[value] ...]
26
27 B<mr> [options] action [params ...]
28
29 =head1 DESCRIPTION
30
31 B<mr> is a Multiple Repository management tool. It
32 can checkout, update, or perform other actions on
33 a set of repositories as if they were one combined respository. It
34 supports any combination of subversion, git, cvs, and bzr repositories, 
35 and support for other revision control systems can easily be added.
36
37 B<mr> cds into and operates on all registered repositories at or below your
38 working directory. Or, if you are in a subdirectory of a repository that
39 contains no other registered repositories, it will stay in that directory,
40 and work on only that repository,
41
42 These predefined commands should be fairly familiar to users of any revision
43 control system:
44
45 =over 4
46
47 =item checkout (or co)
48
49 Checks out any repositories that are not already checked out.
50
51 =item update
52
53 Updates each repository from its configured remote repository.
54
55 If a repository isn't checked out yet, it will first check it out.
56
57 =item status
58
59 Displays a status report for each repository, showing what
60 uncommitted changes are present in the repository.
61
62 =item commit (or ci)
63
64 Commits changes to each repository. (By default, changes are pushed to the
65 remote repository too, when using distributed systems like git.)
66
67 The optional -m parameter allows specifying a commit message.
68
69 =item diff
70
71 Show a diff of uncommitted changes.
72
73 =item log
74
75 Show the commit log.
76
77 =back
78
79 These commands are also available:
80
81 =over 4
82
83 =item list (or ls)
84
85 List the repositories that mr will act on.
86
87 =item register
88
89 Register an existing repository in the mrconfig file. By default, the
90 repository in the current directory is registered, or you can specify a
91 directory to register.
92
93 By default it registers it to the ~/.mrconfig file. To make it write to a
94 different file, use the -c option.
95
96 =item config
97
98 Adds, modifies, removes, or prints a value from the mrconfig file. The next
99 parameter is the name of the section the value is in. To add or modify
100 values, use one or more instances of "parameter=value". Use "parameter=" to
101 remove a parameter. Use just "parameter" to get the value of a parameter.
102
103 For example, to add (or edit) a repository in src/foo:
104
105   mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
106
107 To show the command that mr uses to update the repository in src/foo:
108
109   mr config src/foo update
110
111 =item help
112
113 Displays this help.
114
115 =back
116
117 Actions can be abbreviated to any unambiguous subsctring, so
118 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
119 update"
120
121 Additional parameters can be passed to most commands, and are passed on
122 unchanged to the underlying revision control system. This is mostly useful
123 if the repositories mr will act on all use the same revision control
124 system.
125
126 =head1 OPTIONS
127
128 =over 4
129
130 =item -d directory
131
132 Specifies the topmost directory that B<mr> should work in. The default is
133 the current working directory.
134
135 =item -c mrconfig
136
137 Use the specified mrconfig file, instead of looking for one in your home
138 directory.
139
140 =item -v
141
142 Be verbose.
143
144 =item -s
145
146 Expand the statistics line displayed at the end to include information
147 about exactly which repositories failed and were skipped, if any.
148
149 =back
150
151 =head1 FILES
152
153 B<mr> is configured by .mrconfig files. It starts by reading the .mrconfig
154 file in your home directory, and this can in turn chain load .mrconfig files
155 from repositories.
156
157 Here is an example .mrconfig file:
158
159   [src]
160   checkout = svn co svn://svn.example.com/src/trunk src
161   chain = true
162
163   [src/linux-2.6]
164   checkout = git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git &&
165         cd linux-2.6 &&
166         git checkout -b mybranch origin/master
167
168 The .mrconfig file uses a variant of the INI file format. Lines starting with
169 "#" are comments. Values can be continued to the following line by
170 indenting the line with whitespace.
171
172 The "DEFAULT" section allows setting default values for the sections that
173 come after it.
174
175 The "ALIAS" section allows adding aliases for actions. Each parameter
176 is an alias, and its value is the action to use.
177
178 All other sections add repositories. The section header specifies the
179 directory where the repository is located. This is relative to the directory
180 that contains the mrconfig file, but you can also choose to use absolute
181 paths.
182
183 Within a section, each parameter defines a shell command to run to handle a
184 given action. mr contains default handlers for the "update", "status", and
185 "commit" actions, so normally you only need to specify what to do for
186 "checkout".
187
188 Note that these shell commands are run in a "set -e" shell
189 environment, where any additional parameters you pass are available in
190 "$@". The "checkout" command is run in the parent of the repository
191 directory, since the repository isn't checked out yet. All other commands
192 are run inside the repository, though not necessarily at the top of it.
193 The "MR_REPO" environment variable is set to the path to the top of the
194 repository, and "MR_CONFIG" is set to the topmost .mrconfig file used.
195
196 A few parameters have special meanings:
197
198 =over 4
199
200 =item skip
201
202 If the "skip" parameter is set and its command returns nonzero, then B<mr>
203 will skip acting on that repository. The command is passed the action
204 name in $1.
205
206 Here are two examples. The first skips the repo unless
207 mr is run by joey. The second uses the hours_since function
208 (included in mr's built-in library) to skip updating the repo unless it's
209 been at least 12 hours since the last update.
210
211   skip = test $(whoami) != joey
212   skip = [ "$1" = update ] && [ $(hours_since "$1") -lt 12 ]
213
214 =item chain
215
216 If the "chain" parameter is set and its command returns nonzero, then B<mr>
217 will try to load a .mrconfig file from the root of the repository. (You
218 should avoid chaining from repositories with untrusted committers.)
219
220 =item deleted
221
222 If the "deleted" parameter is set and its command returns nonzero, then
223 B<mr> will treat the repository as deleted. It won't ever actually delete
224 the repository, but it will warn if it sees the repository's directory.
225 This is useful when one mrconfig file is shared amoung multiple machines,
226 to keep track of and remember to delete old repositories.
227
228 =item lib
229
230 The "lib" parameter can specify some shell code that will be run before each
231 command, this can be a useful way to define shell functions for other commands
232 to use.
233
234 =back
235
236 =head1 AUTHOR
237
238 Copyright 2007 Joey Hess <joey@kitenet.net>
239
240 Licensed under the GNU GPL version 2 or higher.
241
242 http://kitenet.net/~joey/code/mr/
243
244 =cut
245
246 #}}}
247
248 use warnings;
249 use strict;
250 use Getopt::Long;
251 use Cwd qw(getcwd abs_path);
252
253 $ENV{MR_CONFIG}="$ENV{HOME}/.mrconfig";
254 my $directory=getcwd();
255 my $verbose=0;
256 my $stats=0;
257 my %config;
258 my %knownactions;
259 my %alias;
260
261 Getopt::Long::Configure("no_permute");
262 my $result=GetOptions(
263         "d|directory=s" => sub { $directory=abs_path($_[1]) },
264         "c|config=s" => \$ENV{MR_CONFIG},
265         "v|verbose" => \$verbose,
266         "s|stats" => \$stats,
267 );
268 if (! $result || @ARGV < 1) {
269         die("Usage: mr [-d directory] action [params ...]\n".
270             "(Use mr help for man page.)\n");
271
272 }
273
274 loadconfig(\*DATA);
275 loadconfig($ENV{MR_CONFIG});
276 #use Data::Dumper;
277 #print Dumper(\%config);
278
279 eval {
280         use FindBin qw($Bin $Script);
281         $ENV{MR_PATH}=$Bin."/".$Script;
282 };
283
284 # alias expansion and command stemming
285 my $action=shift @ARGV;
286 if (exists $alias{$action}) {
287         $action=$alias{$action};
288 }
289 if (! exists $knownactions{$action}) {
290         my @matches = grep { /^\Q$action\E/ }
291                 keys %knownactions, keys %alias;
292         if (@matches == 1) {
293                 $action=$matches[0];
294         }
295         elsif (@matches == 0) {
296                 die "mr: unknown action \"$action\" (known actions: ".
297                         join(", ", sort keys %knownactions).")\n";
298         }
299         else {
300                 die "mr: ambiguous action \"$action\" (matches: ".
301                         join(", ", @matches).")\n";
302         }
303 }
304
305 if ($action eq 'help') {
306         exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
307 }
308 elsif ($action eq 'config') {
309         if (@ARGV < 2) {
310                 die "mr config: not enough parameters\n";
311         }
312         my $section=shift;
313         if ($section=~/^\//) {
314                 # try to convert to a path relative to $config's dir
315                 my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
316                 if ($section=~/^\Q$dir\E(.*)/) {
317                         $section=$1;
318                 }
319         }
320         my %changefields;
321         foreach (@ARGV) {
322                 if (/^([^=]+)=(.*)$/) {
323                         $changefields{$1}=$2;
324                 }
325                 else {
326                         my $found=0;
327                         foreach my $topdir (sort keys %config) {
328                                 if (exists $config{$topdir}{$section} &&
329                                     exists $config{$topdir}{$section}{$_}) {
330                                         print $config{$topdir}{$section}{$_}."\n";
331                                         $found=1;
332                                 }
333                         }
334                         if (! $found) {
335                                 die "mr $action: $section $_ not set\n";
336                         }
337                 }
338         }
339         modifyconfig($ENV{MR_CONFIG}, $section, %changefields) if %changefields;
340         exit 0;
341 }
342 elsif ($action eq 'register') {
343         my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
344                 "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
345                 join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
346         print STDERR "mr $action: running >>$command<<\n" if $verbose;
347         exec($command) || die "exec: $!";
348 }
349
350 # work out what repos to act on
351 my @repos;
352 my $nochdir=0;
353 foreach my $topdir (sort keys %config) {
354         foreach my $subdir (sort keys %{$config{$topdir}}) {
355                 next if $subdir eq 'DEFAULT';
356                 my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
357                 my $d=$directory;
358                 $dir.="/" unless $dir=~/\/$/;
359                 $d.="/" unless $d=~/\/$/;
360                 next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
361                 push @repos, [$dir, $topdir, $subdir];
362         }
363 }
364 if (! @repos) {
365         # fallback to find a leaf repo
366         LEAF: foreach my $topdir (reverse sort keys %config) {
367                 foreach my $subdir (reverse sort keys %{$config{$topdir}}) {
368                         next if $subdir eq 'DEFAULT';
369                         my $dir=($subdir =~/^\//) ? $subdir : $topdir.$subdir;
370                         my $d=$directory;
371                         $dir.="/" unless $dir=~/\/$/;
372                         $d.="/" unless $d=~/\/$/;
373                         if ($d=~/^\Q$dir\E/) {
374                                 push @repos, [$dir, $topdir, $subdir];
375                                 last LEAF;
376                         }
377                 }
378         }
379         $nochdir=1;
380 }
381
382 my (@failed, @ok, @skipped);
383 foreach my $repo (@repos) {
384         action($action, @$repo);
385 }
386
387 sub action { #{{{
388         my ($action, $dir, $topdir, $subdir) = @_;
389         
390         my $lib= exists $config{$topdir}{$subdir}{lib} ?
391                         $config{$topdir}{$subdir}{lib}."\n" : "";
392
393         if (exists $config{$topdir}{$subdir}{deleted}) {
394                 if (! -d $dir) {
395                         return;
396                 }
397                 else {
398                         my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
399                         print "mr $action: running deleted test >>$test<<\n" if $verbose;
400                         my $ret=system($test);
401                         if ($ret >> 8 == 0) {
402                                 print STDERR "mr error: $dir should be deleted yet still exists\n\n";
403                                 push @failed, $dir;
404                                 return;
405                         }
406                 }
407         }
408
409         if ($action eq 'checkout') {
410                 if (-d $dir) {
411                         print "mr $action: $dir already exists, skipping checkout\n" if $verbose;
412                         push @skipped, $dir;
413                         return;
414                 }
415                 $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
416         }
417         elsif ($action eq 'update') {
418                 if (! -d $dir) {
419                         return action("checkout", $dir, $topdir, $subdir);
420                 }
421         }
422         
423         $ENV{MR_REPO}=$dir;
424
425         if (exists $config{$topdir}{$subdir}{skip}) {
426                 my $test="set -e;".$lib.
427                         "my_action(){ $config{$topdir}{$subdir}{skip}\n }; my_action '$action'";
428                 print "mr $action: running skip test >>$test<<\n" if $verbose;
429                 my $ret=system($test);
430                 if ($ret >> 8 == 0) {
431                         print "mr $action: $dir skipped per config file\n" if $verbose;
432                         push @skipped, $dir;
433                         return;
434                 }
435         }
436         
437         if (! $nochdir && ! chdir($dir)) {
438                 print STDERR "mr $action: failed to chdir to $dir: $!\n";
439                 push @failed, $dir;
440         }
441         elsif (! exists $config{$topdir}{$subdir}{$action}) {
442                 print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n";
443                 push @skipped, $dir;
444         }
445         else {
446                 if (! $nochdir) {
447                         print "mr $action: $topdir$subdir\n";
448                 }
449                 else {
450                         print "mr $action: $topdir$subdir (in subdir $directory)\n";
451                 }
452                 my $command="set -e; ".$lib.
453                         "my_action(){ $config{$topdir}{$subdir}{$action}\n }; my_action ".
454                         join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
455                 print STDERR "mr $action: running >>$command<<\n" if $verbose;
456                 my $ret=system($command);
457                 if ($ret != 0) {
458                         print STDERR "mr $action: failed ($ret)\n" if $verbose;
459                         push @failed, $dir;
460                         if ($ret >> 8 != 0) {
461                                 print STDERR "mr $action: command failed\n";
462                         }
463                         elsif ($ret != 0) {
464                                 print STDERR "mr $action: command died ($ret)\n";
465                         }
466                 }
467                 else {
468                         if ($action eq 'checkout' && ! -d $dir) {
469                                 print STDERR "mr $action: $dir missing after checkout\n";;
470                                 push @failed, $dir;
471                                 return;
472                         }
473
474                         push @ok, $dir;
475                 }
476
477                 print "\n";
478         }
479 } #}}}
480
481 sub showstat { #{{{
482         my $count=shift;
483         my $singular=shift;
484         my $plural=shift;
485         if ($count) {
486                 return "$count ".($count > 1 ? $plural : $singular);
487         }
488         return;
489 } #}}}
490 if (! @ok && ! @failed && ! @skipped) {
491         die "mr $action: no repositories found to work on\n";
492 }
493 print "mr $action: finished (".join("; ",
494         showstat($#ok+1, "ok", "ok"),
495         showstat($#failed+1, "failed", "failed"),
496         showstat($#skipped+1, "skipped", "skipped"),
497 ).")\n";
498 if ($stats) {
499         if (@skipped) {
500                 print "mr $action: (skipped: ".join(" ", @skipped).")\n";
501         }
502         if (@failed) {
503                 print "mr $action: (failed: ".join(" ", @failed).")\n";
504         }
505 }
506 if (@failed) {
507         exit 1;
508 }
509 elsif (! @ok && @skipped) {
510         exit 1;
511 }
512 exit 0;
513
514 my %loaded;
515 sub loadconfig { #{{{
516         my $f=shift;
517
518         my @toload;
519
520         my $in;
521         my $dir;
522         if (ref $f eq 'GLOB') {
523                 $dir="";
524                 $in=$f; 
525         }
526         else {
527                 if (! -e $f) {
528                         return;
529                 }
530
531                 my $absf=abs_path($f);
532                 if ($loaded{$absf}) {
533                         return;
534                 }
535                 $loaded{$absf}=1;
536
537                 ($dir)=$f=~/^(.*\/)[^\/]+$/;
538                 if (! defined $dir) {
539                         $dir=".";
540                 }
541                 $dir=abs_path($dir)."/";
542
543                 # copy in defaults from first parent
544                 my $parent=$dir;
545                 while ($parent=~s/^(.*\/)[^\/]+\/?$/$1/) {
546                         if ($parent eq '/') {
547                                 $parent="";
548                         }
549                         if (exists $config{$parent} &&
550                             exists $config{$parent}{DEFAULT}) {
551                                 $config{$dir}{DEFAULT}={ %{$config{$parent}{DEFAULT}} };
552                                 last;
553                         }
554                 }
555                 
556                 print "mr: loading config $f\n" if $verbose;
557                 open($in, "<", $f) || die "mr: open $f: $!\n";
558         }
559         my @lines=<$in>;
560         close $in;
561
562         my $section;
563         my $line=0;
564         while (@lines) {
565                 $_=shift @lines;
566                 $line++;
567                 chomp;
568                 next if /^\s*\#/ || /^\s*$/;
569                 if (/^\[([^\]]*)\]\s*$/) {
570                         $section=$1;
571                 }
572                 elsif (/^(\w+)\s*=\s*(.*)/) {
573                         my $parameter=$1;
574                         my $value=$2;
575
576                         # continued value
577                         while (@lines && $lines[0]=~/^\s(.+)/) {
578                                 shift(@lines);
579                                 $line++;
580                                 $value.="\n$1";
581                                 chomp $value;
582                         }
583
584                         if (! defined $section) {
585                                 die "$f line $.: parameter ($parameter) not in section\n";
586                         }
587                         if ($section ne 'ALIAS' &&
588                             ! exists $config{$dir}{$section} &&
589                             exists $config{$dir}{DEFAULT}) {
590                                 # copy in defaults
591                                 $config{$dir}{$section}={ %{$config{$dir}{DEFAULT}} };
592                         }
593                         if ($section eq 'ALIAS') {
594                                 $alias{$parameter}=$value;
595                         }
596                         elsif ($parameter eq 'lib') {
597                                 $config{$dir}{$section}{lib}.=$value."\n";
598                         }
599                         else {
600                                 $config{$dir}{$section}{$parameter}=$value;
601                                 $knownactions{$parameter}=1;
602                                 if ($parameter eq 'chain' &&
603                                     length $dir && $section ne "DEFAULT" &&
604                                     -e $dir.$section."/.mrconfig" &&
605                                     system($value) >> 8 == 0) {
606                                         push @toload, $dir.$section."/.mrconfig";
607                                 }
608                         }
609                 }
610                 else {
611                         die "$f line $line: parse error\n";
612                 }
613         }
614
615         foreach (@toload) {
616                 loadconfig($_);
617         }
618 } #}}}
619
620 sub modifyconfig { #{{{
621         my $f=shift;
622         # the section to modify or add
623         my $targetsection=shift;
624         # fields to change in the section
625         # To remove a field, set its value to "".
626         my %changefields=@_;
627
628         my @lines;
629         my @out;
630
631         if (-e $f) {
632                 open(my $in, "<", $f) || die "mr: open $f: $!\n";
633                 @lines=<$in>;
634                 close $in;
635         }
636
637         my $formatfield=sub {
638                 my $field=shift;
639                 my @value=split(/\n/, shift);
640
641                 return "$field = ".shift(@value)."\n".
642                         join("", map { "\t$_\n" } @value);
643         };
644         my $addfields=sub {
645                 my @blanks;
646                 while ($out[$#out] =~ /^\s*$/) {
647                         unshift @blanks, pop @out;
648                 }
649                 foreach my $field (sort keys %changefields) {
650                         if (length $changefields{$field}) {
651                                 push @out, "$field = $changefields{$field}\n";
652                                 delete $changefields{$field};
653                         }
654                 }
655                 push @out, @blanks;
656         };
657
658         my $section;
659         while (@lines) {
660                 $_=shift(@lines);
661
662                 if (/^\s*\#/ || /^\s*$/) {
663                         push @out, $_;
664                 }
665                 elsif (/^\[([^\]]*)\]\s*$/) {
666                         if (defined $section && 
667                             $section eq $targetsection) {
668                                 $addfields->();
669                         }
670
671                         $section=$1;
672
673                         push @out, $_;
674                 }
675                 elsif (/^(\w+)\s*=\s(.*)/) {
676                         my $parameter=$1;
677                         my $value=$2;
678
679                         # continued value
680                         while (@lines && $lines[0]=~/^\s(.+)/) {
681                                 shift(@lines);
682                                 $value.="\n$1";
683                                 chomp $value;
684                         }
685
686                         if ($section eq $targetsection) {
687                                 if (exists $changefields{$parameter}) {
688                                         if (length $changefields{$parameter}) {
689                                                 $value=$changefields{$parameter};
690                                         }
691                                         delete $changefields{$parameter};
692                                 }
693                         }
694
695                         push @out, $formatfield->($parameter, $value);
696                 }
697         }
698
699         if (defined $section && 
700             $section eq $targetsection) {
701                 $addfields->();
702         }
703         elsif (%changefields) {
704                 push @out, "\n[$targetsection]\n";
705                 foreach my $field (sort keys %changefields) {
706                         if (length $changefields{$field}) {
707                                 push @out, $formatfield->($field, $changefields{$field});
708                         }
709                 }
710         }
711
712         open(my $out, ">", $f) || die "mr: write $f: $!\n";
713         print $out @out;
714         close $out;     
715 } #}}}
716
717 # Finally, some useful actions that mr knows about by default.
718 # These can be overridden in ~/.mrconfig.
719 #DATA{{{
720 __DATA__
721 [ALIAS]
722 co = checkout
723 ci = commit
724 ls = list
725
726 [DEFAULT]
727 lib =
728         error() {
729                 echo "mr: $@" >&2
730                 exit 1
731         }
732         hours_since() {
733                 for dir in .git .svn .bzr CVS; do
734                         if [ -e "$MR_REPO/$dir" ]; then
735                                 flagfile="$MR_REPO/$dir/.mr_last$1"
736                                 break
737                         fi
738                 done
739                 if [ -z "$flagfile" ]; then
740                         error "cannot determine flag filename"
741                 fi
742                 perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile"
743                 touch "$flagfile"
744         }
745
746 update =
747         if [ -d "$MR_REPO"/.svn ]; then
748                 svn update "$@"
749         elif [ -d "$MR_REPO"/.git ]; then
750                 git pull origin master "$@"
751         elif [ -d "$MR_REPO"/.bzr ]; then
752                 bzr merge "$@"
753         elif [ -d "$MR_REPO"/CVS ]; then
754                 cvs update "$@"
755         else
756                 error "unknown repo type"
757         fi
758 status =
759         if [ -d "$MR_REPO"/.svn ]; then
760                 svn status "$@"
761         elif [ -d "$MR_REPO"/.git ]; then
762                 git status "$@" || true
763         elif [ -d "$MR_REPO"/.bzr ]; then
764                 bzr status "$@"
765         elif [ -d "$MR_REPO"/CVS ]; then
766                 cvs status "$@"
767         else
768                 error "unknown repo type"
769         fi
770 commit =
771         if [ -d "$MR_REPO"/.svn ]; then
772                 svn commit "$@"
773         elif [ -d "$MR_REPO"/.git ]; then
774                 git commit -a "$@" && git push --all
775         elif [ -d "$MR_REPO"/.bzr ]; then
776                 bzr commit "$@" && bzr push
777         elif [ -d "$MR_REPO"/CVS ]; then
778                 cvs commit "$@"
779         else
780                 error "unknown repo type"
781         fi
782 diff =
783         if [ -d "$MR_REPO"/.svn ]; then
784                 svn diff "$@"
785         elif [ -d "$MR_REPO"/.git ]; then
786                 git diff "$@"
787         elif [ -d "$MR_REPO"/.bzr ]; then
788                 bzr diff "$@"
789         elif [ -d "$MR_REPO"/CVS ]; then
790                 cvs diff "$@"
791         else
792                 error "unknown repo type"
793         fi
794 log =
795         if [ -d "$MR_REPO"/.svn ]; then
796                 svn log"$@"
797         elif [ -d "$MR_REPO"/.git ]; then
798                 git log "$@"
799         elif [ -d "$MR_REPO"/.bzr ]; then
800                 bzr log "$@"
801         elif [ -d "$MR_REPO"/CVS ]; then
802                 cvs log "$@"
803         else
804                 error "unknown repo type"
805         fi
806 register =
807         if [ -n "$1" ]; then
808                 cd "$1"
809         fi
810         basedir="$(basename $(pwd))"
811         if [ -d .svn ]; then
812                 url=$(LANG=C svn info . | grep -i ^URL: | cut -d ' ' -f 2)
813                 if [ -z "$url" ]; then
814                         error "cannot determine svn url"
815                 fi
816                 echo "Registering svn url: $url"
817                 mr -c "$MR_CONFIG" config "$(pwd)" checkout="svn co $url $basedir"
818         elif [ -d .git ]; then
819                 url=$(LANG=C git-config --get remote.origin.url)
820                 if [ -z "$url" ]; then
821                         error "cannot determine git url"
822                 fi
823                 echo "Registering git url: $url"
824                 mr -c "$MR_CONFIG" config "$(pwd)" checkout="git clone $url $basedir"
825         elif [ -d .bzr ]; then
826                 url=$(cat .bzr/branch/parent)
827                 if [ -z "$url" ]; then
828                         error "cannot determine bzr url"
829                 fi
830                 echo "Registering bzr url: $url"
831                 mr -c "$MR_CONFIG" config "$(pwd)" checkout="bzr clone $url $basedir"
832         else
833                 error "unable to register this repo type"
834         fi
835 help =
836         if [ ! -e "$MR_PATH" ]; then
837                 error "cannot find program path"
838         fi
839         (pod2man -c mr "$MR_PATH" | man -l -) || error "pod2man or man failed"
840 list = true
841 config = 
842
843 ed = echo "A horse is a horse, of course, of course.."
844 T = echo "I pity the fool."
845 right = echo "Not found."
846 #}}}