summaryrefslogtreecommitdiffstats
path: root/bn_django/git_browse/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django/git_browse/views.py')
-rw-r--r--bn_django/git_browse/views.py94
1 files changed, 87 insertions, 7 deletions
diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py
index c0966b0..9e3ba90 100644
--- a/bn_django/git_browse/views.py
+++ b/bn_django/git_browse/views.py
@@ -1,4 +1,4 @@
-from django.conf import settings
+import settings
from django import forms, http, template
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render_to_response
@@ -13,16 +13,96 @@ try:
except AttributeError:
GITBROWSE_BASE='/home/'
+try:
+ GITCOMMAND = settings.GITCOMMAND
+except AttributeError:
+ GITCOMMAND='git'
+
# Create your views here.
-def repo_view(request, repo):
+def repo_info(request, repo,branch=None):
+ therepo = get_object_or_404(Repository, slug=repo)
+
+ GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git '
+
+ shortlog = commands.getoutput(GITPREFIX + ' log | ' + GITCOMMAND + '-shortlog')
+
+ return render_to_response('git_browse/repository_info.html',
+ dict(object=therepo,
+ shortlog=shortlog,))
+
+def view_tree(request, repo, tree_hash=None,branch=None):
+ therepo = get_object_or_404(Repository, slug=repo)
+
+ GITPREFIX = 'cd ' + GITBROWSE_BASE + therepo.slug + '; ' + GITCOMMAND + ' --git-dir=' + GITBROWSE_BASE + therepo.slug + '/.git '
+
+ head_ref = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat HEAD')
+ head_ref = head_ref.split()[1]
+ head = commands.getoutput('cd ' + GITBROWSE_BASE + therepo.slug +'/.git; cat ' + head_ref)
+ tree_ls = commands.getoutput(GITPREFIX + ' ls-tree ' + head)
+ tree_objs = list()
+ blob_objs = list()
+ for line in tree_ls.splitlines():
+ l = line.split()
+ if len(l) < 4:
+ continue
+ if l[1] == 'tree':
+ tree_objs.append(tree_from_str(line))
+ if l[1] == 'blob':
+ blob_objs.append(blob_from_str(line))
+
+ return render_to_response('git_browse/tree.html',
+ dict(object=therepo,
+ blob_objs=blob_objs,
+ tree_objs=tree_objs,
+ all_objs=tree_objs+blob_objs,))
+
+def view_log(request, repo, tree_hash=None, branch=None):
+ therepo = get_object_or_404(Repository, slug=repo)
+
+ 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 ')
+ if (log_items[0] == ''):
+ log_items.pop(0)
+ if (log_items[0].startswith('commit ')):
+ log_items[0] = log_items[0][7:]
+ log_objs = list()
+ for li in log_items:
+ logobj = dict()
+ lines = li.splitlines()
+ if len(lines) < 3: continue
+ logobj['hash'] = lines[0]
+ logobj['author'] = lines[1][8:]
+ logobj['date'] = lines[2][8:]
+ logobj['comment'] = ''
+ for l in lines[4:]:
+ if l.startswith(' '):
+ logobj['comment'] += l[4:] + '\n'
+ log_objs.append(logobj)
+
+ return render_to_response('git_browse/full_log.html',
+ dict(object=therepo,
+ log_objs=log_objs,))
+
+def view_obj(request, repo, hash, branch=None):
therepo = get_object_or_404(Repository, slug=repo)
- out_content = 'Repo path: ' + therepo.path + '\n'
- out_content += 'Repo slug: ' + therepo.slug + '\n\n\n\n\n'
- out_content += commands.getoutput('cd '+GITBROWSE_BASE+therepo.slug+'; /usr/local/bin/git --git-dir='+GITBROWSE_BASE+therepo.slug+'/.git ls-files')
+ 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);
+ #if(obj_type == 'blob'):
+ # redirect_to('../blob/' + hash);
- return render_to_response('git_browse/repository_raw_output.html',
- dict(object=therepo,raw_content=out_content))
+ obj_contents = commands.getoutput(GITPREFIX + ' cat-file -p ' + hash)
+ obj_size = commands.getoutput(GITPREFIX + ' cat-file -s ' + hash)
+ return render_to_response('git_browse/obj.html',
+ dict(object=therepo,
+ hash=hash,
+ type=obj_type,
+ size=float(obj_size)/1024.0,
+ contents=obj_contents))