1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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/>.
16
from bzrlib import debug, osutils, urlutils
17
from bzrlib.trace import mutter
18
from bzrlib.versionedfile import FulltextContentFactory, VersionedFiles, AbsentContentFactory, VirtualVersionedFiles
20
from bzrlib.plugins.svn.core import SubversionException
21
from bzrlib.plugins.svn.errors import ERR_FS_NOT_FILE
23
from cStringIO import StringIO
25
class SvnTexts(VersionedFiles):
26
"""Subversion texts backend."""
28
def __init__(self, repository):
29
self.repository = repository
31
def check(self, progressbar=None):
34
def add_mpdiffs(self, records):
35
raise NotImplementedError(self.add_mpdiffs)
37
def get_record_stream(self, keys, ordering, include_delta_closure):
38
# TODO: there may be valid text revisions that only exist as
39
# ghosts in the repository itself. This function will
40
# not be able to report them.
41
# TODO: Sort keys by file id and issue just one get_file_revs() call
43
for (fileid, revid) in list(keys):
44
(branch, revnum, mapping) = self.repository.lookup_revision_id(revid)
45
map = self.repository.get_fileid_map(revnum, branch, mapping)
46
# Unfortunately, the map is the other way around
48
for k,(v,ck) in map.items():
52
self.repository.transport.get_file(urlutils.join(branch, k), stream, revnum)
53
lines = stream.readlines()
54
except SubversionException, (_, num):
55
if num == ERR_FS_NOT_FILE:
61
raise Exception("Inconsistent key specified: (%r,%r)" % (fileid, revid))
62
yield FulltextContentFactory((fileid,revid), None,
63
sha1=osutils.sha_strings(lines),
66
def get_parent_map(self, keys):
69
# First, figure out the revision number/path
71
for (fileid, revid) in keys:
73
ret[(fileid, revid)] = None
76
# TODO: annotate, get_sha1s, iter_lines_added_or_present_in_keys, keys
79
class VirtualRevisionTexts(VirtualVersionedFiles):
80
"""Virtual revisions backend."""
81
def __init__(self, repository):
82
self.repository = repository
83
super(VirtualRevisionTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
85
def get_lines(self, key):
86
return osutils.split_lines(self.repository.get_revision_xml(key))
88
# TODO: annotate, iter_lines_added_or_present_in_keys, keys
91
class VirtualInventoryTexts(VirtualVersionedFiles):
92
"""Virtual inventories backend."""
93
def __init__(self, repository):
94
self.repository = repository
95
super(VirtualInventoryTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
97
def get_lines(self, key):
98
return osutils.split_lines(self.repository.get_inventory_xml(key))
100
# TODO: annotate, iter_lines_added_or_present_in_keys, keys
103
class VirtualSignatureTexts(VirtualVersionedFiles):
104
"""Virtual signatures backend."""
105
def __init__(self, repository):
106
self.repository = repository
107
super(VirtualSignatureTexts, self).__init__(self.repository._make_parents_provider().get_parent_map, self.get_lines)
109
def get_lines(self, key):
110
return osutils.split_lines(self.repository.get_signature_text(key))
112
# TODO: annotate, iter_lines_added_or_present_in_keys, keys