1
# Copyright (C) 2009 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 2 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, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from dulwich.object_store import (
20
from dulwich.objects import (
26
from bzrlib.revision import (
29
from bzrlib.versionedfile import (
31
FulltextContentFactory,
36
class GitRevisions(VersionedFiles):
38
def __init__(self, object_store):
39
self.object_store = object_store
41
def check(self, progressbar=None):
45
for sha in self.object_store:
46
if type(sha) == Commit:
50
return list(self.iterkeys())
52
def add_mpdiffs(self, records):
53
raise NotImplementedError(self.add_mpdiffs)
55
def get_record_stream(self, keys, ordering, include_delta_closure):
59
text = self.object_store.get_raw(sha)
61
yield AbsentContentFactory(key)
63
yield FulltextContentFactory(key, None, None, text)
65
def get_parent_map(self, keys):
69
ret[(key,)] = [(p,) for p in self.object_store[key].parents]
75
class GitTexts(VersionedFiles):
76
"""A texts VersionedFiles instance that is backed onto a Git object store."""
78
def __init__(self, repository):
79
self.repository = repository
80
self.object_store = self.repository._git.object_store
82
def check(self, progressbar=None):
85
def add_mpdiffs(self, records):
86
raise NotImplementedError(self.add_mpdiffs)
88
def get_record_stream(self, keys, ordering, include_delta_closure):
91
(foreign_revid, mapping) = self.repository.lookup_git_revid(revid)
92
root_tree = self.object_store[foreign_revid].tree
93
path = mapping.parse_file_id(fileid)
95
obj = tree_lookup_path(self.object_store.__getitem__,
98
yield AbsentContentFactory(key)
100
if isinstance(obj, Tree):
101
yield FulltextContentFactory(key, None, None, "")
102
elif isinstance(obj, Blob):
103
yield FulltextContentFactory(key, None, None, obj._text)
105
yield AbsentContentFactory(key)
107
def get_parent_map(self, keys):
108
raise NotImplementedError(self.get_parent_map)