# HG changeset patch # User Daniel Dourvaris # Date 2019-08-23 18:31:43 # Node ID 4b32a14b2eda056981fa01d891bf731be5de82bb # Parent 2b1d7e0d88ab454459f3e29f3934daaf96d0f35f vcsserver: made binary content check be calculated on vcsserver - now can use caching - for git/hg there are faster dedicated functions instead of detecting the content diff --git a/rhodecode/lib/vcs/backends/base.py b/rhodecode/lib/vcs/backends/base.py --- a/rhodecode/lib/vcs/backends/base.py +++ b/rhodecode/lib/vcs/backends/base.py @@ -1054,6 +1054,12 @@ class BaseCommit(object): """ raise NotImplementedError + def is_node_binary(self, path): + """ + Returns ``True`` is given path is a binary file + """ + raise NotImplementedError + def get_file_content(self, path): """ Returns content of the file at the given `path`. diff --git a/rhodecode/lib/vcs/backends/git/commit.py b/rhodecode/lib/vcs/backends/git/commit.py --- a/rhodecode/lib/vcs/backends/git/commit.py +++ b/rhodecode/lib/vcs/backends/git/commit.py @@ -245,6 +245,10 @@ class GitCommit(base.BaseCommit): def is_link(self, path): return stat.S_ISLNK(self.get_file_mode(path)) + def is_node_binary(self, path): + tree_id, _ = self._get_tree_id_for_path(path) + return self._remote.is_binary(tree_id) + def get_file_content(self, path): """ Returns content of the file at given `path`. diff --git a/rhodecode/lib/vcs/backends/git/inmemory.py b/rhodecode/lib/vcs/backends/git/inmemory.py --- a/rhodecode/lib/vcs/backends/git/inmemory.py +++ b/rhodecode/lib/vcs/backends/git/inmemory.py @@ -58,10 +58,12 @@ class GitInMemoryCommit(base.BaseInMemor updated = [] for node in self.added + self.changed: - if not node.is_binary: + + if node.is_binary: + content = node.content + else: content = node.content.encode(ENCODING) - else: - content = node.content + updated.append({ 'path': node.path, 'node_path': node.name.encode(ENCODING), diff --git a/rhodecode/lib/vcs/backends/hg/commit.py b/rhodecode/lib/vcs/backends/hg/commit.py --- a/rhodecode/lib/vcs/backends/hg/commit.py +++ b/rhodecode/lib/vcs/backends/hg/commit.py @@ -231,6 +231,10 @@ class MercurialCommit(base.BaseCommit): path = self._get_filectx(path) return 'l' in self._remote.fctx_flags(self.raw_id, path) + def is_node_binary(self, path): + path = self._get_filectx(path) + return self._remote.is_binary(self.raw_id, path) + def get_file_content(self, path): """ Returns content of the file at given ``path``. diff --git a/rhodecode/lib/vcs/backends/svn/commit.py b/rhodecode/lib/vcs/backends/svn/commit.py --- a/rhodecode/lib/vcs/backends/svn/commit.py +++ b/rhodecode/lib/vcs/backends/svn/commit.py @@ -108,6 +108,10 @@ class SubversionCommit(base.BaseCommit): return self.get_file_content(path).startswith('link') return False + def is_node_binary(self, path): + path = self._fix_path(path) + return self._remote.is_binary(self._svn_rev, safe_str(path)) + def _get_file_property(self, path, name): file_properties = self._remote.node_properties( safe_str(path), self._svn_rev) diff --git a/rhodecode/lib/vcs/nodes.py b/rhodecode/lib/vcs/nodes.py --- a/rhodecode/lib/vcs/nodes.py +++ b/rhodecode/lib/vcs/nodes.py @@ -377,9 +377,7 @@ class FileNode(Node): """ if self.commit: return self.commit.get_file_content_streamed(self.path) - raise NodeError( - "Cannot retrieve message of the file without related " - "commit attribute") + raise NodeError("Cannot retrieve stream_bytes without related commit attribute") @LazyProperty def md5(self): @@ -581,8 +579,11 @@ class FileNode(Node): """ Returns True if file has binary content. """ - _bin = self.raw_bytes and '\0' in self.raw_bytes - return _bin + if self.commit: + return self.commit.is_node_binary(self.path) + else: + raw_bytes = self._content + return raw_bytes and '\0' in raw_bytes @LazyProperty def extension(self): @@ -742,8 +743,7 @@ class DirNode(Node): return self._nodes_dict[path] elif len(paths) > 1: if self.commit is None: - raise NodeError( - "Cannot access deeper nodes without commit") + raise NodeError("Cannot access deeper nodes without commit") else: path1, path2 = paths[0], '/'.join(paths[1:]) return self.get_node(path1).get_node(path2)