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