Show More
@@ -393,7 +393,7 b' class GitCommit(base.BaseCommit):' | |||||
393 | nodes.sort() |
|
393 | nodes.sort() | |
394 | return nodes |
|
394 | return nodes | |
395 |
|
395 | |||
396 | def get_node(self, path): |
|
396 | def get_node(self, path, pre_load=None): | |
397 | if isinstance(path, unicode): |
|
397 | if isinstance(path, unicode): | |
398 | path = path.encode('utf-8') |
|
398 | path = path.encode('utf-8') | |
399 | path = self._fix_path(path) |
|
399 | path = self._fix_path(path) | |
@@ -415,7 +415,7 b' class GitCommit(base.BaseCommit):' | |||||
415 | else: |
|
415 | else: | |
416 | node = DirNode(path, commit=self) |
|
416 | node = DirNode(path, commit=self) | |
417 | elif type_ == 'blob': |
|
417 | elif type_ == 'blob': | |
418 | node = FileNode(path, commit=self) |
|
418 | node = FileNode(path, commit=self, pre_load=pre_load) | |
419 | else: |
|
419 | else: | |
420 | raise self.no_node_at_path(path) |
|
420 | raise self.no_node_at_path(path) | |
421 |
|
421 |
@@ -289,7 +289,7 b' class MercurialCommit(base.BaseCommit):' | |||||
289 |
|
289 | |||
290 | return nodes |
|
290 | return nodes | |
291 |
|
291 | |||
292 | def get_node(self, path): |
|
292 | def get_node(self, path, pre_load=None): | |
293 | """ |
|
293 | """ | |
294 | Returns `Node` object from the given `path`. If there is no node at |
|
294 | Returns `Node` object from the given `path`. If there is no node at | |
295 | the given `path`, `NodeDoesNotExistError` would be raised. |
|
295 | the given `path`, `NodeDoesNotExistError` would be raised. | |
@@ -298,7 +298,7 b' class MercurialCommit(base.BaseCommit):' | |||||
298 |
|
298 | |||
299 | if path not in self.nodes: |
|
299 | if path not in self.nodes: | |
300 | if path in self._file_paths: |
|
300 | if path in self._file_paths: | |
301 | node = FileNode(path, commit=self) |
|
301 | node = FileNode(path, commit=self, pre_load=pre_load) | |
302 | elif path in self._dir_paths: |
|
302 | elif path in self._dir_paths: | |
303 | if path == '': |
|
303 | if path == '': | |
304 | node = RootNode(commit=self) |
|
304 | node = RootNode(commit=self) |
@@ -140,7 +140,7 b' class SubversionCommit(base.BaseCommit):' | |||||
140 | lambda: self.repository.get_commit(commit_id=commit_id), |
|
140 | lambda: self.repository.get_commit(commit_id=commit_id), | |
141 | content) |
|
141 | content) | |
142 |
|
142 | |||
143 | def get_node(self, path): |
|
143 | def get_node(self, path, pre_load=None): | |
144 | path = self._fix_path(path) |
|
144 | path = self._fix_path(path) | |
145 | if path not in self.nodes: |
|
145 | if path not in self.nodes: | |
146 |
|
146 | |||
@@ -152,7 +152,7 b' class SubversionCommit(base.BaseCommit):' | |||||
152 | if node_type == 'dir': |
|
152 | if node_type == 'dir': | |
153 | node = nodes.DirNode(path, commit=self) |
|
153 | node = nodes.DirNode(path, commit=self) | |
154 | elif node_type == 'file': |
|
154 | elif node_type == 'file': | |
155 | node = nodes.FileNode(path, commit=self) |
|
155 | node = nodes.FileNode(path, commit=self, pre_load=pre_load) | |
156 | else: |
|
156 | else: | |
157 | raise NodeDoesNotExistError(self.no_node_at_path(path)) |
|
157 | raise NodeDoesNotExistError(self.no_node_at_path(path)) | |
158 |
|
158 |
@@ -290,8 +290,9 b' class FileNode(Node):' | |||||
290 | :attribute: commit: if given, first time content is accessed, callback |
|
290 | :attribute: commit: if given, first time content is accessed, callback | |
291 | :attribute: mode: stat mode for a node. Default is `FILEMODE_DEFAULT`. |
|
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 | Only one of ``content`` and ``commit`` may be given. Passing both |
|
297 | Only one of ``content`` and ``commit`` may be given. Passing both | |
297 | would raise ``NodeError`` exception. |
|
298 | would raise ``NodeError`` exception. | |
@@ -308,6 +309,22 b' class FileNode(Node):' | |||||
308 | self._content = content |
|
309 | self._content = content | |
309 | self._mode = mode or FILEMODE_DEFAULT |
|
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 | @LazyProperty |
|
328 | @LazyProperty | |
312 | def mode(self): |
|
329 | def mode(self): | |
313 | """ |
|
330 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now