]> thyrsus.com Git - src.git/commitdiff
Refactor to remove duplicative code.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 18:51:46 +0000 (13:51 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 18:51:46 +0000 (13:51 -0500)
src

diff --git a/src b/src
index aede05d07e68e05b5ebef74ae829a07940ce378d..99d99b952bf7da0b7ec48994ff210dd4eb173c05 100755 (executable)
--- a/src
+++ b/src
@@ -671,15 +671,14 @@ 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):
-    "Move a file and its history to another directory."
-    (revspec, args) = preamble("moveto", args)
+def dircmd(legend, hook, args):
+    (revspec, args) = preamble(legend, args)
     if revspec is not None:
-        croak("moveto doesn't take a revision spec")
+        croak("%s doesn't take a revision spec" % legend)
     if args:
         target = args.pop(0)
     else:
-        croak("moveto requires a sirectory argument")
+        croak("%s requires a directory argument" % legend)
     if not os.path.exists(target):
         croak("%s does not exist" % arg)
     if not os.path.isdir(target):
@@ -691,33 +690,17 @@ def moveto_method(*args):
        elif not os.path.exists(backend.master(arg)):
            croak("%s is not registered, skipping." % arg)
        else:
-           backend.moveto(arg, target)
+           hook(arg, target)
            if not quiet and len(args) > 1:
               announce("%s -> %s" % target)
 
+def moveto_method(*args):
+    "Move a file and its history to another directory."
+    dircmd("moveto", backend.moveto, args)
+
 def copyto_method(*args):
     "Copy a file and its history to another directory."
-    (revspec, args) = preamble("copyto", 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(backend.master(arg)):
-           croak("%s is not registered, skipping." % arg)
-       else:
-           backend.copyto(arg, target)
-           if not quiet and len(args) > 1:
-              announce("%s -> %s" % target)
+    dircmd("copyto", backend.copyto, args)
 
 def ls_method(*args):
     "List registered files."