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.versionedfile import (
28
ChunkedContentFactory,
33
class GitRevisions(VersionedFiles):
35
def __init__(self, repository, object_store):
36
self.repository = repository
37
self.object_store = object_store
39
def check(self, progressbar=None):
43
for sha in self.object_store:
44
if type(sha) == Commit:
48
return list(self.iterkeys())
50
def add_mpdiffs(self, records):
51
raise NotImplementedError(self.add_mpdiffs)
53
def get_record_stream(self, keys, ordering, include_delta_closure):
56
(commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
58
commit = self.object_store[commit_id]
60
yield AbsentContentFactory(key)
62
yield ChunkedContentFactory(key,
63
tuple([(self.repository.lookup_foreign_revision_id(p, mapping),) for p in commit.parents]), None,
64
commit.as_raw_chunks())
66
def get_parent_map(self, keys):
69
(commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
71
ret[(revid,)] = [(self.repository.lookup_foreign_revision_id(p, mapping),) for p in self.object_store[commit_id].parents]
77
class GitTexts(VersionedFiles):
78
"""A texts VersionedFiles instance that is backed onto a Git object store."""
80
def __init__(self, repository):
81
self.repository = repository
82
self.object_store = self.repository._git.object_store
84
def check(self, progressbar=None):
87
def add_mpdiffs(self, records):
88
raise NotImplementedError(self.add_mpdiffs)
90
def get_record_stream(self, keys, ordering, include_delta_closure):
93
(commit_id, mapping) = self.repository.lookup_bzr_revision_id(revid)
94
root_tree = self.object_store[commit_id].tree
95
path = mapping.parse_file_id(fileid)
97
obj = tree_lookup_path(
98
self.object_store.__getitem__, root_tree, path)
99
if isinstance(obj, tuple):
100
(mode, item_id) = obj
101
obj = self.object_store[item_id]
103
yield AbsentContentFactory(key)
105
if isinstance(obj, Tree):
106
yield ChunkedContentFactory(key, None, None, [])
107
elif isinstance(obj, Blob):
108
yield ChunkedContentFactory(key, None, None, obj.chunked)
110
raise AssertionError("file text resolved to %r" % obj)
112
def get_parent_map(self, keys):
113
raise NotImplementedError(self.get_parent_map)