From: Mike Fleetwood Date: Sun, 1 Sep 2013 11:34:47 +0000 (+0100) Subject: Fix importing of branches into RCS X-Git-Tag: 0.2~3 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=3001eccea885b26387a9e4a2e603bd371433882b;p=rcs-fast-import.git Fix importing of branches into RCS RCS requires the parent revision to be locked to checkin a new revision. When there is only a single branch everything works, but when jumping to a different branch `ci' fails reporting the parent revision on this branch isn't locked. Remember the previous revision, which is locked in RCS, for every checked in file. If the parent of the revision being checked in is not the previously checked in revision then unlock the locked revision and relock the parent revision. Test case: $ cat test-04-branches.fastexp commit refs/heads/master mark :1 committer Joe Bloggs 999091736 +0100 data 13 Add file.txt M 644 inline file.txt data 51 Contents of file.txt, changeset 1/3, branch master commit refs/heads/b1 mark :2 committer Joe Bloggs 999098479 +0100 data 29 Update file.txt on branch b1 from :1 M 644 inline file.txt data 47 Contents of file.txt, changeset 2/3, branch b1 commit refs/heads/master mark :3 committer Joe Bloggs 999098479 +0100 data 33 Update file.txt on branch master from :1 M 644 inline file.txt data 51 Contents of file.txt, changeset 3/3, branch master $ rcs-fast-import -v -v -v < test-04-branches.fastexp rcs-fast-import: repository fast import creates /tmp/test/.rs2845 rcs-fast-import:......(0.00 sec) done. commit refs/heads/master rcs-fast-import: :1 M file.txt rcs-fast-import: linking ../.rs2845/inline-156562380 to file.txt Assigning 1.1 to file.txt rcs-fast-import: executing 'ci -l1.1 -d'Wed 29 Aug 2001 14:28:56 +0100' -m'Committer: Joe Bloggs Committer-Date: Wed 29 Aug 2001 14:28:56 +0100 Mark: :1 Add file.txt ' file.txt RCS/file.txt,v' modify RCS/file.txt,v <-- file.txt initial revision: 1.1 done rcs-fast-import: removing file.txt commit refs/heads/b1 rcs-fast-import: :2 M file.txt rcs-fast-import: linking ../.rs2845/inline-156562924 to file.txt Assigning 1.1.1.1 to file.txt rcs-fast-import: executing 'ci -l1.1.1.1 -d'Wed 29 Aug 2001 16:21:19 +0100' -m'Committer: Joe Bloggs Committer-Date: Wed 29 Aug 2001 16:21:19 +0100 Mark: :2 Parents: :1 Update file.txt on branch b1 ' file.txt RCS/file.txt,v' modify RCS/file.txt,v <-- file.txt new revision: 1.1.1.1; previous revision: 1.1 done rcs-fast-import: removing file.txt rcs-fast-import: executing 'rcs -N'refs/heads/b1':1.1.1 RCS/file.txt,v' RCS file: RCS/file.txt,v done commit refs/heads/master rcs-fast-import: :3 M file.txt rcs-fast-import: linking ../.rs2845/inline-156563340 to file.txt Assigning 1.2 to file.txt rcs-fast-import: executing 'ci -l1.2 -d'Wed 29 Aug 2001 16:21:19 +0100' -m'Committer: Joe Bloggs Committer-Date: Wed 29 Aug 2001 16:21:19 +0100 Mark: :3 Parents: :1 Update file.txt on branch master ' file.txt RCS/file.txt,v' modify RCS/file.txt,v <-- file.txt ci: RCS/file.txt,v: no lock set by mike for revision 1.1 cleaning up......(0.00 sec) done. rcs-fast-import: cleaning up /tmp/test/.rs2845......(0.00 sec) done. rcs-fast-import: child returned 1. --- diff --git a/rcs-fast-import b/rcs-fast-import index 7547ada..b2f7a93 100755 --- a/rcs-fast-import +++ b/rcs-fast-import @@ -597,6 +597,19 @@ class GenericRev: s = GenericRev(self.rev) s.rev[-1] += 1 return s + def parent(self): + "Return the parent of this ID." + if self.rev == [1, 1]: + return None + p = GenericRev(list(self.rev)) + if p.rev[-1] > 1: + p.rev[-1] -= 1 + else: + p.rev = p.rev[:-2] + return p + def __ne__(self, other): + "Return true if self and other are different IDs." + return self.rev != other.rev def branch(self, branchnum=None): "With arg, return ID for the tip of a new branch." if branchnum is None: @@ -730,14 +743,24 @@ class RCS(Generic): mastertemplate = "%s,v" def __init__(self): Generic.__init__(self) + self.previous_revs = {} # Most recently checked in revision for each path def checkin(self, commit, comment, op, path, rev): "Check in a new revision - also used to create new masters." - command = "ci -l%s" % rev + rcspath = self.master(path) + command = "" + prev_rev = self.previous_revs.get(path) + parent = rev.parent() + if prev_rev != parent: + # Checking in on a different RCS branch to last time. Lock + # this revisions parent first. + command = "rcs -u %s && rcs -l%s %s && " % (rcspath, parent, rcspath) + command += "ci -l%s" % rev if op == "D": command += " -sDeleted" command += " -d'%s'" % commit.committer.date.rfc822() command += " -m'%s'" % comment.replace("'", "'\"'\"'") - command += " " + path + " " + self.master(path) + command += " " + path + " " + rcspath + self.previous_revs[path] = rev return command def checkout(self, path, branch): "Check out the latest revision corresponding to path and branch."