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