36
36
class GitRevisionTree(revisiontree.RevisionTree):
37
"""Revision tree implementation based on Git objects."""
39
38
def __init__(self, repository, revision_id):
40
39
self._revision_id = revision_id
52
51
store, revision_id)
54
53
def get_revision_id(self):
55
"""See RevisionTree.get_revision_id."""
56
54
return self._revision_id
58
56
def get_file_text(self, file_id, path=None):
59
"""See RevisionTree.get_file_text."""
60
57
if path is not None:
61
58
entry = self._inventory._get_ie(path)
70
67
(old_fileid_map, new_fileid_map), specific_file=None,
71
68
require_versioned=False):
72
69
"""Create a TreeDelta from two git trees.
74
source and target are iterators over tuples with:
71
source and target are iterators over tuples with:
75
72
(filename, sha, mode)
77
74
ret = delta.TreeDelta()
100
def changes_from_git_changes(changes, mapping, specific_file=None,
97
def changes_from_git_changes(changes, mapping, specific_file=None,
101
98
require_versioned=False):
102
99
"""Create a iter_changes-like generator from a git stream.
104
source and target are iterators over tuples with:
101
source and target are iterators over tuples with:
105
102
(filename, sha, mode)
107
104
for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
138
135
newname = newpath
140
137
newparent = mapping.generate_file_id(newparentpath)
141
yield (fileid, (oldpath, newpath), (oldsha != newsha),
142
(oldpath is not None, newpath is not None),
143
(oldparent, newparent), (oldname, newname),
144
(oldkind, newkind), (oldexe, newexe))
138
yield fileid, (oldpath, newpath), (oldsha != newsha), (oldpath is not None, newpath is not None), (oldparent, newparent), (oldname, newname), (oldkind, newkind), (oldexe, newexe)
147
141
class InterGitRevisionTrees(tree.InterTree):
155
149
def is_compatible(cls, source, target):
156
return (isinstance(source, GitRevisionTree) and
150
return (isinstance(source, GitRevisionTree) and
157
151
isinstance(target, GitRevisionTree))
159
153
def compare(self, want_unchanged=False, specific_files=None,
169
163
target_fileid_map = self.target.mapping.get_fileid_map(
170
164
self.target._repository._git.object_store.__getitem__,
171
165
self.target.tree)
172
return tree_delta_from_git_changes(changes, self.target.mapping,
166
return tree_delta_from_git_changes(changes, self.target.mapping,
173
167
(source_fileid_map, target_fileid_map),
174
168
specific_file=specific_files)
176
170
def iter_changes(self, include_unchanged=False, specific_files=None,
177
pb=None, extra_trees=[], require_versioned=True,
178
want_unversioned=False):
171
pb=None, extra_trees=[], require_versioned=True, want_unversioned=False):
179
172
if self.source._repository._git.object_store != self.target._repository._git.object_store:
180
173
raise AssertionError
181
174
changes = self.source._repository._git.object_store.tree_changes(
182
self.source.tree, self.target.tree,
175
self.source.tree, self.target.tree,
183
176
want_unchanged=include_unchanged)
184
return changes_from_git_changes(changes, self.target.mapping,
177
return changes_from_git_changes(changes, self.target.mapping,
185
178
specific_file=specific_files)