From c7d2898a12563c0b251f02fae55419baf07b7a6c Mon Sep 17 00:00:00 2001
From: Jonas Haag <jonas@lophus.org>
Date: Sat, 21 Jun 2014 18:21:04 +0200
Subject: [PATCH] Download: tar -> tar.gz

---
 klaus/tarutils.py             | 4 ++--
 klaus/templates/tree.inc.html | 2 +-
 klaus/views.py                | 9 +++++----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/klaus/tarutils.py b/klaus/tarutils.py
index fcdf7f5..3eeb2d6 100644
--- a/klaus/tarutils.py
+++ b/klaus/tarutils.py
@@ -39,7 +39,7 @@ class ListBytesIO(object):
         return b''.join(buf)
 
 
-def tar_stream(repo, tree, mtime):
+def tar_stream(repo, tree, mtime, format=''):
     """
     Returns a generator that lazily assembles a .tar.gz archive, yielding it in
     pieces (bytestrings). To obtain the complete .tar.gz binary file, simply
@@ -50,7 +50,7 @@ def tar_stream(repo, tree, mtime):
     time of all files in the resulting .tar.gz archive.
     """
     buf = BytesIO()
-    with tarfile.open(None, "w", buf) as tar:
+    with tarfile.open(None, "w:%s" % format, buf) as tar:
         for entry_abspath, entry in walk_tree(repo, tree):
             blob = repo[entry.sha]
             data = ListBytesIO(blob.chunked)
diff --git a/klaus/templates/tree.inc.html b/klaus/templates/tree.inc.html
index 94481e2..2a1b5d0 100644
--- a/klaus/templates/tree.inc.html
+++ b/klaus/templates/tree.inc.html
@@ -1,6 +1,6 @@
 <div class=tree>
   <h2>Tree @<a href="{{ url_for('commit', repo=repo.name, rev=rev) }}">{{ rev|shorten_sha1 }}</a>
-    <span>(<a href="{{ url_for('download', repo=repo.name, rev=rev) }}">Download tar</a>)</span>
+    <span>(<a href="{{ url_for('download', repo=repo.name, rev=rev) }}">Download .tar.gz</a>)</span>
   </h2>
   <ul>
     {% for _, name, fullpath in root_tree.dirs %}
diff --git a/klaus/views.py b/klaus/views.py
index 07c27fe..dedbcff 100644
--- a/klaus/views.py
+++ b/klaus/views.py
@@ -235,10 +235,10 @@ class RawView(BlobViewMixin, BaseRepoView):
 
 class DownloadView(BaseRepoView):
     """
-    Download a repo as a tar file
+    Download a repo as a tar.gz file
     """
     def get_response(self):
-        tarname = "%s@%s.tar" % (self.context['repo'].name, self.context['rev'])
+        tarname = "%s@%s.tar.gz" % (self.context['repo'].name, self.context['rev'])
         headers = {
             'Content-Disposition': "attachment; filename=%s" % tarname,
             'Cache-Control': "no-store",  # Disables browser caching
@@ -247,11 +247,12 @@ class DownloadView(BaseRepoView):
         tar_stream = tarutils.tar_stream(
             self.context['repo'],
             self.context['blob_or_tree'],
-            self.context['commit'].commit_time
+            self.context['commit'].commit_time,
+            format="gz"
         )
         return Response(
             tar_stream,
-            mimetype="application/tar",
+            mimetype="application/x-tgz",
             headers=headers
         )
 
-- 
GitLab