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

bugfixes developed while writing blog post
[code/myrepos.git] / mr
diff --git a/mr b/mr
index c6d74e9cf11daf8e63a5c681d8b648778b7f0bcc..96f3a16cbd4f2332194823ae9126dcb1ba16faf6 100755 (executable)
--- a/mr
+++ b/mr
@@ -89,9 +89,9 @@ 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:
+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
 
@@ -103,10 +103,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"
 
-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
 
@@ -346,7 +346,7 @@ sub action {
 
        if (exists $config{$topdir}{$subdir}{deleted}) {
                if (! -d $dir) {
-                       next;
+                       return;
                }
                else {
                        my $test="set -e;".$lib.$config{$topdir}{$subdir}{deleted};
@@ -463,6 +463,10 @@ sub loadconfig {
                $dir="";
        }
        else {
+               if (! -e $f) {
+                       return;
+               }
+
                my $absf=abs_path($f);
                if ($loaded{$absf}) {
                        return;
@@ -551,14 +555,28 @@ sub modifyconfig {
        my %changefields=@_;
 
        my @lines;
+       my @out;
+
        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 @out;
        while (@lines) {
                $_=shift(@lines);
 
@@ -568,16 +586,7 @@ sub modifyconfig {
                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;
@@ -607,7 +616,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}) {
@@ -708,14 +721,14 @@ register =                                                                \
                if [ -z "$url" ]; then                                  \
                        error "cannot determine svn url"                \
                fi                                                      \
-               echo "Found svn url: $url"                              \
+               echo "Registering svn url: $url"                        \
                mr config "$(pwd)" checkout="svn co $url $basedir"      \
        elif [ -d .git ]; then                                          \
                url=$(git-config --get remote.origin.url)               \
                if [ -z "$url" ]; then                                  \
                        error "cannot determine git url"                \
                fi                                                      \
-               echo "Found git url: $url"                              \
+               echo "Registering git url: $url"                        \
                mr config "$(pwd)" checkout="git clone $url $basedir"   \
        else                                                            \
                error "unable to register this repo type"               \