38
40
# construction - this will mean that we can change the constructor
39
41
# with much less chance of breaking client code.
40
42
self._repository = branch
41
self._weave_store = branch.weave_store
42
43
self._inventory = inv
43
self._revision_id = osutils.safe_revision_id(revision_id)
44
self._revision_id = revision_id
45
self._rules_searcher = None
47
def supports_tree_reference(self):
45
50
def get_parent_ids(self):
46
51
"""See Tree.get_parent_ids.
58
63
"""Return the revision id associated with this tree."""
59
64
return self._revision_id
61
def get_weave(self, file_id):
62
file_id = osutils.safe_file_id(file_id)
63
return self._weave_store.get_weave(file_id,
64
self._repository.get_transaction())
66
def get_file_lines(self, file_id):
67
file_id = osutils.safe_file_id(file_id)
68
ie = self._inventory[file_id]
69
weave = self.get_weave(file_id)
70
return weave.get_lines(ie.revision)
72
def get_file_text(self, file_id):
73
file_id = osutils.safe_file_id(file_id)
74
return ''.join(self.get_file_lines(file_id))
76
def get_file(self, file_id):
77
file_id = osutils.safe_file_id(file_id)
66
def get_file_text(self, file_id, path=None):
67
return list(self.iter_files_bytes([(file_id, None)]))[0][1]
69
def get_file(self, file_id, path=None):
78
70
return StringIO(self.get_file_text(file_id))
80
def annotate_iter(self, file_id):
72
def iter_files_bytes(self, desired_files):
73
"""See Tree.iter_files_bytes.
75
This version is implemented on top of Repository.extract_files_bytes"""
76
repo_desired_files = [(f, self.inventory[f].revision, i)
77
for f, i in desired_files]
79
for result in self._repository.iter_files_bytes(repo_desired_files):
81
except errors.RevisionNotPresent, e:
82
raise errors.NoSuchFile(e.revision_id)
84
def annotate_iter(self, file_id,
85
default_revision=revision.CURRENT_REVISION):
81
86
"""See Tree.annotate_iter"""
82
file_id = osutils.safe_file_id(file_id)
83
w = self.get_weave(file_id)
84
return w.annotate_iter(self.inventory[file_id].revision)
87
text_key = (file_id, self.inventory[file_id].revision)
88
annotations = self._repository.texts.annotate(text_key)
89
return [(key[-1], line) for key, line in annotations]
86
91
def get_file_size(self, file_id):
87
file_id = osutils.safe_file_id(file_id)
92
"""See Tree.get_file_size"""
88
93
return self._inventory[file_id].text_size
90
95
def get_file_sha1(self, file_id, path=None, stat_value=None):
91
file_id = osutils.safe_file_id(file_id)
92
96
ie = self._inventory[file_id]
93
97
if ie.kind == "file":
94
98
return ie.text_sha1
97
101
def get_file_mtime(self, file_id, path=None):
98
file_id = osutils.safe_file_id(file_id)
99
102
ie = self._inventory[file_id]
100
103
revision = self._repository.get_revision(ie.revision)
101
104
return revision.timestamp
103
106
def is_executable(self, file_id, path=None):
104
file_id = osutils.safe_file_id(file_id)
105
107
ie = self._inventory[file_id]
106
108
if ie.kind != "file":
121
123
yield path, 'V', entry.kind, entry.file_id, entry
123
125
def get_symlink_target(self, file_id):
124
file_id = osutils.safe_file_id(file_id)
125
126
ie = self._inventory[file_id]
126
127
return ie.symlink_target;
129
def get_reference_revision(self, file_id, path=None):
130
return self.inventory[file_id].reference_revision
132
def get_root_id(self):
133
if self.inventory.root:
134
return self.inventory.root.file_id
128
136
def kind(self, file_id):
129
file_id = osutils.safe_file_id(file_id)
130
137
return self._inventory[file_id].kind
139
def path_content_summary(self, path):
140
"""See Tree.path_content_summary."""
141
id = self.inventory.path2id(path)
143
return ('missing', None, None, None)
144
entry = self._inventory[id]
147
return (kind, entry.text_size, entry.executable, entry.text_sha1)
148
elif kind == 'symlink':
149
return (kind, None, None, entry.symlink_target)
151
return (kind, None, None, None)
132
153
def _comparison_data(self, entry, path):
133
154
if entry is None:
134
155
return None, False, None
135
156
return entry.kind, entry.executable, None
137
158
def _file_size(self, entry, stat_value):
138
assert entry.text_size is not None
139
159
return entry.text_size
161
def _get_ancestors(self, default_revision):
162
return set(self._repository.get_ancestry(self._revision_id,
141
165
def lock_read(self):
142
166
self._repository.lock_read()