46
46
except KeyError, r:
47
47
raise errors.NoSuchRevision(repository, revision_id)
48
48
self.tree = commit.tree
49
self._inventory = GitInventory(self.tree, self.mapping, store,
49
fileid_map = self.mapping.get_fileid_map(store.__getitem__, self.tree)
50
self._inventory = GitInventory(self.tree, self.mapping, fileid_map,
52
53
def get_revision_id(self):
53
54
return self._revision_id
62
63
return entry.object.data
65
def tree_delta_from_git_changes(changes, mapping, specific_file=None,
66
require_versioned=False):
66
def tree_delta_from_git_changes(changes, mapping,
67
(old_fileid_map, new_fileid_map), specific_file=None,
68
require_versioned=False):
67
69
"""Create a TreeDelta from two git trees.
69
71
source and target are iterators over tuples with:
72
74
ret = delta.TreeDelta()
73
75
for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
76
if mapping.is_control_file(oldpath):
78
if mapping.is_control_file(newpath):
80
if oldpath is None and newpath is None:
74
82
if oldpath is None:
75
ret.added.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode)))
83
ret.added.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
76
84
elif newpath is None:
77
ret.removed.append((oldpath, mapping.generate_file_id(oldpath), mode_kind(oldmode)))
85
ret.removed.append((oldpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(oldmode)))
78
86
elif oldpath != newpath:
79
ret.renamed.append((oldpath, newpath, mapping.generate_file_id(oldpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
87
ret.renamed.append((oldpath, newpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
80
88
elif mode_kind(oldmode) != mode_kind(newmode):
81
ret.kind_changed.append((newpath, mapping.generate_file_id(newpath), mode_kind(oldmode), mode_kind(newmode)))
89
ret.kind_changed.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(oldmode), mode_kind(newmode)))
82
90
elif oldsha != newsha or oldmode != newmode:
83
ret.modified.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
91
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)))
93
ret.unchanged.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
149
157
raise AssertionError
150
158
changes = self.source._repository._git.object_store.tree_changes(
151
159
self.source.tree, self.target.tree, want_unchanged=want_unchanged)
160
source_fileid_map = self.source.mapping.get_fileid_map(
161
self.source._repository._git.object_store.__getitem__,
163
target_fileid_map = self.target.mapping.get_fileid_map(
164
self.target._repository._git.object_store.__getitem__,
152
166
return tree_delta_from_git_changes(changes, self.target.mapping,
167
(source_fileid_map, target_fileid_map),
153
168
specific_file=specific_files)
155
170
def iter_changes(self, include_unchanged=False, specific_files=None,