[Pkg-bazaar-commits] ./bzr-git/unstable r27: New snapshot.

Jelmer Vernooij jelmer at samba.org
Fri Apr 10 12:28:15 UTC 2009


------------------------------------------------------------
revno: 27
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: debian
timestamp: Fri 2008-08-22 19:35:50 +0200
message:
  New snapshot.
added:
  tests/test_versionedfiles.py
  versionedfiles.py
modified:
  debian/changelog
  tests/__init__.py
    ------------------------------------------------------------
    revno: 17.1.74
    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
      versionedfiles.py
    modified:
      tests/__init__.py
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog	2008-07-26 23:13:47 +0000
+++ b/debian/changelog	2008-08-22 17:35:50 +0000
@@ -1,4 +1,4 @@
-bzr-git (0.1~bzr90-1) unstable; urgency=low
+bzr-git (0.1~bzr91-1) unstable; urgency=low
 
   * Initial release. (Closes: #489169)
 

=== 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 Pkg-bazaar-commits mailing list