]> thyrsus.com Git - src.git/commitdiff
Implemented and tested moveto.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 15:16:26 +0000 (10:16 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 15:16:26 +0000 (10:16 -0500)
src
src.asc
srctest

diff --git a/src b/src
index 399939d00007b26dc7556f18169b9869675ef110..6e90d4fa6d366f515ca9af94eed8e315bb41c475 100755 (executable)
--- a/src
+++ b/src
@@ -299,6 +299,9 @@ src diff ['revision-spec'] ['file'...]
    the working copy against the last version checked in. With one revno,
    diffs the working copy against that stored revision; with a range,
 
+src moveto 'directory' ['file'...]
+   Moves files and their histories to another directory.
+
 src fast-export ['file'...]
    Export one or more projects to standard output as a git fast-import stream.
    The committer identification is copied from your Git configuration.
@@ -306,15 +309,19 @@ src fast-export ['file'...]
 
 def init_method(*args):
     "Create a repo directory if none already exists."
-    if not os.path.exists(repodir):
+    if args:
+        target = os.path.join(args[0], ".src") 
+    else:
+        target = repodir
+    if not os.path.exists(target):
         try:
-            os.mkdir(repodir)
+            os.mkdir(target)
         except OSError:
             croak("creation failed, check directory permissions.")
-    elif os.path.isdir(repodir):
-        croak("%s already exists." % repodir)
+    elif os.path.isdir(target):
+        croak("%s already exists." % target)
     else:
-        croak("%s exists but is not a directory." % repodir)
+        croak("%s exists but is not a directory." % target)
 
 def preamble(cmd, args):
     "Common setup code."
@@ -657,6 +664,31 @@ def fast_export_method(*args):
                 if val in revrange:
                     sys.stdout.write("reset refs/tags/%s\nfrom :%d\n\n" % (key, markmap[val]))
 
+def moveto_method(*args):
+    "Register a file into src control."
+    (revspec, args) = preamble("moveto", args)
+    if revspec is not None:
+        croak("moveto doesn't take a revision spec")
+    if args:
+        target = args.pop(0)
+    else:
+        croak("moveto requires a sirectory argument")
+    if not os.path.exists(target):
+        croak("%s does not exist" % arg)
+    if not os.path.isdir(target):
+        croak("%s is not a directory" % arg)
+    init_method(target)
+    for arg in args:
+       if not os.path.exists(arg):
+           croak("I see no '%s' here." % arg)
+       elif not os.path.exists(master(arg)):
+           croak("%s is not registered, skipping." % arg)
+       else:
+           # Using mv(1) evades cross-filesystem issues
+           do_or_die("mv {0} {1} && mv {2} {3]/{4}".format(arg, target, master(arg), target, repodir)) 
+           if not quiet and len(args) > 1:
+              announce("%s -> %s" % target) 
+
 dispatch = {
     "help":        help_method,
     "init":        init_method,
@@ -671,6 +703,7 @@ dispatch = {
     "diff":        diff_method,
     "tag":         tag_method,
     "fast-export": fast_export_method,
+    "moveto":      moveto_method,
 }
 
 if __name__ == "__main__":
diff --git a/src.asc b/src.asc
index 27debb883ab1245d6dbea23b397a9d723b82fe55..febf04c4ee7bb272f9aa1336bc9dc0173b514957 100644 (file)
--- a/src.asc
+++ b/src.asc
@@ -82,6 +82,9 @@ src diff ['revision-spec'] ['file'...]
    the working copy against the last version checked in. With one revno,
    diffs the working copy against that stored revision; with a range,
 
+src moveto 'directory' ['file'...]
+   Moves files and their histories to another directory.
+
 src fast-export ['file'...]
    Export one or more projects as a git fast-import stream.
    The committer identification is copied from your Git configuration.
@@ -95,11 +98,11 @@ on, and the command is not a report generator (cat, log, list,
 fast-export, the listing modes of tag and branch) you will see a reply
 only if the operation failed.
 
-Other commands (add, commit, checkout, tag creation and deletion) give
-you a success message per file when operating on multiple files, so
-you will not be in doubt about which operation succeeded.  This
-behavior can be suppressed with the -q option, placed 'before' the 
-subcommand word.
+Other commands (add, commit, checkout, tag creation and deletion,
+moveto) give you a success message per file when operating on multiple
+files, so you will not be in doubt about which operation succeeded.
+This behavior can be suppressed with the -q option, placed 'before'
+the subcommand word.
 
 == DEBUGGING OPTIONS ==
 
@@ -117,9 +120,8 @@ It also attributes all commits to J. Random Hacker and sets a
 constant screen witch of 79. It's for regression testing.
 
 == DANGER! DANGER! ==
-This is a proof-of-concept alpha release. The 'branch' and
-'fast-export' commands are not yet implemented; they are
-described here to document the design.
+This is a proof-of-concept alpha release. The 'branch' command is not
+yet implemented; it is described here to document the design.
 
 == IMPLEMENTATION NOTE ==
 SRC presently uses RCS for back-end storage. This may change in the future.
diff --git a/srctest b/srctest
index 2514af3b5cc85fea47aa6f58d998d5b6cbd4c30f..3220549eb162d04f4e0e2eea7e4a0f4424ce2e1a 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -6,7 +6,7 @@
 # Needs to not be a subdirectory of here, or git gets confused
 SANDBOX=/tmp/src-sandbox
 
-trap "rm -f testfile* $SANDBOX/testfile*" 0 1 2 15
+trap "rm -fr $SANDBOX" 0 1 2 15
 
 check() {
     case $? in
@@ -167,4 +167,8 @@ cat testfile14 | (cd $SANDBOX/foo >/dev/null; git init --quiet; git fast-import
 diff -u testfile14 testfile15
 check "fast-export" 
 
+mkdir $SANDBOX/bar
+src $TESTOPTS moveto $SANDBOX/bar
+check "moveto"
+
 # end