Show More
@@ -1054,6 +1054,12 b' class BaseCommit(object):' | |||||
1054 | """ |
|
1054 | """ | |
1055 | raise NotImplementedError |
|
1055 | raise NotImplementedError | |
1056 |
|
1056 | |||
|
1057 | def is_node_binary(self, path): | |||
|
1058 | """ | |||
|
1059 | Returns ``True`` is given path is a binary file | |||
|
1060 | """ | |||
|
1061 | raise NotImplementedError | |||
|
1062 | ||||
1057 | def get_file_content(self, path): |
|
1063 | def get_file_content(self, path): | |
1058 | """ |
|
1064 | """ | |
1059 | Returns content of the file at the given `path`. |
|
1065 | Returns content of the file at the given `path`. |
@@ -245,6 +245,10 b' class GitCommit(base.BaseCommit):' | |||||
245 | def is_link(self, path): |
|
245 | def is_link(self, path): | |
246 | return stat.S_ISLNK(self.get_file_mode(path)) |
|
246 | return stat.S_ISLNK(self.get_file_mode(path)) | |
247 |
|
247 | |||
|
248 | def is_node_binary(self, path): | |||
|
249 | tree_id, _ = self._get_tree_id_for_path(path) | |||
|
250 | return self._remote.is_binary(tree_id) | |||
|
251 | ||||
248 | def get_file_content(self, path): |
|
252 | def get_file_content(self, path): | |
249 | """ |
|
253 | """ | |
250 | Returns content of the file at given `path`. |
|
254 | Returns content of the file at given `path`. |
@@ -58,10 +58,12 b' class GitInMemoryCommit(base.BaseInMemor' | |||||
58 |
|
58 | |||
59 | updated = [] |
|
59 | updated = [] | |
60 | for node in self.added + self.changed: |
|
60 | for node in self.added + self.changed: | |
61 | if not node.is_binary: |
|
61 | ||
|
62 | if node.is_binary: | |||
|
63 | content = node.content | |||
|
64 | else: | |||
62 | content = node.content.encode(ENCODING) |
|
65 | content = node.content.encode(ENCODING) | |
63 | else: |
|
66 | ||
64 | content = node.content |
|
|||
65 | updated.append({ |
|
67 | updated.append({ | |
66 | 'path': node.path, |
|
68 | 'path': node.path, | |
67 | 'node_path': node.name.encode(ENCODING), |
|
69 | 'node_path': node.name.encode(ENCODING), |
@@ -231,6 +231,10 b' class MercurialCommit(base.BaseCommit):' | |||||
231 | path = self._get_filectx(path) |
|
231 | path = self._get_filectx(path) | |
232 | return 'l' in self._remote.fctx_flags(self.raw_id, path) |
|
232 | return 'l' in self._remote.fctx_flags(self.raw_id, path) | |
233 |
|
233 | |||
|
234 | def is_node_binary(self, path): | |||
|
235 | path = self._get_filectx(path) | |||
|
236 | return self._remote.is_binary(self.raw_id, path) | |||
|
237 | ||||
234 | def get_file_content(self, path): |
|
238 | def get_file_content(self, path): | |
235 | """ |
|
239 | """ | |
236 | Returns content of the file at given ``path``. |
|
240 | Returns content of the file at given ``path``. |
@@ -108,6 +108,10 b' class SubversionCommit(base.BaseCommit):' | |||||
108 | return self.get_file_content(path).startswith('link') |
|
108 | return self.get_file_content(path).startswith('link') | |
109 | return False |
|
109 | return False | |
110 |
|
110 | |||
|
111 | def is_node_binary(self, path): | |||
|
112 | path = self._fix_path(path) | |||
|
113 | return self._remote.is_binary(self._svn_rev, safe_str(path)) | |||
|
114 | ||||
111 | def _get_file_property(self, path, name): |
|
115 | def _get_file_property(self, path, name): | |
112 | file_properties = self._remote.node_properties( |
|
116 | file_properties = self._remote.node_properties( | |
113 | safe_str(path), self._svn_rev) |
|
117 | safe_str(path), self._svn_rev) |
@@ -377,9 +377,7 b' class FileNode(Node):' | |||||
377 | """ |
|
377 | """ | |
378 | if self.commit: |
|
378 | if self.commit: | |
379 | return self.commit.get_file_content_streamed(self.path) |
|
379 | return self.commit.get_file_content_streamed(self.path) | |
380 | raise NodeError( |
|
380 | raise NodeError("Cannot retrieve stream_bytes without related commit attribute") | |
381 | "Cannot retrieve message of the file without related " |
|
|||
382 | "commit attribute") |
|
|||
383 |
|
381 | |||
384 | @LazyProperty |
|
382 | @LazyProperty | |
385 | def md5(self): |
|
383 | def md5(self): | |
@@ -581,8 +579,11 b' class FileNode(Node):' | |||||
581 | """ |
|
579 | """ | |
582 | Returns True if file has binary content. |
|
580 | Returns True if file has binary content. | |
583 | """ |
|
581 | """ | |
584 | _bin = self.raw_bytes and '\0' in self.raw_bytes |
|
582 | if self.commit: | |
585 | return _bin |
|
583 | return self.commit.is_node_binary(self.path) | |
|
584 | else: | |||
|
585 | raw_bytes = self._content | |||
|
586 | return raw_bytes and '\0' in raw_bytes | |||
586 |
|
587 | |||
587 | @LazyProperty |
|
588 | @LazyProperty | |
588 | def extension(self): |
|
589 | def extension(self): | |
@@ -742,8 +743,7 b' class DirNode(Node):' | |||||
742 | return self._nodes_dict[path] |
|
743 | return self._nodes_dict[path] | |
743 | elif len(paths) > 1: |
|
744 | elif len(paths) > 1: | |
744 | if self.commit is None: |
|
745 | if self.commit is None: | |
745 | raise NodeError( |
|
746 | raise NodeError("Cannot access deeper nodes without commit") | |
746 | "Cannot access deeper nodes without commit") |
|
|||
747 | else: |
|
747 | else: | |
748 | path1, path2 = paths[0], '/'.join(paths[1:]) |
|
748 | path1, path2 = paths[0], '/'.join(paths[1:]) | |
749 | return self.get_node(path1).get_node(path2) |
|
749 | return self.get_node(path1).get_node(path2) |
General Comments 0
You need to be logged in to leave comments.
Login now