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
This commit is contained in:
parent
de8ff5bcfa
commit
38b8c11ea5
6 changed files with 30 additions and 10 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -58,10 +58,12 @@ class GitInMemoryCommit(base.BaseInMemoryCommit):
|
|||
|
||||
updated = []
|
||||
for node in self.added + self.changed:
|
||||
if not node.is_binary:
|
||||
content = node.content.encode(ENCODING)
|
||||
else:
|
||||
|
||||
if node.is_binary:
|
||||
content = node.content
|
||||
else:
|
||||
content = node.content.encode(ENCODING)
|
||||
|
||||
updated.append({
|
||||
'path': node.path,
|
||||
'node_path': node.name.encode(ENCODING),
|
||||
|
|
|
|||
|
|
@ -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``.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue