]> 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:

implemented mr register
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 12 Oct 2007 23:14:17 +0000 (19:14 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 12 Oct 2007 23:14:17 +0000 (19:14 -0400)
TODO
mr

diff --git a/TODO b/TODO
index 000d5abbe7376caa7ed5efb0b745aaa530835df0..fe3550677c7ae1001d99a77ff341481c32efe496 100644 (file)
--- a/TODO
+++ b/TODO
   renamedfrom = src/foo/bar
 
   (Support multple renames of a single repo?)
-
-* mr register
-
-  Idea is you check out a repo and then use mr register to add it to the
-  closest mrconfig file.
-
-  mr register would be implemented as a shell command that then calls
-  mr config with flags that make it edit the mrconfig file:
-
-  if [ -d "$MR_REPO/.svn" ]; then
-       url=$(svn info "$MR_REPO" | grep -i ^URL: | cut -d ' ' -f 2)
-       if [ -z "$url" ]; then
-               error "cannot determine svn url"
-       fi
-       mr -c "$MR_CONFIG" config --add "$MR_REPO" --checkout="svn co $URL"
-  fi
diff --git a/mr b/mr
index 235c17518ad546c868086b8dcb73e931d7c95794..c6d74e9cf11daf8e63a5c681d8b648778b7f0bcc 100755 (executable)
--- a/mr
+++ b/mr
@@ -18,6 +18,8 @@ B<mr> [options] diff
 
 B<mr> [options] log
 
+B<mr> [options] register repository
+
 B<mr> [options] config section [parameter=[value] ...]
 
 B<mr> [options] action [params ...]
@@ -76,12 +78,18 @@ Show the commit log.
 
 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.
+
 =item config
 
 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:
+"parameter=value". Use "parameter=" to remove a parameter. 
+
+For example, to register a new svn repository in src/foo:
 
   mr config src/foo checkout="svn co svn://example.com/foo/trunk"
 
@@ -259,13 +267,20 @@ if (! exists $knownactions{$action}) {
 }
 
 if ($action eq 'help') {
-       exec($config{''}{DEFAULT}{help});
+       exec($config{''}{DEFAULT}{$action}) || die "exec: $!";
 }
 elsif ($action eq 'config') {
        if (@ARGV < 2) {
                die "mr config: not enough parameters\n";
        }
        my $section=shift;
+       if ($section=~/^\//) {
+               # try to convert to a path relative to $config's dir
+               my ($dir)=$config=~/^(.*\/)[^\/]+$/;
+               if ($section=~/^\Q$dir\E(.*)/) {
+                       $section=$1;
+               }
+       }
        my %fields;
        foreach (@ARGV) {
                if (/^([^=]+)=(.*)$/) {
@@ -278,6 +293,13 @@ elsif ($action eq 'config') {
        modifyconfig($config, $section, %fields);
        exit 0;
 }
+elsif ($action eq 'register') {
+       my $command="set -e; ".$config{''}{DEFAULT}{lib}."\n".
+               "my_action(){ $config{''}{DEFAULT}{$action}\n }; my_action ".
+               join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
+       print STDERR "mr $action: running >>$command<<\n" if $verbose;
+       exec($command) || die "exec: $!";
+}
 
 # work out what repos to act on
 my @repos;
@@ -441,7 +463,6 @@ sub loadconfig {
                $dir="";
        }
        else {
-               # $f might be a symlink
                my $absf=abs_path($f);
                if ($loaded{$absf}) {
                        return;
@@ -675,6 +696,30 @@ log =                                                      \
        else                                            \
                error "unknown repo type"               \
        fi
+register =                                                             \
+       if [ -z "$1" ]; then                                            \
+               error "repository directory not specified"              \
+       fi                                                              \
+       cd "$1"                                                         \
+       basedir="$(basename $(pwd))"                                    \
+       if [ -d .svn ]; then                                            \
+               url=$(svn info . |                                      \
+                     grep -i ^URL: | cut -d ' ' -f 2)                  \
+               if [ -z "$url" ]; then                                  \
+                       error "cannot determine svn url"                \
+               fi                                                      \
+               echo "Found svn url: $url"                              \
+               mr config "$(pwd)" checkout="svn co $url $basedir"      \
+       elif [ -d .git ]; then                                          \
+               url=$(git-config --get remote.origin.url)               \
+               if [ -z "$url" ]; then                                  \
+                       error "cannot determine git url"                \
+               fi                                                      \
+               echo "Found git url: $url"                              \
+               mr config "$(pwd)" checkout="git clone $url $basedir"   \
+       else                                                            \
+               error "unable to register this repo type"               \
+       fi
 list = true
 config = 
 help =                                                 \