46
47
except KeyError, r:
47
48
raise errors.NoSuchRevision(repository, revision_id)
48
49
self.tree = commit.tree
49
self._inventory = GitInventory(self.tree, self.mapping, store,
50
fileid_map = self.mapping.get_fileid_map(store.__getitem__, self.tree)
51
self._inventory = GitInventory(self.tree, self.mapping, fileid_map,
52
54
def get_revision_id(self):
55
"""See RevisionTree.get_revision_id."""
53
56
return self._revision_id
55
58
def get_file_text(self, file_id, path=None):
59
"""See RevisionTree.get_file_text."""
56
60
if path is not None:
57
61
entry = self._inventory._get_ie(path)
62
66
return entry.object.data
65
def tree_delta_from_git_changes(changes, mapping, specific_file=None,
66
require_versioned=False):
69
def tree_delta_from_git_changes(changes, mapping,
70
(old_fileid_map, new_fileid_map), specific_file=None,
71
require_versioned=False):
67
72
"""Create a TreeDelta from two git trees.
69
source and target are iterators over tuples with:
74
source and target are iterators over tuples with:
70
75
(filename, sha, mode)
72
77
ret = delta.TreeDelta()
73
78
for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
79
if mapping.is_control_file(oldpath):
81
if mapping.is_control_file(newpath):
83
if oldpath is None and newpath is None:
74
85
if oldpath is None:
75
ret.added.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode)))
86
ret.added.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
76
87
elif newpath is None:
77
ret.removed.append((oldpath, mapping.generate_file_id(oldpath), mode_kind(oldmode)))
88
ret.removed.append((oldpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(oldmode)))
78
89
elif oldpath != newpath:
79
ret.renamed.append((oldpath, newpath, mapping.generate_file_id(oldpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
90
ret.renamed.append((oldpath, newpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
80
91
elif mode_kind(oldmode) != mode_kind(newmode):
81
ret.kind_changed.append((newpath, mapping.generate_file_id(newpath), mode_kind(oldmode), mode_kind(newmode)))
92
ret.kind_changed.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(oldmode), mode_kind(newmode)))
82
93
elif oldsha != newsha or oldmode != newmode:
83
ret.modified.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
94
ret.modified.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
85
ret.unchanged.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode)))
96
ret.unchanged.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
89
def changes_from_git_changes(changes, mapping, specific_file=None,
100
def changes_from_git_changes(changes, mapping, specific_file=None,
90
101
require_versioned=False):
91
102
"""Create a iter_changes-like generator from a git stream.
93
source and target are iterators over tuples with:
104
source and target are iterators over tuples with:
94
105
(filename, sha, mode)
96
107
for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
127
138
newname = newpath
129
140
newparent = mapping.generate_file_id(newparentpath)
130
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))
133
147
class InterGitRevisionTrees(tree.InterTree):
149
163
raise AssertionError
150
164
changes = self.source._repository._git.object_store.tree_changes(
151
165
self.source.tree, self.target.tree, want_unchanged=want_unchanged)
152
return tree_delta_from_git_changes(changes, self.target.mapping,
166
source_fileid_map = self.source.mapping.get_fileid_map(
167
self.source._repository._git.object_store.__getitem__,
169
target_fileid_map = self.target.mapping.get_fileid_map(
170
self.target._repository._git.object_store.__getitem__,
172
return tree_delta_from_git_changes(changes, self.target.mapping,
173
(source_fileid_map, target_fileid_map),
153
174
specific_file=specific_files)
155
176
def iter_changes(self, include_unchanged=False, specific_files=None,
156
pb=None, extra_trees=[], require_versioned=True, want_unversioned=False):
177
pb=None, extra_trees=[], require_versioned=True,
178
want_unversioned=False):
157
179
if self.source._repository._git.object_store != self.target._repository._git.object_store:
158
180
raise AssertionError
159
181
changes = self.source._repository._git.object_store.tree_changes(
160
self.source.tree, self.target.tree,
182
self.source.tree, self.target.tree,
161
183
want_unchanged=include_unchanged)
162
return changes_from_git_changes(changes, self.target.mapping,
184
return changes_from_git_changes(changes, self.target.mapping,
163
185
specific_file=specific_files)