X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/681a17143709b01f67a2d91b099247fba1a9626e..fb4c5ab3cf865b15d2092ccbc90aa5f7bd416c16:/mr?ds=sidebyside diff --git a/mr b/mr index c6d74e9..b65e623 100755 --- a/mr +++ b/mr @@ -18,7 +18,7 @@ B [options] diff B [options] log -B [options] register repository +B [options] register [repository] B [options] config section [parameter=[value] ...] @@ -80,8 +80,9 @@ List the repositories that mr will act on. =item register -The next parameter is the directory of an existing repository. The -repository will be registered in the mrconfig file. +Register an existing repository in the mrconfig file. By default, the +epository in the current directory is registered, or you can specify a +directory to register. =item config @@ -89,9 +90,9 @@ Modifies the mrconfig file. The next parameter is the name of the section to add or modify, and it is followed by one or more instances of "parameter=value". Use "parameter=" to remove a parameter. -For example, to register a new svn repository in src/foo: +For example, to add (or edit) a repository in src/foo: - mr config src/foo checkout="svn co svn://example.com/foo/trunk" + mr config src/foo checkout="svn co svn://example.com/foo/trunk foo" =item help @@ -103,10 +104,10 @@ Actions can be abbreviated to any unambiguous subsctring, so "mr st" is equivilant to "mr status", and "mr up" is equivilant to "mr update" -Additional parameters can be passed to other commands than "commit", they -will be passed on unchanged to the underlying revision control system. -This is mostly useful if the repositories mr will act on all use the same -revision control system. +Additional parameters can be passed to most commands, and are passed on +unchanged to the underlying revision control system. This is mostly useful +if the repositories mr will act on all use the same revision control +system. =head1 OPTIONS @@ -346,7 +347,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 +464,10 @@ sub loadconfig { $dir=""; } else { + if (! -e $f) { + return; + } + my $absf=abs_path($f); if ($loaded{$absf}) { return; @@ -551,14 +556,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 +587,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 +617,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}) { @@ -697,26 +711,32 @@ log = \ error "unknown repo type" \ fi register = \ - if [ -z "$1" ]; then \ - error "repository directory not specified" \ + if [ -n "$1" ]; then \ + cd "$1" \ fi \ - 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" \ fi \ - echo "Found svn url: $url" \ + 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 "Found git url: $url" \ + 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