]> git.madduck.net Git - code/myrepos.git/blobdiff - 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:

mr register: default to registering the current directory
[code/myrepos.git] / mr
diff --git a/mr b/mr
index 235c17518ad546c868086b8dcb73e931d7c95794..b65e623f09192d7703d883190e335e7662463f5e 100755 (executable)
--- a/mr
+++ b/mr
@@ -18,6 +18,8 @@ B<mr> [options] diff
 
 B<mr> [options] log
 
 
 B<mr> [options] log
 
+B<mr> [options] register [repository]
+
 B<mr> [options] config section [parameter=[value] ...]
 
 B<mr> [options] action [params ...]
 B<mr> [options] config section [parameter=[value] ...]
 
 B<mr> [options] action [params ...]
@@ -76,14 +78,21 @@ Show the commit log.
 
 List the repositories that mr will act on.
 
 
 List the repositories that mr will act on.
 
+=item register
+
+Register an existing repository in the mrconfig file. By default, the
+epository in the current directory is registered, or you can specify a
+directory to register.
+
 =item config
 
 Modifies the mrconfig file. The next parameter is the name of the section
 to add or modify, and it is followed by one or more instances of
 =item config
 
 Modifies the mrconfig file. The next parameter is the name of the section
 to add or modify, and it is followed by one or more instances of
-"parameter=value". Use "parameter=" to remove a parameter. For example,
-to register a new svn repository in src/foo:
+"parameter=value". Use "parameter=" to remove a parameter. 
+
+For example, to add (or edit) a repository in src/foo:
 
 
-  mr config src/foo checkout="svn co svn://example.com/foo/trunk"
+  mr config src/foo checkout="svn co svn://example.com/foo/trunk foo"
 
 =item help
 
 
 =item help
 
@@ -95,10 +104,10 @@ Actions can be abbreviated to any unambiguous subsctring, so
 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
 update"
 
 "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr
 update"
 
-Additional parameters can be passed to other commands than "commit", they
-will be passed on unchanged to the underlying revision control system.
-This is mostly useful if the repositories mr will act on all use the same
-revision control system.
+Additional parameters can be passed to most commands, and are passed on
+unchanged to the underlying revision control system. This is mostly useful
+if the repositories mr will act on all use the same revision control
+system.
 
 =head1 OPTIONS
 
 
 =head1 OPTIONS
 
@@ -259,13 +268,20 @@ if (! exists $knownactions{$action}) {
 }
 
 if ($action eq 'help') {
 }
 
 if ($action eq 'help') {
-       exec($config{''}{DEFAULT}{help});
+       exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
 }
 elsif ($action eq 'config') {
        if (@ARGV < 2) {
                die "mr config: not enough parameters\n";
        }
        my $section=shift;
 }
 elsif ($action eq 'config') {
        if (@ARGV < 2) {
                die "mr config: not enough parameters\n";
        }
        my $section=shift;
+       if ($section=~/^\//) {
+               # try to convert to a path relative to $config's dir
+               my ($dir)=$config=~/^(.*\/)[^\/]+$/;
+               if ($section=~/^\Q$dir\E(.*)/) {
+                       $section=$1;
+               }
+       }
        my %fields;
        foreach (@ARGV) {
                if (/^([^=]+)=(.*)$/) {
        my %fields;
        foreach (@ARGV) {
                if (/^([^=]+)=(.*)$/) {
@@ -278,6 +294,13 @@ elsif ($action eq 'config') {
        modifyconfig($config, $section, %fields);
        exit 0;
 }
        modifyconfig($config, $section, %fields);
        exit 0;
 }
+elsif ($action eq 'register') {
+       my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
+               "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
+               join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
+       print STDERR "mr $action: running >>$command<<\n" if $verbose;
+       exec($command) || die "exec: $!";
+}
 
 # work out what repos to act on
 my @repos;
 
 # work out what repos to act on
 my @repos;
@@ -324,7 +347,7 @@ sub action {
 
        if (exists $config{$topdir}{$subdir}{deleted}) {
                if (! -d $dir) {
 
        if (exists $config{$topdir}{$subdir}{deleted}) {
                if (! -d $dir) {
-                       next;
+                       return;
                }
                else {
                        my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
                }
                else {
                        my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
@@ -441,7 +464,10 @@ sub loadconfig {
                $dir="";
        }
        else {
                $dir="";
        }
        else {
-               # $f might be a symlink
+               if (! -e $f) {
+                       return;
+               }
+
                my $absf=abs_path($f);
                if ($loaded{$absf}) {
                        return;
                my $absf=abs_path($f);
                if ($loaded{$absf}) {
                        return;
@@ -530,14 +556,28 @@ sub modifyconfig {
        my %changefields=@_;
 
        my @lines;
        my %changefields=@_;
 
        my @lines;
+       my @out;
+
        if (-e $f) {
                open(my $in, "<", $f) || die "mr: open $f: $!\n";
                @lines=<$in>;
                close $in;
        }
 
        if (-e $f) {
                open(my $in, "<", $f) || die "mr: open $f: $!\n";
                @lines=<$in>;
                close $in;
        }
 
+       my $addfields=sub {
+               my @blanks;
+               while ($out[$#out] =~ /^\s*$/) {
+                       unshift @blanks, pop @out;
+               }
+               foreach my $field (sort keys %changefields) {
+                       if (length $changefields{$field}) {
+                               push @out, "$field = $changefields{$field}\n";
+                       }
+               }
+               push @out, @blanks;
+       };
+
        my $section;
        my $section;
-       my @out;
        while (@lines) {
                $_=shift(@lines);
 
        while (@lines) {
                $_=shift(@lines);
 
@@ -547,16 +587,7 @@ sub modifyconfig {
                elsif (/^\s*\[([^\]]*)\]\s*$/) {
                        if (defined $section && 
                            $section eq $targetsection) {
                elsif (/^\s*\[([^\]]*)\]\s*$/) {
                        if (defined $section && 
                            $section eq $targetsection) {
-                               my @blanks;
-                               while ($out[$#out] =~ /^\s*$/) {
-                                       unshift @blanks, pop @out;
-                               }
-                               foreach my $field (sort keys %changefields) {
-                                       if (length $changefields{$field}) {
-                                               push @out, "$field = $changefields{$field}\n";
-                                       }
-                               }
-                               push @out, @blanks;
+                               $addfields->();
                        }
 
                        $section=$1;
                        }
 
                        $section=$1;
@@ -586,7 +617,11 @@ sub modifyconfig {
                }
        }
 
                }
        }
 
-       if (%changefields) {
+       if (defined $section && 
+           $section eq $targetsection) {
+                       $addfields->();
+       }
+       elsif (%changefields) {
                push @out, "\n[$targetsection]\n";
                foreach my $field (sort keys %changefields) {
                        if (length $changefields{$field}) {
                push @out, "\n[$targetsection]\n";
                foreach my $field (sort keys %changefields) {
                        if (length $changefields{$field}) {
@@ -675,6 +710,36 @@ log =                                                      \
        else                                            \
                error "unknown repo type"               \
        fi
        else                                            \
                error "unknown repo type"               \
        fi
+register =                                                             \
+       if [ -n "$1" ]; then                                            \
+               cd "$1"                                                 \
+       fi                                                              \
+       basedir="$(basename $(pwd))"                                    \
+       if [ -d .svn ]; then                                            \
+               url=$(LANG=C svn info . |                               \
+                     grep -i ^URL: | cut -d ' ' -f 2)                  \
+               if [ -z "$url" ]; then                                  \
+                       error "cannot determine svn url"                \
+               fi                                                      \
+               echo "Registering svn url: $url"                        \
+               mr config "$(pwd)" checkout="svn co $url $basedir"      \
+       elif [ -d .git ]; then                                          \
+               url=$(LANG=C git-config --get remote.origin.url)        \
+               if [ -z "$url" ]; then                                  \
+                       error "cannot determine git url"                \
+               fi                                                      \
+               echo "Registering git url: $url"                        \
+               mr config "$(pwd)" checkout="git clone $url $basedir"   \
+       elif [ -d .bzr ]; then                                          \
+               url=$(cat .bzr/branch/parent)                           \
+               if [ -z "$url" ]; then                                  \
+                       error "cannot determine bzr url"                \
+               fi                                                      \
+               echo "Registering bzr url: $url"                        \
+               mr config "$(pwd)" checkout="bzr clone $url $basedir"   \
+       else                                                            \
+               error "unable to register this repo type"               \
+       fi
 list = true
 config = 
 help =                                                 \
 list = true
 config = 
 help =                                                 \