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

* Add the -n switch, for disabling recursion.
[code/myrepos.git] / mr
diff --git a/mr b/mr
index d4c3b250f1a6bca1d86454e3998c730f8041d827..44fb671e856749684eff8f98b4a7ed9ac2c270dd 100755 (executable)
--- a/mr
+++ b/mr
@@ -146,6 +146,11 @@ Be verbose.
 Expand the statistics line displayed at the end to include information
 about exactly which repositories failed and were skipped, if any.
 
+=item -n
+
+Just operate on the repository for the current directory, do not 
+recurse into deeper repositories.
+
 =back
 
 =head1 FILES
@@ -259,6 +264,7 @@ $ENV{MR_CONFIG}="$ENV{HOME}/.mrconfig";
 my $directory=getcwd();
 my $verbose=0;
 my $stats=0;
+my $no_recurse=0;
 my %config;
 my %knownactions;
 my %alias;
@@ -269,6 +275,7 @@ my $result=GetOptions(
        "c|config=s" => sub { $ENV{MR_CONFIG}=abs_path($_[1]) },
        "v|verbose" => \$verbose,
        "s|stats" => \$stats,
+       "n|no-recurse" => \$no_recurse,
 );
 if (! $result || @ARGV < 1) {
        die("Usage: mr [-d directory] action [params ...]\n".
@@ -316,7 +323,7 @@ elsif ($action eq 'config') {
        }
        my $section=shift;
        if ($section=~/^\//) {
-               # try to convert to a path relative to $config's dir
+               # try to convert to a path relative to the config file
                my ($dir)=$ENV{MR_CONFIG}=~/^(.*\/)[^\/]+$/;
                if ($section=~/^\Q$dir\E(.*)/) {
                        $section=$1;
@@ -362,7 +369,8 @@ foreach my $topdir (sort keys %config) {
                my $d=$directory;
                $dir.="/" unless $dir=~/\/$/;
                $d.="/" unless $d=~/\/$/;
-               next if $dir ne $directory && $dir !~ /^\Q$directory\E/;
+               next if $no_recurse && $d ne $dir;
+               next if $dir ne $d && $dir !~ /^\Q$d\E/;
                push @repos, [$dir, $topdir, $subdir];
        }
 }
@@ -426,7 +434,13 @@ sub action { #{{{
                        push @skipped, $dir;
                        return;
                }
+
                $dir=~s/^(.*)\/[^\/]+\/?$/$1/;
+
+               if (! -d $dir) {
+                       print "mr $action: creating parent directory $dir\n" if $verbose;
+                       my $ret=system("mkdir", "-p", $dir);
+               }
        }
        elsif ($action eq 'update') {
                if (! -d $dir) {
@@ -531,7 +545,7 @@ if ($stats) {
                print "mr $action: (skipped: ".join(" ", @skipped).")\n";
        }
        if (@failed) {
-               print "mr $action: (failed: ".join(" ", @failed).")\n";
+               print STDERR "mr $action: (failed: ".join(" ", @failed).")\n";
        }
 }
 if (@failed) {