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

Brought back the "deleted" parameter, which provides an easy way to mark repositories...
[code/myrepos.git] / mr
diff --git a/mr b/mr
index 17f95859912aac266ae71b6e71dbb0ae0eb154c4..bd6c2d73d90656a332ec9f12acd6d1d47a1fd036 100755 (executable)
--- a/mr
+++ b/mr
@@ -377,6 +377,14 @@ part of the including file.
 Unlike all other parameters, this parameter does not need to be placed
 within a section.
 
+=item deleted
+
+If the "deleted" parameter is set and its command returns true, then
+B<mr> will treat the repository as deleted. It won't ever actually delete
+the repository, but it will warn if it sees the repository's directory.
+This is useful when one mrconfig file is shared amoung multiple machines,
+to keep track of and remember to delete old repositories.
+
 =item lib
 
 The "lib" parameter can specify some shell code that will be run before each
@@ -567,6 +575,37 @@ sub action {
        my $is_update=($action =~ /update/);
 
        $ENV{MR_REPO}=$dir;
+       
+       foreach my $testname ("skip", "deleted") {
+               my $testcommand=findcommand($testname, $dir, $topdir, $subdir, $is_checkout);
+
+               if (defined $testcommand) {
+                       my $test="set -e;".$lib.
+                               "my_action(){ $testcommand\n }; my_action '$action'";
+                       print "mr $action: running $testname test >>$test<<\n" if $verbose;
+                       my $ret=system($test);
+                       if ($ret != 0) {
+                               if (($? & 127) == 2) {
+                                       print STDERR "mr $action: interrupted\n";
+                                       return ABORT;
+                               }
+                               elsif ($? & 127) {
+                                       print STDERR "mr $action: $testname test received signal ".($? & 127)."\n";
+                                       return ABORT;
+                               }
+                       }
+                       if ($ret >> 8 == 0) {
+                               if ($testname eq "deleted") {
+                                       if (-d $dir) {
+                                               print STDERR "mr error: $dir should be deleted yet still exists\n";
+                                               return FAILED;
+                                       }
+                               }
+                               print "mr $action: skip $dir skipped\n" if $verbose;
+                               return SKIPPED;
+                       }
+               }
+       }
 
        if ($is_checkout) {
                if (! $force_checkout) {
@@ -584,30 +623,8 @@ sub action {
                }
        }
 
-       my $skiptest=findcommand("skip", $dir, $topdir, $subdir, $is_checkout);
        my $command=findcommand($action, $dir, $topdir, $subdir, $is_checkout);
 
-       if (defined $skiptest) {
-               my $test="set -e;".$lib.
-                       "my_action(){ $skiptest\n }; my_action '$action'";
-               print "mr $action: running skip test >>$test<<\n" if $verbose;
-               my $ret=system($test);
-               if ($ret != 0) {
-                       if (($? & 127) == 2) {
-                               print STDERR "mr $action: interrupted\n";
-                               return ABORT;
-                       }
-                       elsif ($? & 127) {
-                               print STDERR "mr $action: skip test received signal ".($? & 127)."\n";
-                               return ABORT;
-                       }
-               }
-               if ($ret >> 8 == 0) {
-                       print "mr $action: $dir skipped per config file\n" if $verbose;
-                       return SKIPPED;
-               }
-       }
-
        if ($is_checkout && ! -d $dir) {
                print "mr $action: creating parent directory $dir\n" if $verbose;
                system("mkdir", "-p", $dir);
@@ -1056,14 +1073,24 @@ sub is_trusted_checkout {
 }
 
 sub trusterror {
-       die shift()."\n".
-               "(To trust this file, list it in ~/.mrtrust.)\n";
+       my ($err, $file, $line, $url)=@_;
+       
+       if (defined $url) {
+               die "$err in untrusted $url line $line\n".
+                       "(To trust this url, --trust-all can be used; but please use caution;\n".
+                       "this can allow arbitrary code execution!)\n";
+       }
+       else {
+               die "$err in untrusted $file line $line\n".
+                       "(To trust this file, list it in ~/.mrtrust.)\n";
+       }
 }
 
 my %loaded;
 sub loadconfig {
        my $f=shift;
        my $dir=shift;
+       my $bootstrap_url=shift;
 
        my @toload;
 
@@ -1075,10 +1102,6 @@ sub loadconfig {
                $trusted=1;
        }
        else {
-               if (! -e $f) {
-                       return;
-               }
-
                my $absf=abs_path($f);
                if ($loaded{$absf}) {
                        return;
@@ -1113,6 +1136,10 @@ sub loadconfig {
                        }
                }
                
+               if (! -e $f) {
+                       return;
+               }
+
                print "mr: loading config $f\n" if $verbose;
                open($in, "<", $f) || die "mr: open $f: $!\n";
        }
@@ -1133,7 +1160,7 @@ sub loadconfig {
                                if (! is_trusted_repo($section) ||
                                    $section eq 'ALIAS' ||
                                    $section eq 'DEFAULT') {
-                                       trusterror "mr: illegal section \"[$section]\" in untrusted $f line $line";
+                                       trusterror("mr: illegal section \"[$section]\"", $f, $line, $bootstrap_url)
                                }
                        }
                        $section=expandenv($section) if $trusted;
@@ -1160,10 +1187,10 @@ sub loadconfig {
                                # Untrusted files can only contain checkout
                                # parameters.
                                if ($parameter ne 'checkout') {
-                                       trusterror "mr: illegal setting \"$parameter=$value\" in untrusted $f line $line";
+                                       trusterror("mr: illegal setting \"$parameter=$value\"", $f, $line, $bootstrap_url);
                                }
                                if (! is_trusted_checkout($value)) {
-                                       trusterror "mr: illegal checkout command \"$value\" in untrusted $f line $line";
+                                       trusterror("mr: illegal checkout command \"$value\"", $f, $line, $bootstrap_url);
                                }
                        }
 
@@ -1474,7 +1501,7 @@ sub bootstrap {
        # would normally be skipped.
        my $topdir=abs_path(".")."/";
        my @repo=($topdir, $topdir, ".");
-       loadconfig($tmpconfig, $topdir);
+       loadconfig($tmpconfig, $topdir, $url);
        record(\@repo, action("checkout", @repo, 1))
                if exists $config{$topdir}{"."}{"checkout"};