From 5eb42d9e35ef0f94da4254552f6ac0ed184775a0 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 20 Feb 2007 20:33:11 -0800 Subject: wrapped up git_browse tree for now, filled in Blob object --- bn_django/git_browse/models.py | 12 +++++ .../git_browse/templates/git_browse/full_log.html | 3 +- .../git_browse/templates/git_browse/tree.html | 20 ++------- .../git_browse/templates/git_browse/tree_table | 52 +++++++++++++--------- bn_django/git_browse/views.py | 11 +++++ static/style/git_browse.css | 46 +++++++++++-------- 6 files changed, 87 insertions(+), 57 deletions(-) diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index db69bfc..edddf60 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -119,6 +119,8 @@ class Blob(models.Model): path = models.CharField("relative path from repo base", maxlength=512) id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) name = models.CharField("name of dir", maxlength=128,blank=False) + size = models.IntField("filesize in byte", maxlength=128,blank=False) + contents = models.TextField("ASCII contents of the file") type='blob' class Admin: @@ -130,6 +132,16 @@ class Blob(models.Model): return "/code/%s/%s" % (self.repo.slug, self.hash) def get_admin_url(self): return "%s/code/tree/%s/" % (ADMIN_URL, self.id) + + def update(self): + import commands + + if not self.id: return + self.id = self.id.strip() + self.contents = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id) + self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + hash) + + def blob_from_str(s): s = s.split(); diff --git a/bn_django/git_browse/templates/git_browse/full_log.html b/bn_django/git_browse/templates/git_browse/full_log.html index a467ae8..75ea2ab 100644 --- a/bn_django/git_browse/templates/git_browse/full_log.html +++ b/bn_django/git_browse/templates/git_browse/full_log.html @@ -8,7 +8,8 @@ Hash: {{ item.hash }}
Author: {{ item.author }}
Date: {{ item.date }} -
Comment:
{{ item.comment }}
+
Comment: +
{{ item.comment|wordwrap:80 }}
{% endfor %} {% endif %} {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/tree.html b/bn_django/git_browse/templates/git_browse/tree.html index 3c8c294..79a8f39 100644 --- a/bn_django/git_browse/templates/git_browse/tree.html +++ b/bn_django/git_browse/templates/git_browse/tree.html @@ -2,22 +2,8 @@ {% block gitbrowse %} -

Tree sha1 hash:


{{ hash }}
+

Tree sha1 hash:

+ {{ hash }}

Directory listing:

- {% include tree_table %} - {% if tree_objs %} - {% for o in tree_objs %} - [{{o.type}}] {{ o.mode }} - {% ifequal o.type 'blob' %} - {{o.name}} - {% else %} - {% ifequal o.type 'tree' %} - {{o.name}} - {% else %} - {{o.name}} - {% endifequal %}{% endifequal %} -
- {% endfor %} - {% else %}No contents! - {% endif %} + {% include "git_browse/tree_table" %} {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/tree_table b/bn_django/git_browse/templates/git_browse/tree_table index 7df504a..a472283 100644 --- a/bn_django/git_browse/templates/git_browse/tree_table +++ b/bn_django/git_browse/templates/git_browse/tree_table @@ -1,23 +1,33 @@ -{% if tags %} +{% if tree_objs %} -{% for t in tags.iteritems %} - - - - -{% endfor %} + {% for o in tree_objs %} + + + + {% else %} {% ifequal o.type 'tree' %} + + {{o.name}}/ + + {% else %} + + {{o.name}} + + {% endifequal %}{% endifequal %} + + {% endfor %}
- - {{ t.0 }} - {% for h in heads.iteritems %} - {% ifequal h.1 t.1 %} - - [{{ h.0 }}] - {% endifequal %} - {% endfor %} - - {{ t.1 }}
+ {{o.type}} + {{ o.mode }} + {% ifequal o.type 'blob' %} + + {{o.name}} + + log | + zip + + browse | + zip + +
-{% else %}No tags!{% endif %} +{% else %}No contents! +{% endif %} diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index 8a84241..e27d949 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -96,6 +96,17 @@ def view_log(request, repo, tree_hash=None, branch=None): return render_to_response('git_browse/full_log.html', dict(object=therepo, log_objs=log_objs,)) +def view_blob(request, repo, hash, branch=None): + therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() + blob = Blob(hash=hash,repo=therepo) + blob.update() + + return render_to_response('git_browse/obj.html', + dict(object=therepo, + hash=blob.id, + size=blob.size, + contents=blob.contents)) def view_obj(request, repo, hash, branch=None): therepo = get_object_or_404(Repository, slug=repo) diff --git a/static/style/git_browse.css b/static/style/git_browse.css index bf9974d..7fc04e8 100644 --- a/static/style/git_browse.css +++ b/static/style/git_browse.css @@ -9,49 +9,59 @@ pre.large { table.gitbrowser { width: 100%; border-spacing: 0px; - font-size: 11px; -} + font-size: 11px; } table.gitbrowser tr { width: 100%; - background-color: #EEEEEE; -} + background-color: #EEEEEE; } td.head { font-weight: bold; padding-left: 13px; width: 130px; - overflow: hidden; -} + overflow: hidden; } +td.links { + width: 90px; + overflow: hidden; } +td.objtype { + width: 35px; + font-style: italic; } +td.filemode { + width: 55px; + font-family: courier; } +td.filename { + width: 450px; } +td.filename a.tree { + font-weight: bold; } +td.filename a.blob { + font-weight: normal; } td.tag { font-weight: bold; padding-left: 13px; width: 130px; - overflow: hidden; -} + overflow: hidden; } td.date { font-style: italic; width: 90px; - overflow: hidden; -} + overflow: hidden; } td.author { font-style: italic; width: 100px; - overflow: hidden; -} + overflow: hidden; } td.description { - overflow: hidden; -} + overflow: hidden; } td.shorthash { width: 60px; overflow: hidden; text-align: right; - font-family: courier; -} + font-family: courier; } td.hash { width: 100px; overflow: hidden; text-align: right; - font-family: courier; -} + font-family: courier; } + +span.hash { + font-family: courier; } + a.head { color: green; } -- cgit v1.2.3