]> git.madduck.net Git - code/myrepos.git/commitdiff

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:

print included content as an included line number is not useful
authorJoey Hess <joey@kitenet.net>
Mon, 5 Dec 2011 17:23:53 +0000 (13:23 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 5 Dec 2011 17:23:53 +0000 (13:23 -0400)
Due to how includes work, a line number is not very helpful;
printing the actual included content is better.

Some associated refactoring.
(What I wouldn't give for a haskell where clause right about now..)

mr

diff --git a/mr b/mr
index 4dd3a07293076dbd4b49d643b2a598fc581b0273..ff30c16cefefc05d634638cb353bfa24c4229a15 100755 (executable)
--- a/mr
+++ b/mr
@@ -1119,20 +1119,6 @@ sub is_trusted_checkout {
        return 0;
 }
 
-sub trusterror {
-       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;
@@ -1197,30 +1183,43 @@ sub loadconfig {
 
        # Keep track of the current line in the config file;
        # when a file is included track the current line from the include.
-       my $line=0;
+       my $lineno=0;
        my $included=undef;
-       my $includeline=0;
+
+       my $line;
        my $nextline = sub {
                if ($included) {
-                       $includeline++;
                        $included--;
                }
                else {
                        $included=undef;
-                       $includeline=0;
-                       $line++;
+                       $lineno++;
                }
-               my $l=shift @lines;
-               chomp $l;
-               return $l
+               $line=shift @lines;
+               chomp $line;
+               return $line;
        };
        my $lineerror = sub {
                my $msg=shift;
                if (defined $included) {
-                       die "mr: $f line $line include line $includeline: $msg\n";
+                       die "mr: $f line $lineno included line '$line': $msg\n";
+               }
+               else {
+                       die "mr: $f line $lineno: $msg\n";
+               }
+       };
+       my $trusterror = sub {
+               my $msg=shift;
+               my ($err, $file, $lineno, $url)=@_;
+       
+               if (defined $bootstrap_url) {
+                       die "mr: $err in untrusted $bootstrap_url line $lineno\n".
+                               "(To trust this url, --trust-all can be used; but please use caution;\n".
+                               "this can allow arbitrary code execution!)\n";
                }
                else {
-                       die "mr: $f line $line: $msg\n";
+                       die "mr: $err in untrusted $file line $lineno\n".
+                               "(To trust this file, list it in ~/.mrtrust.)\n";
                }
        };
 
@@ -1228,7 +1227,7 @@ sub loadconfig {
                $_=$nextline->();
 
                if (! $trusted && /[[:cntrl:]]/) {
-                       trusterror("mr: illegal control character", $f, $line, $bootstrap_url);
+                       $trusterror->("illegal control character");
                }
 
                next if /^\s*\#/ || /^\s*$/;
@@ -1239,7 +1238,7 @@ sub loadconfig {
                                if (! is_trusted_repo($section) ||
                                    $section eq 'ALIAS' ||
                                    $section eq 'DEFAULT') {
-                                       trusterror("mr: illegal section \"[$section]\"", $f, $line, $bootstrap_url)
+                                       $trusterror->("illegal section \"[$section]\"");
                                }
                        }
                        $section=expandenv($section) if $trusted;
@@ -1266,7 +1265,7 @@ sub loadconfig {
                                # settings in specific known-safe formats.
                                if ($parameter eq 'checkout') {
                                        if (! is_trusted_checkout($value)) {
-                                               trusterror("mr: illegal checkout command \"$value\"", $f, $line, $bootstrap_url);
+                                               $trusterror->("illegal checkout command \"$value\"");
                                        }
                                }
                                elsif ($parameter eq 'order') {
@@ -1278,7 +1277,7 @@ sub loadconfig {
                                        # safe.
                                }
                                else {
-                                       trusterror("mr: illegal setting \"$parameter=$value\"", $f, $line, $bootstrap_url);
+                                       $trusterror->("illegal setting \"$parameter=$value\"");
                                }
                        }