From 7adab6520975d9a8650a214ca519f2357707bd65 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 20 Feb 2007 19:22:14 -0800 Subject: git_browse: actually moved heads_table and tags_table to seperate files created shortlog_table --- bn_django/git_browse/models.py | 41 +++++++++++++++++++--- .../git_browse/templates/git_browse/base.html | 9 +++-- .../templates/git_browse/repository_info.html | 4 +-- bn_django/git_browse/views.py | 4 +-- 4 files changed, 43 insertions(+), 15 deletions(-) (limited to 'bn_django/git_browse') diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index be097f8..db69bfc 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -49,16 +49,47 @@ class Repository(models.Model): heads = dict() for h in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/heads/'): f = open(GITBROWSE_BASE + self.slug + '/.git/refs/heads/' + h,'r') - heads[h] = f.readline() - f.close + heads[h.strip()] = f.readline().strip() + f.close() tags = dict() for t in os.listdir(GITBROWSE_BASE + self.slug + '/.git/refs/tags/'): f = open(GITBROWSE_BASE + self.slug + '/.git/refs/tags/' + t,'r') - tags[t] = f.readline() - f.close - + tags[t.strip()] = f.readline().strip() + f.close() return (GITPREFIX, heads, tags) + + def shortlog(self): + import commands + + GITPREFIX = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \ + + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git ' + logtxt = commands.getoutput(GITPREFIX + ' log --relative-date --max-count=6 | cat') + log_items = logtxt.split('\ncommit ') + if (log_items[0] == ''): + log_items.pop(0) + if (log_items[0].startswith('commit ')): + log_items[0] = log_items[0][7:] + shortlog = list() + for li in log_items: + logobj = dict() + lines = li.splitlines() + if len(lines) < 3: continue + logobj['hash'] = lines[0].strip() + logobj['shorthash'] = lines[0].strip()[:5] + logobj['author'] = lines[1][8:] + logobj['date'] = lines[2][8:] + if len(lines) > 4: + logobj['description'] = lines[4][4:] + else: + logobj['description'] = '(none)' + # here we truncate commit comments for shortlogs + logobj['shortdescription'] = logobj['description'][:128] + shortlog.append(logobj) + return shortlog + + + class Tree(models.Model): repo = models.ForeignKey(Repository) mode = models.CharField("file mode/permissions", blank=False,maxlength=4) diff --git a/bn_django/git_browse/templates/git_browse/base.html b/bn_django/git_browse/templates/git_browse/base.html index 93814c1..d23ab55 100644 --- a/bn_django/git_browse/templates/git_browse/base.html +++ b/bn_django/git_browse/templates/git_browse/base.html @@ -9,9 +9,11 @@ {% endblock %} {% block path %} - code » +{{ block.super }} {% if object %} - {{ object.name }} + {{ object.name }} + [browse, + log] {% endif %} {% endblock %} @@ -30,9 +32,6 @@ browse tree - full log
- {% if raw %} -
{{raw}}
- {% endif %} {% else %}

No such repository!

{% endif %} diff --git a/bn_django/git_browse/templates/git_browse/repository_info.html b/bn_django/git_browse/templates/git_browse/repository_info.html index 51794d3..f45eeb8 100644 --- a/bn_django/git_browse/templates/git_browse/repository_info.html +++ b/bn_django/git_browse/templates/git_browse/repository_info.html @@ -2,9 +2,8 @@ {% block gitbrowse %} {{ object.description }} -{% if shortlog %}

Shortlog (full log)

-
{{ shortlog }}
+{% include "git_browse/shortlog_table" %}

Heads (browse)

{% include "git_browse/heads_table" %}

Tags (browse)

@@ -12,5 +11,4 @@

Filelist (browse tree)

{% if filelist %}
{{ filelist }}
{% else %}No files!{% endif %} -{% endif %} {% endblock %} diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index d8e01d7..3439c35 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -25,10 +25,10 @@ def repo_info(request, repo,branch=None): therepo = get_object_or_404(Repository, slug=repo) (GITPREFIX, heads, tags) = therepo.scan() - shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND \ - + '-shortlog') branches = commands.getoutput(GITPREFIX + ' branch') filelist = commands.getoutput(GITPREFIX + ' ls-files') + shortlog = therepo.shortlog() + return render_to_response('git_browse/repository_info.html', \ dict(object=therepo, \ filelist=filelist, \ -- cgit v1.2.3