]> thyrsus.com Git - rcs-fast-import.git/commitdiff
Factor out semantics of RCS revisions and branches.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 14 Nov 2010 04:12:45 +0000 (23:12 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 14 Nov 2010 04:12:45 +0000 (23:12 -0500)
rcs-fast-import

index 0762826ce81d7fa0c8bdc9036b6b01d39fc98589..524285270a536e05aa4b7802b854c0ba39cbb044 100755 (executable)
@@ -538,6 +538,15 @@ class Repository:
     def __setitem__(self, i, v):
         self.events[i] = v
 
+def sanecheck(event, path, mode, copyfile):
+    "Sanity-check an operation to see if we can cope."
+    if mode == "160000":
+        raise FatalException("ignoring a submodule link %s", path)
+    elif mode == "120000":
+        raise FatalException("ignoring a symlink %s", path)
+    if not mode[-3:] in ('644', '755'):
+        raise FatalException("unknown mode %s on %s", (mode, path))
+
 def complain(msg):
     print >>sys.stderr, "rcs-fast-import:", msg
 
@@ -635,7 +644,7 @@ class Generic:
         loud_remove(path)
     def modify(self, event, path, mode, copyfile):
         "Perform file checkins and modifications,"
-        self.sanecheck(event, path, mode, copyfile)
+        sanecheck(event, path, mode, copyfile)
         self.instantiate(path, copyfile)
         self.supercheckin(event, "M", path, "modify")
         #self.record("M", path)
@@ -660,6 +669,27 @@ class Generic:
         self.copy(commit, source, target, legend="Rename")
         self.delete(commit, source, legend="Rename")
 
+class RCSRev:
+    "Encapsulate operations on an RCS ID."
+    def __init__(self, rev=None):
+        if rev is None:
+            self.rev = [1, 1]
+        else:
+            self.rev = rev
+    def __hash__(self):
+        "Make these valid dictionary keys,"
+        return hash(tuple(self.rev))
+    def successor(self):
+        "Return the successor of this ID."
+        s = RCSRev(self.rev)
+        s.rev[-1] += 1
+        return s
+    def branch(self, branchnum):
+        "Return ID for the tip of a new branch."
+        return RCSRev(self.rev + [branchnum, 1])
+    def __str__(self):
+        return ".".join(map(str, self.rev))
+
 class RCS(Generic):
     "Class encapsulating RCS version-control operations."
     repodirectory = "RCS"
@@ -667,18 +697,11 @@ class RCS(Generic):
     def __init__(self):
         Generic.__init__(self)
         self.branch_tips = {}
-    def sanecheck(self, event, path, mode, copyfile):
-        if mode == "160000":
-            raise FatalException("ignoring a submodule link %s", path)
-        elif mode == "120000":
-            raise FatalException("ignoring a symlink %s", path)
-        if not mode[-3:] in ('644', '755'):
-            raise FatalException("unknown mode %s on %s", (mode, path))
     def checkin(self, commit, comment, op, path):
         "Check in a new revision - also used to create new masters."
         # This is the only manipulation of the branch structure there is.
         if not os.path.exists(self.master(path)):
-            myrev = "1.1"
+            myrev = RCSRev()
         else:
             parents = commit.parents()
             if len(parents) > 1:
@@ -695,17 +718,14 @@ class RCS(Generic):
                     tip = self.branch_tips[(path, ancestor.branch)]
                     break
             if ancestor.branch == commit.branch:
-                # Not going down a branch point.  Just bump the last
-                # field of the tip revision.
-                fields = map(int, tip.split("."))
-                fields[-1] += 1
-                myrev = ".".join(map(str, fields))
+                # Not going down a branch point.
+                myrev = tip.successor()
             else:
                 # Going down a branch point.
                 if commit.branch not in parents[0].childbranches:
                     parents[0].childbranches.append(commit.branch)
                 branchnum = parents[0].childbranches.index(commit.branch) + 1
-                myrev = tip + "." + `branchnum` + ".1"
+                myrev = tip.branch(branchnum)
         if verbose >= DEBUG_BRANCHING:
             print "Assigning", myrev, "to", path
         self.branch_tips[(path, commit.branch)] = myrev