/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to versionedfiles.py

Import VirtualVersionedFiles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
from bzrlib import debug, osutils, urlutils
 
17
from bzrlib.trace import mutter
 
18
from bzrlib.versionedfile import FulltextContentFactory, VersionedFiles, AbsentContentFactory, VirtualVersionedFiles
 
19
 
 
20
from bzrlib.plugins.svn.core import SubversionException
 
21
from bzrlib.plugins.svn.errors import ERR_FS_NOT_FILE
 
22
 
 
23
from cStringIO import StringIO
 
24
 
 
25
class SvnTexts(VersionedFiles):
 
26
    """Subversion texts backend."""
 
27
 
 
28
    def __init__(self, repository):
 
29
        self.repository = repository
 
30
 
 
31
    def check(self, progressbar=None):
 
32
        return True
 
33
 
 
34
    def add_mpdiffs(self, records):
 
35
        raise NotImplementedError(self.add_mpdiffs)
 
36
 
 
37
    def get_record_stream(self, keys, ordering, include_delta_closure):
 
38
        # TODO: Sort keys by file id and issue just one get_file_revs() call 
 
39
        # per file-id ?
 
40
        for (fileid, revid) in list(keys):
 
41
            (branch, revnum, mapping) = self.repository.lookup_revision_id(revid)
 
42
            map = self.repository.get_fileid_map(revnum, branch, mapping)
 
43
            # Unfortunately, the map is the other way around
 
44
            lines = None
 
45
            for k,(v,ck) in map.items():
 
46
                if v == fileid:
 
47
                    try:
 
48
                        stream = StringIO()
 
49
                        self.repository.transport.get_file(urlutils.join(branch, k), stream, revnum)
 
50
                        lines = stream.readlines()
 
51
                    except SubversionException, (_, num):
 
52
                        if num == ERR_FS_NOT_FILE:
 
53
                            lines = []
 
54
                        else:
 
55
                            raise
 
56
                    break
 
57
            if lines is None:
 
58
                raise Exception("Inconsistent key specified: (%r,%r)" % (fileid, revid))
 
59
            yield FulltextContentFactory((fileid,revid), None, 
 
60
                        sha1=osutils.sha_strings(lines),
 
61
                        text=''.join(lines))
 
62
 
 
63
    def get_parent_map(self, keys):
 
64
        invs = {}
 
65
 
 
66
        # First, figure out the revision number/path
 
67
        ret = {}
 
68
        for (fileid, revid) in keys:
 
69
            # FIXME: Evil hack
 
70
            ret[(fileid, revid)] = None
 
71
        return ret
 
72
 
 
73
    # TODO: annotate, get_sha1s, iter_lines_added_or_present_in_keys, keys
 
74
 
 
75
 
 
76
class VirtualRevisionTexts(VirtualVersionedFiles):
 
77
    """Virtual revisions backend."""
 
78
    def __init__(self, repository):
 
79
        self.repository = repository
 
80
        super(VirtualRevisionTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
 
81
 
 
82
    def get_lines(self, key):
 
83
        return osutils.split_lines(self.repository.get_revision_xml(key))
 
84
 
 
85
    # TODO: annotate, iter_lines_added_or_present_in_keys, keys
 
86
 
 
87
 
 
88
class VirtualInventoryTexts(VirtualVersionedFiles):
 
89
    """Virtual inventories backend."""
 
90
    def __init__(self, repository):
 
91
        self.repository = repository
 
92
        super(VirtualInventoryTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
 
93
 
 
94
    def get_lines(self, key):
 
95
        return osutils.split_lines(self.repository.get_inventory_xml(key))
 
96
 
 
97
    # TODO: annotate, iter_lines_added_or_present_in_keys, keys
 
98
 
 
99
 
 
100
class VirtualSignatureTexts(VirtualVersionedFiles):
 
101
    """Virtual signatures backend."""
 
102
    def __init__(self, repository):
 
103
        self.repository = repository
 
104
        super(VirtualSignatureTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
 
105
 
 
106
    def get_lines(self, key):
 
107
        return osutils.split_lines(self.repository.get_signature_text(key))
 
108
 
 
109
    # TODO: annotate, iter_lines_added_or_present_in_keys, keys
 
110