From efd0190b6e3560319edf0e26bb2f0787856db720 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 13 Nov 2010 23:12:45 -0500 Subject: [PATCH] Factor out semantics of RCS revisions and branches. --- rcs-fast-import | 50 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/rcs-fast-import b/rcs-fast-import index 0762826..5242852 100755 --- a/rcs-fast-import +++ b/rcs-fast-import @@ -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 -- 2.43.0