Martin Vium  committed 1f21430

files: largefile support for show and download raw and add image previewing

  • Participants
  • Parent commits 51c43e3
  • Branches default

Comments (0)

Files changed (4)

File kallithea/controllers/

         response.content_type = file_node.mimetype
-        return file_node.content
+        return file_node.http_write_or_return(response)
     @HasRepoPermissionAnyDecorator('', 'repository.write',
         response.content_disposition = dispo
         response.content_type = mimetype
-        return file_node.content
+        return file_node.http_write_or_return(response)
     @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')

File kallithea/lib/vcs/backends/hg/

 from kallithea.lib.vcs.utils import safe_str, safe_unicode, date_fromtimestamp
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.vcs.utils.paths import get_dirs_for_path
-from kallithea.lib.vcs.utils.hgcompat import archival, hex
+from kallithea.lib.vcs.utils.hgcompat import archival, hex, lfutil
 class MercurialChangeset(BaseChangeset):
         fctx = self._get_filectx(path)
+    def get_largefile_path(self, path):
+        """
+        Return the path to the largefile in the store
+        """
+        if lfutil.isstandin(path):
+            sha = self.get_file_content(path).strip()
+            return lfutil.findfile(self.repository._repo, sha)
     def get_file_size(self, path):
         Returns size of the file at given ``path``.

File kallithea/lib/vcs/

 import stat
 import posixpath
 import mimetypes
+import shutil
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import NodeError, RemovedFileNodeError
+    def http_write_or_return(self, response):
+        if self.changeset:
+            lfpath = self.changeset.get_largefile_path(self.path)
+            if lfpath:
+                with open(lfpath, 'rb') as f:
+                    shutil.copyfileobj(f, response)
+                return ''
+        return self.content
     def extension(self):
         """Returns filenode extension"""

File kallithea/lib/vcs/utils/

 from mercurial.util import url as hg_url
 from mercurial.scmutil import revrange
 from mercurial.node import nullrev
+from hgext.largefiles import lfutil
-# those authnadlers are patched for python 2.6.5 bug an
+# those authhandlers are patched for python 2.6.5 bug an
 # infinit looping when given invalid resources
 from mercurial.url import httpbasicauthhandler, httpdigestauthhandler