Rev 91: Import VirtualVersionedFiles. in http://people.samba.org/bzr/jelmer/bzr-git/trunk
Jelmer Vernooij
jelmer at samba.org
Mon Jul 28 02:43:49 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-git/trunk
------------------------------------------------------------
revno: 91
revision-id: jelmer at samba.org-20080728014348-cgq9jwebhl6pdnc9
parent: jelmer at samba.org-20080726205651-0ug01npe1r2ff6d4
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2008-07-28 03:43:48 +0200
message:
Import VirtualVersionedFiles.
added:
tests/test_versionedfiles.py test_versionedfiles.-20080626153242-v0c6uolklpux67a1-1
versionedfiles.py versionedfiles.py-20080626134117-j8g0ntz1pj228iox-1
modified:
tests/__init__.py __init__.py-20070202180350-njrb42t7fnv35d1k-2
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-07-25 22:56:43 +0000
+++ b/tests/__init__.py 2008-07-28 01:43:48 +0000
@@ -233,6 +233,7 @@
'test_git_repository',
'test_ids',
'test_blackbox',
+ 'test_versionedfiles',
]
testmod_names = ['%s.%s' % (__name__, t) for t in testmod_names]
suite.addTests(loader.loadTestsFromModuleNames(testmod_names))
=== added file 'tests/test_versionedfiles.py'
--- a/tests/test_versionedfiles.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_versionedfiles.py 2008-07-28 01:43:48 +0000
@@ -0,0 +1,74 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from bzrlib import osutils
+from bzrlib.graph import DictParentsProvider
+from bzrlib.tests import TestCase
+
+from bzrlib.plugins.git.versionedfiles import (SvnTexts, VirtualRevisionTexts,
+ VirtualInventoryTexts, VirtualSignatureTexts)
+
+
+class BasicSvnTextsTests:
+ def test_add_lines(self):
+ self.assertRaises(NotImplementedError,
+ self.texts.add_lines, "foo", [], [])
+
+ def test_add_mpdiffs(self):
+ self.assertRaises(NotImplementedError,
+ self.texts.add_mpdiffs, [])
+
+ def test_check(self):
+ self.assertTrue(self.texts.check())
+
+ def test_insert_record_stream(self):
+ self.assertRaises(NotImplementedError, self.texts.insert_record_stream,
+ [])
+
+
+class SvnTextsTests(TestCase,BasicSvnTextsTests):
+ def setUp(self):
+ self.texts = SvnTexts(self)
+
+
+class VirtualRevisionTextsTests(TestCase,BasicSvnTextsTests):
+ def setUp(self):
+ self.texts = VirtualRevisionTexts(self)
+
+ def get_parent_map(self, keys):
+ raise NotImplementedError
+
+
+class VirtualInventoryTextsTests(TestCase,BasicSvnTextsTests):
+ def get_inventory_xml(self, key):
+ return "FOO"
+
+ def get_parent_map(self, keys):
+ return {("A",): (("B",))}
+
+ def setUp(self):
+ self.texts = VirtualInventoryTexts(self)
+
+ def test_get_sha1s(self):
+ self.assertEquals({("A",): osutils.sha_strings(["FOO"])}, self.texts.get_sha1s([("A",)]))
+
+
+class VirtualSignatureTextsTests(TestCase,BasicSvnTextsTests):
+ def setUp(self):
+ self.texts = VirtualSignatureTexts(self)
+
+ def get_parent_map(self, keys):
+ raise NotImplementedError
+
=== added file 'versionedfiles.py'
--- a/versionedfiles.py 1970-01-01 00:00:00 +0000
+++ b/versionedfiles.py 2008-07-28 01:43:48 +0000
@@ -0,0 +1,110 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from bzrlib import debug, osutils, urlutils
+from bzrlib.trace import mutter
+from bzrlib.versionedfile import FulltextContentFactory, VersionedFiles, AbsentContentFactory, VirtualVersionedFiles
+
+from bzrlib.plugins.svn.core import SubversionException
+from bzrlib.plugins.svn.errors import ERR_FS_NOT_FILE
+
+from cStringIO import StringIO
+
+class SvnTexts(VersionedFiles):
+ """Subversion texts backend."""
+
+ def __init__(self, repository):
+ self.repository = repository
+
+ def check(self, progressbar=None):
+ return True
+
+ def add_mpdiffs(self, records):
+ raise NotImplementedError(self.add_mpdiffs)
+
+ def get_record_stream(self, keys, ordering, include_delta_closure):
+ # TODO: Sort keys by file id and issue just one get_file_revs() call
+ # per file-id ?
+ for (fileid, revid) in list(keys):
+ (branch, revnum, mapping) = self.repository.lookup_revision_id(revid)
+ map = self.repository.get_fileid_map(revnum, branch, mapping)
+ # Unfortunately, the map is the other way around
+ lines = None
+ for k,(v,ck) in map.items():
+ if v == fileid:
+ try:
+ stream = StringIO()
+ self.repository.transport.get_file(urlutils.join(branch, k), stream, revnum)
+ lines = stream.readlines()
+ except SubversionException, (_, num):
+ if num == ERR_FS_NOT_FILE:
+ lines = []
+ else:
+ raise
+ break
+ if lines is None:
+ raise Exception("Inconsistent key specified: (%r,%r)" % (fileid, revid))
+ yield FulltextContentFactory((fileid,revid), None,
+ sha1=osutils.sha_strings(lines),
+ text=''.join(lines))
+
+ def get_parent_map(self, keys):
+ invs = {}
+
+ # First, figure out the revision number/path
+ ret = {}
+ for (fileid, revid) in keys:
+ # FIXME: Evil hack
+ ret[(fileid, revid)] = None
+ return ret
+
+ # TODO: annotate, get_sha1s, iter_lines_added_or_present_in_keys, keys
+
+
+class VirtualRevisionTexts(VirtualVersionedFiles):
+ """Virtual revisions backend."""
+ def __init__(self, repository):
+ self.repository = repository
+ super(VirtualRevisionTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
+
+ def get_lines(self, key):
+ return osutils.split_lines(self.repository.get_revision_xml(key))
+
+ # TODO: annotate, iter_lines_added_or_present_in_keys, keys
+
+
+class VirtualInventoryTexts(VirtualVersionedFiles):
+ """Virtual inventories backend."""
+ def __init__(self, repository):
+ self.repository = repository
+ super(VirtualInventoryTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
+
+ def get_lines(self, key):
+ return osutils.split_lines(self.repository.get_inventory_xml(key))
+
+ # TODO: annotate, iter_lines_added_or_present_in_keys, keys
+
+
+class VirtualSignatureTexts(VirtualVersionedFiles):
+ """Virtual signatures backend."""
+ def __init__(self, repository):
+ self.repository = repository
+ super(VirtualSignatureTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
+
+ def get_lines(self, key):
+ return osutils.split_lines(self.repository.get_signature_text(key))
+
+ # TODO: annotate, iter_lines_added_or_present_in_keys, keys
+
More information about the bazaar-commits
mailing list