diff options
author | bnewbold <bnewbold@manus.(none)> | 2007-08-08 03:23:36 -0400 |
---|---|---|
committer | bnewbold <bnewbold@manus.(none)> | 2007-08-08 03:23:36 -0400 |
commit | 9581828aa8489b7f09f1f6bf627faf231789cf84 (patch) | |
tree | 882087776d25a205506e02bf4a301359522afee4 /bn_django | |
parent | a891065a0447396a89fd03e4f038ca2e996a68aa (diff) | |
download | bnewnet-9581828aa8489b7f09f1f6bf627faf231789cf84.tar.gz bnewnet-9581828aa8489b7f09f1f6bf627faf231789cf84.zip |
zip downloads of tree-like objects
Diffstat (limited to 'bn_django')
-rw-r--r-- | bn_django/git_browse/models.py | 12 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/blob.html | 1 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/tree_table | 3 | ||||
-rw-r--r-- | bn_django/git_browse/urls.py | 5 | ||||
-rw-r--r-- | bn_django/git_browse/views.py | 13 |
5 files changed, 25 insertions, 9 deletions
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index 2af2c98..b2e62df 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -110,6 +110,8 @@ class Tree(models.Model): import commands if (not self.id): return + GITPREFIX = self.repo.getGITPREFIX() + self.id = self.id.strip() tree_ls = commands.getoutput(GITPREFIX + ' ls-tree --full-name ' \ + self.id) @@ -127,12 +129,12 @@ class Tree(models.Model): t.name = t.path tree_objs.append(t) if l[1] == 'blob': - i = Item(id=l[2]) - i.path = ' '.join(l[3:]) + b = Blob(id=l[2]) + b.path = ' '.join(l[3:]) if self.path and self.path != '/': - i.path = self.path + '/' + i.path - i.name=i.path - blob_objs.append(i) + b.path = self.path + '/' + b.path + b.name=b.path + blob_objs.append(b) self.tree_objs = tree_objs self.blob_objs = blob_objs self.all_objs = tree_objs + blob_objs diff --git a/bn_django/git_browse/templates/git_browse/blob.html b/bn_django/git_browse/templates/git_browse/blob.html index 3730807..4a0304c 100644 --- a/bn_django/git_browse/templates/git_browse/blob.html +++ b/bn_django/git_browse/templates/git_browse/blob.html @@ -5,7 +5,6 @@ {{ hash }}<br /> <h3>Size</h3> {{ size|filesizeformat }}<br /> - <h3><a href="zip">Download zip</a></h3> <h3>Raw contents</h3> <pre class="large">{{ contents|escape|wordwrap:80 }}</pre> {% else %} diff --git a/bn_django/git_browse/templates/git_browse/tree_table b/bn_django/git_browse/templates/git_browse/tree_table index 7f67fe9..ce10c10 100644 --- a/bn_django/git_browse/templates/git_browse/tree_table +++ b/bn_django/git_browse/templates/git_browse/tree_table @@ -10,8 +10,7 @@ <a href='/code/{{ object.slug }}/blob/{{ o.id }}/' class="blob"> {{o.name}}</a> </td><td type="links"> - <a href='/code/{{object.slug}}/tree/{{ o.id }}/'>log</a> | - <a href='/code/{{object.slug}}/tree/{{ o.id }}/zip/'>zip</a> + <a href='/code/{{object.slug}}/tree/{{ o.id }}/'>log</a> </td> {% else %} {% ifequal o.type 'tree' %} <a href='/code/{{object.slug}}/tree/{{ o.id }}/' class="tree"> diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py index 4c88b99..141f533 100644 --- a/bn_django/git_browse/urls.py +++ b/bn_django/git_browse/urls.py @@ -35,11 +35,14 @@ urlpatterns += patterns('bn_django.git_browse.views', (r'^(?P<repo>[\w\-\_]*)/obj/(?P<hash>[0-9a-z]{40})/$', 'view_obj',), (r'^(?P<repo>[\w\-\_]*)/commit/(?P<hash>[0-9a-z]{40})/$', 'view_commit',), (r'^(?P<repo>[\w\-\_]*)/commit/$', 'view_commit',), + (r'^(?P<repo>[\w\-\_]*)/commit/(?P<hash>[0-9a-z]{40})/zip/$', 'zip',), #TODO: head and tag views (r'^(?P<repo>[\w\-\_]*)/tag/(?P<hash>[\w\-\_]+)/$', 'view_commit',), + (r'^(?P<repo>[\w\-\_]*)/tag/(?P<hash>[0-9a-z]{40})/zip/$', 'zip',), (r'^(?P<repo>[\w\-\_]*)/head/(?P<hash>[\w\-\_]+)/$', 'view_commit',), + (r'^(?P<repo>[\w\-\_]*)/head/(?P<hash>[0-9a-z]{40})/zip/$', 'zip',), (r'^(?P<repo>[\w\-\_]*)/blob/(?P<hash>[0-9a-z]{40})/$', 'view_blob',), (r'^(?P<repo>[\w\-\_]*)/tree/$', 'view_tree',), (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/$', 'view_tree',), - (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/zip/$', 'view_tree',), + (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/zip/$', 'zip',), ) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index 1f1b03c..79b3573 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -144,3 +144,16 @@ def view_obj(request, repo, hash, branch=None): type=obj_type, size=float(obj_size), contents=obj_contents)) + +def zip(request, repo, hash): + therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() + t = Tree(id=hash,repo=therepo) + t.update() + + hr = HttpResponse(mimetype="application/zip") + hr['Content-Disposition'] = 'filename=%s.zip' % t.id + archive = commands.getoutput(GITPREFIX + \ + ' archive --format=zip ' + hash + ' | cat') + hr.write(archive) + return hr |