39
42
def __init__(self, repository, revision_id):
40
43
self._revision_id = revision_id
41
44
self._repository = repository
42
store = repository._git.object_store
45
self.store = repository._git.object_store
43
46
assert isinstance(revision_id, str)
44
47
git_id, self.mapping = repository.lookup_bzr_revision_id(revision_id)
46
commit = store[git_id]
49
commit = self.store[git_id]
47
50
except KeyError, r:
48
51
raise errors.NoSuchRevision(repository, revision_id)
49
52
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,
53
self.fileid_map = self.mapping.get_fileid_map(self.store.__getitem__, self.tree)
55
def id2path(self, file_id):
56
return self.fileid_map.lookup_path(file_id)
58
def path2id(self, path):
59
return self.fileid_map.lookup_file_id(path.encode('utf-8'))
61
def get_root_id(self):
62
return self.path2id("")
64
def has_or_had_id(self, file_id):
65
return self.has_id(file_id)
67
def has_id(self, file_id):
69
path = self.id2path(file_id)
70
except errors.NoSuchId:
72
return self.has_filename(path)
74
def has_filename(self, path):
76
tree_lookup_path(self.store.__getitem__, self.tree,
83
def list_files(self, include_root=False, from_dir=None, recursive=True):
86
(mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
87
from_dir.encode("utf-8"))
88
if mode is None: # Root
89
root_ie = self._get_dir_ie("", None)
91
parent_path = posixpath.dirname(from_dir.encode("utf-8"))
92
parent_id = self.fileid_map.lookup_file_id(parent_path)
93
if mode_kind(mode) == 'directory':
94
root_ie = self._get_dir_ie(from_dir.encode("utf-8"), parent_id)
96
root_ie = self._get_file_ie(from_dir.encode("utf-8"),
97
posixpath.basename(from_dir), mode, hexsha)
98
if from_dir != "" or include_root:
99
yield (from_dir, "V", root_ie.kind, root_ie.file_id, root_ie)
101
if root_ie.kind == 'directory':
102
todo.add((from_dir.encode("utf-8"), hexsha, root_ie.file_id))
104
(path, hexsha, parent_id) = todo.pop()
105
tree = self.store[hexsha]
106
for name, mode, hexsha in tree.iteritems():
107
child_path = posixpath.join(path, name)
108
if stat.S_ISDIR(mode):
109
ie = self._get_dir_ie(child_path, parent_id)
111
todo.add((child_path, hexsha, ie.file_id))
113
ie = self._get_file_ie(child_path, name, mode, hexsha, parent_id)
114
yield child_path, "V", ie.kind, ie.file_id, ie
116
def _get_file_ie(self, path, name, mode, hexsha, parent_id):
117
kind = mode_kind(mode)
118
file_id = self.fileid_map.lookup_file_id(path)
119
ie = inventory.entry_factory[kind](file_id, name.decode("utf-8"), parent_id)
120
if kind == 'symlink':
121
ie.symlink_target = self.store[hexsha].data
123
data = self.store[hexsha].data
124
ie.text_sha1 = osutils.sha_string(data)
125
ie.text_size = len(data)
126
ie.executable = mode_is_executable(mode)
129
def _get_dir_ie(self, path, parent_id):
130
file_id = self.fileid_map.lookup_file_id(path)
131
return inventory.InventoryDirectory(file_id,
132
posixpath.basename(path).decode("utf-8"), parent_id)
134
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
135
# FIXME: Support specific_file_ids
136
#FIXME: yield actual inventory entries
137
if specific_file_ids is not None:
138
raise NotImplementedError(self.iter_entries_by_dir)
139
todo = set([("", self.tree, None)])
141
path, tree_sha, parent_id = todo.pop()
142
ie = self._get_dir_ie(path, parent_id)
144
tree = self.store[tree_sha]
145
for name, mode, hexsha in tree.iteritems():
146
child_path = posixpath.join(path, name)
147
if stat.S_ISDIR(mode):
148
todo.add((child_path, hexsha, ie.file_id))
150
yield child_path, self._get_file_ie(path, name, mode, hexsha, ie.file_id)
54
152
def get_revision_id(self):
55
153
"""See RevisionTree.get_revision_id."""