From 3d203c153301d4dd9c3285e7dea86ee09eb3b0c5 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 20 Feb 2007 02:21:25 -0800 Subject: mid-progress, work on git-browser fan is dying, more work to do though! TODO: seperate style for git_browser, use "block.super" --- bn_django/git_browse/models.py | 25 +++++++++++ bn_django/git_browse/templates/git_browse/obj.html | 2 +- .../templates/git_browse/repository_info.html | 52 +++++++++++++++++++++- bn_django/git_browse/urls.py | 11 ++++- bn_django/git_browse/views.py | 33 ++++++++------ 5 files changed, 104 insertions(+), 19 deletions(-) (limited to 'bn_django/git_browse') diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index 765fe02..be097f8 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -5,6 +5,13 @@ try: GITBROWSE_BASE = settings.GITBROWSE_BASE except AttributeError: GITBROWSE_BASE='/home' +if GITBROWSE_BASE[-1] != '/': + GITBROWSE_BASE += '/' + +try: + GITCOMMAND = settings.GITCOMMAND +except AttributeError: + GITCOMMAND='git' try: ADMIN_URL = settings.ADMIN_URL @@ -34,6 +41,24 @@ class Repository(models.Model): def get_admin_url(self): return "%s/code/repository/%s/" % (ADMIN_URL, self.slug) + def scan(self): + import os + + GITPREFIX = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \ + + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git ' + 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 + 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 + + return (GITPREFIX, heads, tags) + 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/obj.html b/bn_django/git_browse/templates/git_browse/obj.html index be0b556..0170eab 100644 --- a/bn_django/git_browse/templates/git_browse/obj.html +++ b/bn_django/git_browse/templates/git_browse/obj.html @@ -3,7 +3,7 @@ {% block gitbrowse %} {% if contents %}

Object sha1 hash: {{ hash }}
- Size: {{ size }} kB
+ Size: {{ size|filesizeformat }}
Type: "{{ type }}"

{{ contents }}
{% else %} 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 72f30b1..b3028a2 100644 --- a/bn_django/git_browse/templates/git_browse/repository_info.html +++ b/bn_django/git_browse/templates/git_browse/repository_info.html @@ -5,7 +5,55 @@ {% if shortlog %}

Shortlog (full log)

{{ shortlog }}
-

Filelist (browse)

-
{{ filelist }}
+

Heads (browse)

+{% if heads %} + +{% for h in heads.iteritems %} + + + + +{% endfor %} +
+ + {{ h.0 }} + + {{ h.1 }} + {% for t in tags.iteritems %} + {% ifequal h.1 t.1 %} + + [{{ t.0 }}] + {% endifequal %}{% endfor %} +
+{% else %}No heads!{% endif %} +

Tags (browse)

+{% if tags %} + +{% for t in tags.iteritems %} + + + + + {% endfor %} +{% endfor %} +
+ + {{ t.0 }} + + {{ t.1 }} + {% for t in tags.iteritems %} + {% ifequal h.1 t.1 %} + + [{{ t.0 }}] + {% endifequal %}
+{% else %}No tags!{% endif %} +

Filelist (browse tree)

+{% if filelist %}
{{ filelist }}
+{% else %}No files!{% endif %} {% endif %} {% endblock %} diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py index 909bfcd..77fabd3 100644 --- a/bn_django/git_browse/urls.py +++ b/bn_django/git_browse/urls.py @@ -32,10 +32,17 @@ urlpatterns = patterns('django.views.generic.list_detail', urlpatterns += patterns('bn_django.git_browse.views', (r'^(?P[\w\-\_]*)/$', 'repo_info',), - (r'^(?P[\w\-\_]*)/tree/$', 'view_tree',), (r'^(?P[\w\-\_]*)/branches/$', 'view_branches',), - (r'^(?P[\w\-\_]*)/history/$', 'view_history',), (r'^(?P[\w\-\_]*)/log/$', 'view_log',), (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]{40})/$', 'view_obj',), + (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]{40})/log/$', 'view_log',), + (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/commit/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/tag/(?P[0-9a-z]{40})/$', 'view_tag',), + (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/$', 'view_blob',), + (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/raw/$', 'view_blob',), + (r'^(?P[\w\-\_]*)/tree/$', 'view_tree',), (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/gz/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/tar/$', 'view_tree',), ) diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index c8a7a40..d8e01d7 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -23,26 +23,29 @@ except AttributeError: def repo_info(request, repo,branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' - - shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND + '-shortlog') + shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND \ + + '-shortlog') + branches = commands.getoutput(GITPREFIX + ' branch') filelist = commands.getoutput(GITPREFIX + ' ls-files') - - return render_to_response('git_browse/repository_info.html', - dict(object=therepo, - filelist=filelist, + return render_to_response('git_browse/repository_info.html', \ + dict(object=therepo, \ + filelist=filelist, \ + tags=tags, \ + heads=heads, \ shortlog=shortlog,)) def view_tree(request, repo, hash=None,branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' - if(hash == None): - head_ref = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat HEAD') + head_ref = commands.getoutput('cd ' + GITBROWSE_BASE \ + + therepo.slug +'/.git; cat HEAD') head_ref = head_ref.split()[1] - hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat ' + head_ref) + hash = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug \ + +'/.git; cat ' + head_ref) tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + hash) tree_objs = list() @@ -65,8 +68,10 @@ def view_tree(request, repo, hash=None,branch=None): def view_log(request, repo, tree_hash=None, branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' + GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND \ + + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' logtxt = commands.getoutput(GITPREFIX + ' log | cat') log_items = logtxt.split('\ncommit ') @@ -94,8 +99,8 @@ def view_log(request, repo, tree_hash=None, branch=None): def view_obj(request, repo, hash, branch=None): therepo = get_object_or_404(Repository, slug=repo) + (GITPREFIX, heads, tags) = therepo.scan() - GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git ' obj_type = commands.getoutput(GITPREFIX + ' cat-file -t ' + hash) #if(obj_type == 'tree'): # redirect_to('../tree/' + hash); @@ -109,5 +114,5 @@ def view_obj(request, repo, hash, branch=None): dict(object=therepo, hash=hash, type=obj_type, - size=float(obj_size)/1024.0, + size=float(obj_size), contents=obj_contents)) -- cgit v1.2.3