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

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