]> 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:

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