diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-23 14:19:15 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-23 14:19:15 -0400 |
commit | 45cc50d7ce0b5c32a2936d6eb87a3002670924bc (patch) | |
tree | 3d7d34e3a6eb19a76aab4b649a2b72f8cef98cb9 | |
parent | 988b86a70cfc493f51b71e3e0b7effa439719a13 (diff) | |
download | bugseverywhere-45cc50d7ce0b5c32a2936d6eb87a3002670924bc.tar.gz |
Added .revision_id() to all the VCSs.
This makes it easier to compare recent revisions without a human
around to give you revision numbers.
-rw-r--r-- | libbe/arch.py | 12 | ||||
-rw-r--r-- | libbe/bzr.py | 8 | ||||
-rw-r--r-- | libbe/darcs.py | 43 | ||||
-rw-r--r-- | libbe/git.py | 13 | ||||
-rw-r--r-- | libbe/hg.py | 16 | ||||
-rw-r--r-- | libbe/rcs.py | 46 |
6 files changed, 114 insertions, 24 deletions
diff --git a/libbe/arch.py b/libbe/arch.py index 2f45aa9..1bdc8ae 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -176,7 +176,6 @@ class Arch(RCS): self._get_archive_project_name(root) return root - def _get_archive_name(self, root): status,output,error = self._u_invoke_client("archives") lines = output.split('\n') @@ -188,7 +187,6 @@ class Arch(RCS): if os.path.realpath(location) == os.path.realpath(root): self._archive_name = archive assert self._archive_name != None - def _get_archive_project_name(self, root): # get project names status,output,error = self._u_invoke_client("tree-version", directory=root) @@ -281,6 +279,16 @@ class Arch(RCS): assert revpath.startswith(self._archive_project_name()+'--') revision = revpath[len(self._archive_project_name()+'--'):] return revpath + def _rcs_revision_id(self, index): + status,output,error = self._u_invoke_client("logs") + logs = output.splitlines() + first_log = logs.pop(0) + assert first_log == "base-0", first_log + try: + log = logs[index] + except IndexError: + return None + return "%s--%s" % (self._archive_project_name(), log) class CantAddFile(Exception): def __init__(self, file): diff --git a/libbe/bzr.py b/libbe/bzr.py index b33292c..7457815 100644 --- a/libbe/bzr.py +++ b/libbe/bzr.py @@ -93,6 +93,14 @@ class Bzr(RCS): assert len(match.groups()) == 1 revision = match.groups()[0] return revision + def _rcs_revision_id(self, index): + status,output,error = self._u_invoke_client("revno") + current_revision = int(output) + if index >= current_revision or index < -current_revision: + return None + if index >= 0: + return str(index+1) # bzr commit 0 is the empty tree. + return str(current_revision+index+1) def postcommit(self): try: self._u_invoke_client('merge') diff --git a/libbe/darcs.py b/libbe/darcs.py index e7132c0..0720ed9 100644 --- a/libbe/darcs.py +++ b/libbe/darcs.py @@ -18,8 +18,13 @@ import codecs import os import re import sys -import unittest +try: # import core module, Python >= 2.5 + from xml.etree import ElementTree +except ImportError: # look for non-core module + from elementtree import ElementTree +from xml.sax.saxutils import unescape import doctest +import unittest import rcs from rcs import RCS @@ -138,24 +143,36 @@ class Darcs(RCS): args = ['record', '--all', '--author', id, '--logfile', commitfile] status,output,error = self._u_invoke_client(*args) empty_strings = ["No changes!"] - revision = None if self._u_any_in_string(empty_strings, output) == True: if allow_empty == False: raise rcs.EmptyCommit() - else: # we need a extra call to get the current revision - args = ["changes", "--last=1", "--xml"] - status,output,error = self._u_invoke_client(*args) - revline = re.compile("[ \t]*<name>(.*)</name>") - # note that darcs does _not_ make an empty revision. - # this returns the last non-empty revision id... + # note that darcs does _not_ make an empty revision. + # this returns the last non-empty revision id... + revision = self._rcs_revision_id(-1) else: revline = re.compile("Finished recording patch '(.*)'") - match = revline.search(output) - assert match != None, output+error - assert len(match.groups()) == 1 - revision = match.groups()[0] + match = revline.search(output) + assert match != None, output+error + assert len(match.groups()) == 1 + revision = match.groups()[0] return revision - + def _rcs_revision_id(self, index): + status,output,error = self._u_invoke_client("changes", "--xml") + revisions = [] + xml_str = output.encode("unicode_escape").replace(r"\n", "\n") + element = ElementTree.XML(xml_str) + assert element.tag == "changelog", element.tag + for patch in element.getchildren(): + assert patch.tag == "patch", patch.tag + for child in patch.getchildren(): + if child.tag == "name": + text = unescape(unicode(child.text).decode("unicode_escape").strip()) + revisions.append(text) + revisions.reverse() + try: + return revisions[index] + except IndexError: + return None rcs.make_rcs_testcase_subclasses(Darcs, sys.modules[__name__]) diff --git a/libbe/git.py b/libbe/git.py index 2f9ffa9..2b45679 100644 --- a/libbe/git.py +++ b/libbe/git.py @@ -111,7 +111,18 @@ class Git(RCS): assert match != None, output+error assert len(match.groups()) == 3 revision = match.groups()[1] - return revision + full_revision = self._rcs_revision_id(-1) + assert full_revision.startswith(revision), \ + "Mismatched revisions:\n%s\n%s" % (revision, full_revision) + return full_revision + def _rcs_revision_id(self, index): + args = ["rev-list", "--first-parent", "--reverse", "HEAD"] + status,output,error = self._u_invoke_client(*args) + commits = output.splitlines() + try: + return commits[index] + except IndexError: + return None rcs.make_rcs_testcase_subclasses(Git, sys.modules[__name__]) diff --git a/libbe/hg.py b/libbe/hg.py index a20eeb5..fcda829 100644 --- a/libbe/hg.py +++ b/libbe/hg.py @@ -80,14 +80,14 @@ class Hg(RCS): strings = ["nothing changed"] if self._u_any_in_string(strings, output) == True: raise rcs.EmptyCommit() - status,output,error = self._u_invoke_client('identify') - revision = None - revline = re.compile("(.*) tip") - match = revline.search(output) - assert match != None, output+error - assert len(match.groups()) == 1 - revision = match.groups()[0] - return revision + return self._rcs_revision_id(-1) + def _rcs_revision_id(self, index, style="id"): + args = ["identify", "--rev", str(int(index)), "--%s" % style] + kwargs = {"expect": (0,255)} + status,output,error = self._u_invoke_client(*args, **kwargs) + if status == 0: + return output.strip() + return None rcs.make_rcs_testcase_subclasses(Hg, sys.modules[__name__]) 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 <index>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 <index>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.""" |