summaryrefslogtreecommitdiffstats
path: root/bn_django/git_browse
diff options
context:
space:
mode:
authorbnewbold <bnewbold@manus.(none)>2007-02-18 13:53:30 -0800
committerbnewbold <bnewbold@manus.(none)>2007-02-18 13:53:30 -0800
commit0c7c01d4ff1635cb7f04bed3d099b30b967f44bd (patch)
treef5a953687406c932573599b3de95d007148139cd /bn_django/git_browse
parent9077a48cf9aeb06ddd751cfa7497fd636ed489a6 (diff)
downloadbnewnet-0c7c01d4ff1635cb7f04bed3d099b30b967f44bd.tar.gz
bnewnet-0c7c01d4ff1635cb7f04bed3d099b30b967f44bd.zip
renamed a few templates, further work on git_browsev0.0.0
Diffstat (limited to 'bn_django/git_browse')
-rw-r--r--bn_django/git_browse/models.py46
-rw-r--r--bn_django/git_browse/settings.py7
-rw-r--r--bn_django/git_browse/templates/git_browse/base.html31
-rw-r--r--bn_django/git_browse/templates/git_browse/full_log.html14
-rw-r--r--bn_django/git_browse/templates/git_browse/obj.html12
-rw-r--r--bn_django/git_browse/templates/git_browse/repository_info.html8
-rw-r--r--bn_django/git_browse/templates/git_browse/repository_raw_output.html23
-rw-r--r--bn_django/git_browse/templates/git_browse/tree.html10
-rw-r--r--bn_django/git_browse/urls.py9
-rw-r--r--bn_django/git_browse/views.py94
10 files changed, 222 insertions, 32 deletions
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py
index 93a22b3..765fe02 100644
--- a/bn_django/git_browse/models.py
+++ b/bn_django/git_browse/models.py
@@ -33,3 +33,49 @@ class Repository(models.Model):
return "/code/%s/" % self.slug
def get_admin_url(self):
return "%s/code/repository/%s/" % (ADMIN_URL, self.slug)
+
+class Tree(models.Model):
+ repo = models.ForeignKey(Repository)
+ mode = models.CharField("file mode/permissions", blank=False,maxlength=4)
+ 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)
+ type = 'tree'
+
+ class Admin:
+ ordering = ['repo','path']
+
+ def __str__(self):
+ return self.name
+ def get_absolute_url(self):
+ return "/code/%s/%s" % (self.repo.slug, self.hash)
+ def get_admin_url(self):
+ return "%s/code/tree/%s/" % (ADMIN_URL, self.id)
+
+def tree_from_str(s):
+ s = s.split();
+ if len(s) != 4: return
+ return Tree(mode=s[0],id=s[2],name=s[3])
+
+class Blob(models.Model):
+ repo = models.ForeignKey(Repository)
+ mode = models.CharField("file mode/permissions", blank=False,maxlength=4)
+ 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)
+ type='blob'
+
+ class Admin:
+ ordering = ['repo','path']
+
+ def __str__(self):
+ return self.name
+ def get_absolute_url(self):
+ return "/code/%s/%s" % (self.repo.slug, self.hash)
+ def get_admin_url(self):
+ return "%s/code/tree/%s/" % (ADMIN_URL, self.id)
+
+def blob_from_str(s):
+ s = s.split();
+ if len(s) != 4: return
+ return Blob(mode=s[0],id=s[2],name=s[3])
diff --git a/bn_django/git_browse/settings.py b/bn_django/git_browse/settings.py
new file mode 100644
index 0000000..a18018b
--- /dev/null
+++ b/bn_django/git_browse/settings.py
@@ -0,0 +1,7 @@
+
+# full path to directory holding all the git repositories (or sys links to
+# the repositories)
+GITBROWSE_BASE = '/home/bnewbold/bn-project/'
+
+# fill path to the git command
+GITCOMMAND = '/usr/local/bin/git'
diff --git a/bn_django/git_browse/templates/git_browse/base.html b/bn_django/git_browse/templates/git_browse/base.html
index 94d9808..0edb5a7 100644
--- a/bn_django/git_browse/templates/git_browse/base.html
+++ b/bn_django/git_browse/templates/git_browse/base.html
@@ -1 +1,32 @@
{% extends "base.html" %}
+
+{% block path %}
+ <a href="/code/">code</a> &raquo;
+{% if object %}
+ <a href="/code/{{ object.slug }}/">{{ object.name }}</a>
+{% endif %}
+{% endblock %}
+
+{% block title %}
+{% if object %}
+{{ object.name }}
+{% endif %}
+{% endblock %}
+
+{% block content %}
+{% if object %}
+ {% block gitbrowse %}
+ {% endblock %}
+ <br />
+ <span class="righty">
+ <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 %}
+
+{% endblock %}
diff --git a/bn_django/git_browse/templates/git_browse/full_log.html b/bn_django/git_browse/templates/git_browse/full_log.html
new file mode 100644
index 0000000..a467ae8
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/full_log.html
@@ -0,0 +1,14 @@
+{% extends "git_browse/base.html" %}
+
+{% block gitbrowse %}
+{% if log_objs %}
+ <h3>Full Log</h3><br />
+ {% for item in log_objs %}
+ <hr>
+ <b>Hash: </b>{{ item.hash }}
+ <br /><b>Author: </b>{{ item.author }}
+ <br /><b>Date: </b>{{ item.date }}
+ <br /><b>Comment: </b><pre>{{ item.comment }}</pre>
+ {% endfor %}
+{% endif %}
+{% endblock %}
diff --git a/bn_django/git_browse/templates/git_browse/obj.html b/bn_django/git_browse/templates/git_browse/obj.html
new file mode 100644
index 0000000..be0b556
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/obj.html
@@ -0,0 +1,12 @@
+{% extends "git_browse/base.html" %}
+
+{% block gitbrowse %}
+ {% if contents %}
+ <h3>Object sha1 hash: {{ hash }}<br />
+ Size: {{ size }} kB<br />
+ Type: "{{ type }}"</h3>
+ <pre>{{ contents }}</pre>
+ {% else %}
+ <h3>No such object: {{ hash }}</h3>
+ {% endif %}
+{% endblock %}
diff --git a/bn_django/git_browse/templates/git_browse/repository_info.html b/bn_django/git_browse/templates/git_browse/repository_info.html
new file mode 100644
index 0000000..bec150c
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/repository_info.html
@@ -0,0 +1,8 @@
+{% extends "git_browse/base.html" %}
+
+{% block gitbrowse %}
+{% if shortlog %}
+<h3>Shortlog</h3>
+<pre>{{ shortlog }}</pre>
+{% endif %}
+{% endblock %}
diff --git a/bn_django/git_browse/templates/git_browse/repository_raw_output.html b/bn_django/git_browse/templates/git_browse/repository_raw_output.html
index 3ce6894..ee1c8e0 100644
--- a/bn_django/git_browse/templates/git_browse/repository_raw_output.html
+++ b/bn_django/git_browse/templates/git_browse/repository_raw_output.html
@@ -1,29 +1,8 @@
{% extends "git_browse/base.html" %}
-{% block path %}
- <a href="../">code</a> &raquo;
-{% if object %}
- <a href="/code/{{ object.slug }}/">{{ object.name }}</a>
-{% endif %}
-{% endblock %}
-
-{% block title %}
-{% if object %}
-Repository: {{ object.name }}
-{% endif %}
-{% endblock %}
-
{% block content %}
-{% if object %}
{% if raw_content %}
<br />
- <pre>
-
-{{ raw_content }}
- </pre>
+ <pre> {{ raw_content }} </pre>
{% endif %}
-{% else %}
-<p>No such repository!</p>
-{% endif %}
-
{% endblock %}
diff --git a/bn_django/git_browse/templates/git_browse/tree.html b/bn_django/git_browse/templates/git_browse/tree.html
new file mode 100644
index 0000000..22162da
--- /dev/null
+++ b/bn_django/git_browse/templates/git_browse/tree.html
@@ -0,0 +1,10 @@
+{% extends "git_browse/base.html" %}
+
+{% block gitbrowse %}
+ {% if all_objs %}
+ <h3>Directory listing:</h3>
+ {% for obj in all_objs %}
+[{{obj.type}}] <a href='../obj/{{ obj.id }}/'>{{obj.name}}</a> <br />
+ {% endfor %}
+ {% endif %}
+{% endblock %}
diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py
index 3d26e4f..91e9baa 100644
--- a/bn_django/git_browse/urls.py
+++ b/bn_django/git_browse/urls.py
@@ -31,7 +31,10 @@ urlpatterns = patterns('django.views.generic.list_detail',
)
urlpatterns += patterns('bn_django.git_browse.views',
- (r'^(?P<repo>[\w\-\_]*)/$', 'repo_view',),
- (r'^(?P<repo>[\w\-\_]*)/tree/(?P<path>.?)$', 'view_tree',),
- (r'^(?P<repo>[\w\-\_]*)/obj/(?P<obj_hash>.?)$', 'view_obj',),
+ (r'^(?P<repo>[\w\-\_]*)/$', 'repo_info',),
+ (r'^(?P<repo>[\w\-\_]*)/tree/$', 'view_tree',),
+ (r'^(?P<repo>[\w\-\_]*)/branches/$', 'view_branches',),
+ (r'^(?P<repo>[\w\-\_]*)/history/$', 'view_history',),
+ (r'^(?P<repo>[\w\-\_]*)/log/$', 'view_log',),
+ (r'^(?P<repo>[\w\-\_]*)/obj/(?P<hash>[0-9a-z]*)/$', 'view_obj',),
)
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))