]> thyrsus.com Git - src.git/commitdiff
Implemented copyto
authorEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 15:22:09 +0000 (10:22 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 15:22:09 +0000 (10:22 -0500)
src
src.asc

diff --git a/src b/src
index 6e90d4fa6d366f515ca9af94eed8e315bb41c475..4c8127e38d14ee9163d14dc957cb69c158f834e4 100755 (executable)
--- a/src
+++ b/src
@@ -302,6 +302,9 @@ src diff ['revision-spec'] ['file'...]
 src moveto 'directory' ['file'...]
    Moves files and their histories to another directory.
 
+src copyto 'directory' ['file'...]
+   Copies 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.
@@ -665,7 +668,7 @@ def fast_export_method(*args):
                     sys.stdout.write("reset refs/tags/%s\nfrom :%d\n\n" % (key, markmap[val]))
 
 def moveto_method(*args):
-    "Register a file into src control."
+    "Move a file and its history to another directory."
     (revspec, args) = preamble("moveto", args)
     if revspec is not None:
         croak("moveto doesn't take a revision spec")
@@ -687,7 +690,32 @@ def moveto_method(*args):
            # 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) 
+              announce("%s -> %s" % target)
+
+def copyto_method(*args):
+    "Copy a file and its history to another directory."
+    (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 cp(1) evades cross-filesystem issues
+           do_or_die("cp {0} {1} && cp {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,
@@ -704,6 +732,7 @@ dispatch = {
     "tag":         tag_method,
     "fast-export": fast_export_method,
     "moveto":      moveto_method,
+    "copyto":      copyto_method,
 }
 
 if __name__ == "__main__":
diff --git a/src.asc b/src.asc
index febf04c4ee7bb272f9aa1336bc9dc0173b514957..539fed349a62789ff4e9eb9bbdd1e1fad5fe83d6 100644 (file)
--- a/src.asc
+++ b/src.asc
@@ -85,6 +85,9 @@ src diff ['revision-spec'] ['file'...]
 src moveto 'directory' ['file'...]
    Moves files and their histories to another directory.
 
+src copyto 'directory' ['file'...]
+   Copies 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.