X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/af1ece782ef8ad328a97bed416a2793f9c56fc35..d1e21e723b6deb2263449195f6e63e5246d2e8b5:/mr diff --git a/mr b/mr index 8eb0374..c5efb74 100755 --- a/mr +++ b/mr @@ -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}) { @@ -703,7 +716,7 @@ register = \ cd "$1" \ basedir="$(basename $(pwd))" \ if [ -d .svn ]; then \ - url=$(svn info . | \ + url=$(LANG=C svn info . | \ grep -i ^URL: | cut -d ' ' -f 2) \ if [ -z "$url" ]; then \ error "cannot determine svn url" \ @@ -711,12 +724,19 @@ register = \ echo "Registering svn url: $url" \ mr config "$(pwd)" checkout="svn co $url $basedir" \ elif [ -d .git ]; then \ - url=$(git-config --get remote.origin.url) \ + url=$(LANG=C git-config --get remote.origin.url) \ if [ -z "$url" ]; then \ error "cannot determine git url" \ fi \ echo "Registering git url: $url" \ mr config "$(pwd)" checkout="git clone $url $basedir" \ + elif [ -d .bzr ]; then \ + url=$(cat .bzr/branch/parent) \ + if [ -z "$url" ]; then \ + error "cannot determine bzr url" \ + fi \ + echo "Registering bzr url: $url" \ + mr config "$(pwd)" checkout="bzr clone $url $basedir" \ else \ error "unable to register this repo type" \ fi