aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django/git_browse
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django/git_browse')
-rw-r--r--bn_django/git_browse/models.py41
-rw-r--r--bn_django/git_browse/templates/git_browse/base.html9
-rw-r--r--bn_django/git_browse/templates/git_browse/repository_info.html4
-rw-r--r--bn_django/git_browse/views.py4
4 files changed, 43 insertions, 15 deletions
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 %}
- <a href="/code/">code</a> &raquo;
+{{ block.super }}
{% if object %}
- <a href="/code/{{ object.slug }}/">{{ object.name }}</a>
+ <a href="/code/{{ object.slug }}/">{{ object.name }}</a>
+ [<a href="/code/{{ object.slug }}/tree/">browse</a>,
+ <a href="/code/{{ object.slug }}/log/">log</a>]
{% endif %}
{% endblock %}
@@ -30,9 +32,6 @@
<a href="/code/{{ object.slug }}/tree/">browse tree</a> - <a href="/code/{{ object.slug }}/log">full log</a>
</span>
<br />
- {% if raw %}
- <pre>{{raw}}</pre>
- {% endif %}
{% else %}
<p>No such repository!</p>
{% 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 %}
<h3>Shortlog (<a href="/code/{{object.slug}}/log/">full log</a>)</h3>
-<pre>{{ shortlog }}</pre>
+{% include "git_browse/shortlog_table" %}
<h3>Heads (<a href="/code/{{object.slug}}/tree/">browse</a>)</h3>
{% include "git_browse/heads_table" %}
<h3>Tags (<a href="/code/{{object.slug}}/tree/">browse</a>)</h3>
@@ -12,5 +11,4 @@
<h3>Filelist (<a href="/code/{{object.slug}}/tree/">browse tree</a>)</h3>
{% if filelist %} <pre class="large">{{ filelist }}</pre>
{% 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, \