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
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)
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"
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:
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