##// END OF EJS Templates
vcs: added possibility to pre-load attributes for FileNodes.
marcink -
r1355:71f19ea6 default
parent child Browse files
Show More
@@ -393,7 +393,7 b' class GitCommit(base.BaseCommit):'
393 393 nodes.sort()
394 394 return nodes
395 395
396 def get_node(self, path):
396 def get_node(self, path, pre_load=None):
397 397 if isinstance(path, unicode):
398 398 path = path.encode('utf-8')
399 399 path = self._fix_path(path)
@@ -415,7 +415,7 b' class GitCommit(base.BaseCommit):'
415 415 else:
416 416 node = DirNode(path, commit=self)
417 417 elif type_ == 'blob':
418 node = FileNode(path, commit=self)
418 node = FileNode(path, commit=self, pre_load=pre_load)
419 419 else:
420 420 raise self.no_node_at_path(path)
421 421
@@ -289,7 +289,7 b' class MercurialCommit(base.BaseCommit):'
289 289
290 290 return nodes
291 291
292 def get_node(self, path):
292 def get_node(self, path, pre_load=None):
293 293 """
294 294 Returns `Node` object from the given `path`. If there is no node at
295 295 the given `path`, `NodeDoesNotExistError` would be raised.
@@ -298,7 +298,7 b' class MercurialCommit(base.BaseCommit):'
298 298
299 299 if path not in self.nodes:
300 300 if path in self._file_paths:
301 node = FileNode(path, commit=self)
301 node = FileNode(path, commit=self, pre_load=pre_load)
302 302 elif path in self._dir_paths:
303 303 if path == '':
304 304 node = RootNode(commit=self)
@@ -140,7 +140,7 b' class SubversionCommit(base.BaseCommit):'
140 140 lambda: self.repository.get_commit(commit_id=commit_id),
141 141 content)
142 142
143 def get_node(self, path):
143 def get_node(self, path, pre_load=None):
144 144 path = self._fix_path(path)
145 145 if path not in self.nodes:
146 146
@@ -152,7 +152,7 b' class SubversionCommit(base.BaseCommit):'
152 152 if node_type == 'dir':
153 153 node = nodes.DirNode(path, commit=self)
154 154 elif node_type == 'file':
155 node = nodes.FileNode(path, commit=self)
155 node = nodes.FileNode(path, commit=self, pre_load=pre_load)
156 156 else:
157 157 raise NodeDoesNotExistError(self.no_node_at_path(path))
158 158
@@ -290,8 +290,9 b' class FileNode(Node):'
290 290 :attribute: commit: if given, first time content is accessed, callback
291 291 :attribute: mode: stat mode for a node. Default is `FILEMODE_DEFAULT`.
292 292 """
293 _filter_pre_load = []
293 294
294 def __init__(self, path, content=None, commit=None, mode=None):
295 def __init__(self, path, content=None, commit=None, mode=None, pre_load=None):
295 296 """
296 297 Only one of ``content`` and ``commit`` may be given. Passing both
297 298 would raise ``NodeError`` exception.
@@ -308,6 +309,22 b' class FileNode(Node):'
308 309 self._content = content
309 310 self._mode = mode or FILEMODE_DEFAULT
310 311
312 self._set_bulk_properties(pre_load)
313
314 def _set_bulk_properties(self, pre_load):
315 if not pre_load:
316 return
317 pre_load = [entry for entry in pre_load
318 if entry not in self._filter_pre_load]
319 if not pre_load:
320 return
321
322 for attr_name in pre_load:
323 result = getattr(self, attr_name)
324 if callable(result):
325 result = result()
326 self.__dict__[attr_name] = result
327
311 328 @LazyProperty
312 329 def mode(self):
313 330 """
General Comments 0
You need to be logged in to leave comments. Login now