X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/f9f7242bc46863624b9096d0bcda50bbc098aa49..677f2c478ccc89aa2f30c4407e26bc568d8b5532:/mr diff --git a/mr b/mr index 3996b60..fc63605 100755 --- a/mr +++ b/mr @@ -602,7 +602,7 @@ sub action { my $is_checkout=($action eq 'checkout'); my $is_update=($action =~ /update/); - $ENV{MR_REPO}=$dir; + ($ENV{MR_REPO}=$dir) =~ s!/$!!; $ENV{MR_ACTION}=$action; foreach my $testname ("skip", "deleted") { @@ -946,7 +946,10 @@ sub repodir { return $ret; } -# figure out which repos to act on +# Figure out which repos to act on. Returns a list of array refs +# in the format: +# +# [ "$full_repo_path/", "$mr_config_path/", $section_header ] sub selectrepos { my @repos; foreach my $repo (repolist()) { @@ -1179,11 +1182,43 @@ sub loadconfig { close $in unless ref $f eq 'GLOB'; my $section; + + # 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 $included=undef; + my $includeline=0; + my $nextline = sub { + if ($included) { + $includeline++; + $included--; + } + else { + $included=undef; + $includeline=0; + $line++; + } + my $l=shift @lines; + chomp $l; + return $l + }; + my $lineerror = sub { + my $msg=shift; + if (defined $included) { + die "mr: $f line $line include line $includeline: $msg\n"; + } + else { + die "mr: $f line $line: $msg\n"; + } + }; + while (@lines) { - $_=shift @lines; - $line++; - chomp; + $_=$nextline->(); + + if (! $trusted && /[[:cntrl:]]/) { + trusterror("mr: illegal control character", $f, $line, $bootstrap_url); + } + next if /^\s*\#/ || /^\s*$/; if (/^\[([^\]]*)\]\s*$/) { $section=$1; @@ -1209,10 +1244,9 @@ sub loadconfig { # continued value while (@lines && $lines[0]=~/^\s(.+)/) { - shift(@lines); - $line++; $value.="\n$1"; chomp $value; + $nextline->(); } if (! $trusted) { @@ -1238,15 +1272,17 @@ sub loadconfig { if ($parameter eq "include") { print "mr: including output of \"$value\"\n" if $verbose; - unshift @lines, `$value`; + my @inc=`$value`; if ($?) { print STDERR "mr: include command exited nonzero ($?)\n"; } + $included += @inc; + unshift @lines, @inc; next; } if (! defined $section) { - die "$f line $.: parameter ($parameter) not in section\n"; + $lineerror->("parameter ($parameter) not in section"); } if ($section eq 'ALIAS') { $alias{$parameter}=$value; @@ -1265,7 +1301,7 @@ sub loadconfig { if ($parameter eq 'chain' && length $dir && $section ne "DEFAULT") { my $chaindir="$section"; - if ($chaindir !~ m!/!) { + if ($chaindir !~ m!^/!) { $chaindir=$dir.$chaindir; } if (-e "$chaindir/.mrconfig") { @@ -1287,7 +1323,7 @@ sub loadconfig { } } else { - die "$f line $line: parse error\n"; + $lineerror->("parse error"); } }