From 45cc50d7ce0b5c32a2936d6eb87a3002670924bc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 23 Jul 2009 14:19:15 -0400 Subject: Added .revision_id() to all the VCSs. This makes it easier to compare recent revisions without a human around to give you revision numbers. --- libbe/rcs.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libbe/rcs.py') diff --git a/libbe/rcs.py b/libbe/rcs.py index 1e1cfa7..d979df0 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -214,6 +214,16 @@ class RCS(object): changes to commit. """ return None + def _rcs_revision_id(self, index): + """ + Return the name of the th revision. Index will be an + integer (possibly <= 0). The choice of which branch to follow + when crossing branches/merges is not defined. + + Return None if revision IDs are not supported, or if the + specified revision does not exist. + """ + return None def installed(self): try: self._rcs_help() @@ -407,6 +417,18 @@ class RCS(object): pass def postcommit(self, directory): pass + def revision_id(self, index=None): + """ + Return the name of the th revision. The choice of + which branch to follow when crossing branches/merges is not + defined. + + Return None if index==None, revision IDs are not supported, or + if the specified revision does not exist. + """ + if index == None: + return None + return self._rcs_revision_id(index) def _u_any_in_string(self, list, string): """ Return True if any of the strings in list are in string. @@ -814,6 +836,30 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual( self.test_contents['rev_1'], committed_contents) + def test_revision_id_as_committed(self): + """Check for compatibility between .commit() and .revision_id()""" + if not self.rcs.versioned: + self.failUnlessEqual(self.rcs.revision_id(5), None) + return + committed_revisions = [] + for path in self.test_files: + full_path = self.full_path(path) + self.rcs.set_file_contents( + full_path, self.test_contents['rev_1']) + revision = self.rcs.commit("Initial %s contents." % path) + committed_revisions.append(revision) + self.rcs.set_file_contents( + full_path, self.test_contents['uncommitted']) + revision = self.rcs.commit("Altered %s contents." % path) + committed_revisions.append(revision) + for i,revision in enumerate(committed_revisions): + self.failUnlessEqual(self.rcs.revision_id(i), revision) + i += -len(committed_revisions) # check negative indices + self.failUnlessEqual(self.rcs.revision_id(i), revision) + i = len(committed_revisions) + self.failUnlessEqual(self.rcs.revision_id(i), None) + self.failUnlessEqual(self.rcs.revision_id(-i-1), None) + class RCS_duplicate_repo_TestCase(RCSTestCase): """Test cases for RCS.duplicate_repo method.""" -- cgit From 22a38de80ee11ada710bc6766798ca608f938307 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 29 Jul 2009 15:49:45 -0400 Subject: Corrected some problems with revision_id() before an initial commit. --- libbe/rcs.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libbe/rcs.py') diff --git a/libbe/rcs.py b/libbe/rcs.py index d979df0..fdbb01a 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -860,6 +860,15 @@ class RCS_commit_TestCase(RCSTestCase): self.failUnlessEqual(self.rcs.revision_id(i), None) self.failUnlessEqual(self.rcs.revision_id(-i-1), None) + def test_revision_id_as_committed(self): + """Check revision id before first commit""" + if not self.rcs.versioned: + self.failUnlessEqual(self.rcs.revision_id(5), None) + return + committed_revisions = [] + for path in self.test_files: + self.failUnlessEqual(self.rcs.revision_id(0), None) + class RCS_duplicate_repo_TestCase(RCSTestCase): """Test cases for RCS.duplicate_repo method.""" -- cgit