X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/c5af54402038777a9fd81bc731313c12b1828fc9..abf6cf51bad2cff8877412f018e7c9a54b9a266e:/mr diff --git a/mr b/mr index 2b5c656..01a9feb 100755 --- a/mr +++ b/mr @@ -120,11 +120,22 @@ registers several additional repositories. The .mrconfig file uses a variant of the INI file format. Lines starting with "#" are comments. Lines ending with "\" are continued on to the next line. -Sections specify where each repository is located, relative to the + +The "default" section allows setting default values for the sections that +come after it. + +The "alias" section allows adding aliases for actions. Each parameter +is an alias, and its value is the action to use. + +All other sections specify where each repository is located, relative to the directory that contains the .mrconfig file. Within a section, each parameter defines a shell command to run to handle a -given action. Note that these shell commands are run in a "set -e" shell +given action. mr contains default handlers for the "update", "status", and +"commit" actions, so normally you only need to specify what to do for +"checkout". + +Note that these shell commands are run in a "set -e" shell environment, where any additional parameters you pass are available in "$@". The "checkout" command is run in the parent of the repository directory, since the repository isn't checked out yet. All other commands @@ -141,14 +152,6 @@ should avoid chaining from repositories with untrusted committers.) The command, this can be a useful way to define shell functions for other commands to use. -The "default" section allows setting up default handlers for each action, -and is overridden by the contents of other sections. mr contains default -handlers for the "update", "status", and "commit" actions, so normally -you only need to specify what to do for "checkout". - -The "alias" section allows adding aliases for actions. Each parameter -is an alias, and its value is the action to use. - For example: [src] @@ -215,24 +218,22 @@ eval { # alias expansion and command stemming my $action=shift @ARGV; +if (exists $alias{$action}) { + $action=$alias{$action}; +} if (! exists $knownactions{$action}) { - if (exists $alias{$action}) { - $action=$alias{$action}; + my @matches = grep { /^\Q$action\E/ } + keys %knownactions, keys %alias; + if (@matches == 1) { + $action=$matches[0]; + } + elsif (@matches == 0) { + die "mr: unknown action \"$action\" (known actions: ". + join(", ", sort keys %knownactions).")\n"; } else { - my @matches = grep { /^\Q$action\E/ } - keys %knownactions, keys %alias; - if (@matches == 1) { - $action=$matches[0]; - } - elsif (@matches == 0) { - die "mr: unknown action \"$action\" (known actions: ". - join(", ", sort keys %knownactions).")\n"; - } - else { - die "mr: ambiguous action \"$action\" (matches: ". - join(", ", @matches).")\n"; - } + die "mr: ambiguous action \"$action\" (matches: ". + join(", ", @matches).")\n"; } } @@ -295,21 +296,23 @@ sub action { } $ENV{MR_REPO}=$dir; - if (! $nochdir && ! chdir($dir)) { - print STDERR "mr $action: failed to chdir to $dir: $!\n"; - push @skipped, $dir; - } if (exists $config{$topdir}{$subdir}{skip}) { - my $ret=system($lib.$config{$topdir}{$subdir}{skip}); + my $test="set -e;".$lib.$config{$topdir}{$subdir}{skip}; + print "mr $action: running skip test $test\n" if $verbose; + my $ret=system($test); if ($ret >> 8 == 0) { print "mr $action: $dir skipped per config file\n" if $verbose; push @skipped, $dir; return; } } - - if (! exists $config{$topdir}{$subdir}{$action}) { + + if (! $nochdir && ! chdir($dir)) { + print STDERR "mr $action: failed to chdir to $dir: $!\n"; + push @failed, $dir; + } + elsif (! exists $config{$topdir}{$subdir}{$action}) { print STDERR "mr $action: no defined $action command for $topdir$subdir, skipping\n"; push @skipped, $dir; } @@ -323,9 +326,10 @@ sub action { my $command="set -e; ".$lib. "my_action(){ $config{$topdir}{$subdir}{$action} ; }; my_action ". join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV); + print STDERR "mr $action: running $command\n" if $verbose; my $ret=system($command); if ($ret != 0) { - print STDERR "mr $action: failed to run: $command\n" if $verbose; + print STDERR "mr $action: failed ($ret)\n" if $verbose; push @failed, $topdir.$subdir; if ($ret >> 8 != 0) { print STDERR "mr $action: command failed\n"; @@ -467,17 +471,21 @@ __DATA__ co = checkout ci = commit ls = list + [default] lib = \ error() { \ echo "mr: $@" >&2; \ exit 1; \ } + update = \ if [ -d "$MR_REPO"/.svn ]; then \ svn update "$@"; \ elif [ -d "$MR_REPO"/.git ]; then \ git pull origin master "$@"; \ + elif [ -d "$MR_REPO"/CVS ]; then \ + cvs update "$@"; \ else \ error "unknown repo type"; \ fi @@ -486,6 +494,8 @@ status = \ svn status "$@"; \ elif [ -d "$MR_REPO"/.git ]; then \ git status "$@" || true; \ + elif [ -d "$MR_REPO"/CVS ]; then \ + cvs status "$@"; \ else \ error "unknown repo type"; \ fi @@ -494,6 +504,8 @@ commit = \ svn commit "$@"; \ elif [ -d "$MR_REPO"/.git ]; then \ git commit -a "$@" && git push --all; \ + elif [ -d "$MR_REPO"/CVS ]; then \ + cvs commit "$@"; \ else \ error "unknown repo type"; \ fi @@ -502,6 +514,8 @@ diff = \ svn diff "$@"; \ elif [ -d "$MR_REPO"/.git ]; then \ git diff "$@"; \ + elif [ -d "$MR_REPO"/CVS ]; then \ + cvs diff "$@"; \ else \ error "unknown repo type"; \ fi @@ -510,13 +524,19 @@ log = \ svn log"$@"; \ elif [ -d "$MR_REPO"/.git ]; then \ git log "$@"; \ + elif [ -d "$MR_REPO"/CVS ]; then \ + cvs log "$@"; \ else \ error "unknown repo type"; \ fi list = true + help = \ if [ ! -e "$MR_PATH" ]; then \ error "cannot find program path";\ fi; \ (pod2man -c mr "$MR_PATH" | man -l -) || \ error "pod2man or man failed" + +ed = echo "A horse is a horse, of course, of course.." +T = echo "I pity the fool."