]> thyrsus.com Git - rcs-fast-import.git/commitdiff
Yet more refactoring.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 13 Nov 2010 21:24:09 +0000 (16:24 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 13 Nov 2010 21:24:09 +0000 (16:24 -0500)
rcs-fast-import

index 16f1bdc5d0d4464b0e65561747f05982f2715c01..c42bbf0b73556addb63ae81c1dc9c7e183a3e2c6 100755 (executable)
@@ -569,30 +569,30 @@ def loud_rename(source, target):
 #
 # All VCS-specific code is beyond this point.  At the moment there's
 # just one VCS class, for RCS, but it would be easy to write another
-# for, say, SCCS.
+# subclass for, say, SCCS.
 #
+# The Generic class assumes that the VCS is file-oriented and that
+# the checkout tool can operate from a top-level directory to check
+# our working-file paths. It also assumes that we have to stuff
+# commit metadata in comments as RFC822 headers if we want to keep it.
 
 class Generic:
     "Generic file-oriented VCS - could be used for, say. SCCS as well as RCS."
     def __init__(self):
         self.roundtrip = False
         if verbose:
-            if not os.path.exists(self.__class__.repodir):
+            if not os.path.exists(self.__class__.repodirectory):
                 try:
-                    os.makedirs(self.__class__.repodir)
+                    os.makedirs(self.__class__.repodirectory)
                 except OSError:
                     raise FatalException("can't create RCS directory.")
     def master(self, filename):
         "Return the master file corresponding to a specified filename."
         parts = list(os.path.split(filename))
-        parts.insert(-1, self.__class__.repodir)
-        return os.path.join(*parts) + ",v"
-    def rename(self, commit, source, target):
-        "Perform RCS renames, carrying history with the rename."
-        self.copy(commit, source, target, legend="Rename")
-        self.delete(commit, source, legend="Rename")
+        parts.insert(-1, self.__class__.repodirectory)
+        return self.__class__.mastertemplate % os.path.join(*parts)
     def instantiate(self, path, copyfile=None):
-        rcsdir = os.path.join(os.path.dirname(path), self.__class__.repodir)
+        rcsdir = os.path.join(os.path.dirname(path), self.__class__.repodirectory)
         if not os.path.exists(rcsdir):
             try:
                 os.makedirs(rcsdir)
@@ -611,7 +611,7 @@ class Generic:
         "List all masters."
         res = []
         for root, dirs, files in os.walk(os.getcwd(), topdown=False):
-            if root.endswith(os.sep + self.__class__.repodir):
+            if root.endswith(os.sep + self.__class__.repodirectory):
                 for name in files:
                     res.append(os.path.join(root, name))
         return res
@@ -648,10 +648,15 @@ class Generic:
         open(path, "w").close()
         self.supercheckin(commit, "D", path, "delete")
         #self.record("D", path)
+    def rename(self, commit, source, target):
+        "Perform RCS renames, carrying history with the rename."
+        self.copy(commit, source, target, legend="Rename")
+        self.delete(commit, source, legend="Rename")
 
 class RCS(Generic):
     "Class encapsulating RCS version-control operations."
-    repodir = "RCS"
+    repodirectory = "RCS"
+    mastertemplate = "%s,v"
     def gethdr(self, path, header):
         "Retrieve a required header from a master file"
         master = self.master(path)
@@ -755,7 +760,8 @@ if __name__ == '__main__':
                         else:
                             raise FatalException("unknown op type %s" % op.op)
                     vcs.postcommit(event)
-                loud_rename(vcs.repodir, os.path.join(here, vcs.repodir))
+                loud_rename(vcs.repodirectory,
+                            os.path.join(here, vcs.repodirectory))
                 os.chdir(here)
             finally:
                 nuke(tempdir, "cleaning up")