diff options
Diffstat (limited to 'bn_django/git_browse')
-rw-r--r-- | bn_django/git_browse/models.py | 36 | ||||
-rw-r--r-- | bn_django/git_browse/settings.py | 7 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/base.html | 2 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/blob.html | 2 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/commit.html | 2 | ||||
-rw-r--r-- | bn_django/git_browse/templates/git_browse/full_log.html | 2 | ||||
-rw-r--r-- | bn_django/git_browse/views.py | 19 |
7 files changed, 47 insertions, 23 deletions
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py index c914cac..315365a 100644 --- a/bn_django/git_browse/models.py +++ b/bn_django/git_browse/models.py @@ -2,6 +2,13 @@ from django.db import models from django.conf import settings 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' @@ -16,14 +23,11 @@ if ADMIN_URL[-1] == '/': # Create your models here. class Repository(models.Model): -# path = models.FilePathField("relative path to repository", \ -# path=GITBROWSE_BASE,recursive=True,match="\.git$",unique=True, \ -# blank=False) - path = models.CharField("path to git dir", maxlength=386, unique=True,\ - blank=False, default="/srv/git/") - name = models.CharField(_("name"), maxlength=80, unique=True) - slug = models.SlugField("short description of repo", unique=True,\ + path = models.FilePathField("relative path to repository", \ + path=GITBROWSE_BASE,recursive=True,match="^.*\.git$",unique=True, \ blank=False) + name = models.CharField(_("name"), maxlength=80) + slug = models.SlugField(prepopulate_from=("path",),unique=True) git_version = models.CharField(_("git version"), maxlength=100, \ default="git version 1.4.4", blank=True, \ help_text="Output of \'git --version\'") @@ -42,27 +46,29 @@ class Repository(models.Model): def getGITPREFIX(self): """returns the glued together combination of GITCOMMAND and GITBROWSE_BASE needed to call git commands on this repository""" - return 'cd ' + str(self.path) + '; ' + str(GITCOMMAND) + ' --git-dir='\ - + str(self.path) + return 'cd ' + str(GITBROWSE_BASE) + str(self.slug) + '; ' \ + + str(GITCOMMAND) + ' --git-dir=' + str(GITBROWSE_BASE) \ + + str(self.slug) + '/.git ' def scan(self): import os GITPREFIX = self.getGITPREFIX() heads = dict() - for h in os.listdir(self.path + '/refs/heads/'): - f = open(self.path + '/refs/heads/' + h,'r') + 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.strip()] = f.readline().strip() f.close() tags = dict() - for t in os.listdir(self.path + '/refs/tags/'): - f = open(self.path + '/refs/tags/' + t,'r') + 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.strip()] = f.readline().strip() f.close() return (GITPREFIX, heads, tags) def shortlog(self): import commands - GITPREFIX = self.getGITPREFIX() + 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 ') @@ -189,8 +195,6 @@ class Commit(models.Model): raw = raw.splitlines() if len(raw) < 3: return self.treehash = raw[0].split()[-1].strip() - if not raw[1].startswith('parent'): - raw.insert(1, 'parent ') self.parenthash = raw[1][6:].strip() self.author = raw[2].split()[1] self.author_date = time.ctime(int(raw[2].split()[-2])) diff --git a/bn_django/git_browse/settings.py b/bn_django/git_browse/settings.py index 87b957d..53799ab 100644 --- a/bn_django/git_browse/settings.py +++ b/bn_django/git_browse/settings.py @@ -1,2 +1,7 @@ + +# full path to directory holding all the git repositories (or sys links to +# the repositories) +GITBROWSE_BASE = '/srv/git/' + # fill path to the git command -GITCOMMAND = '/usr/local/bin/git' +GITCOMMAND = '/usr/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 89a0139..c86e03b 100644 --- a/bn_django/git_browse/templates/git_browse/base.html +++ b/bn_django/git_browse/templates/git_browse/base.html @@ -4,7 +4,7 @@ {{ block.super }} <link rel="STYLESHEET" type="text/css" href="style/git_browse.css" /> <link rel="STYLESHEET" type="text/css" href="/style/git_browse.css" /> -<!--<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_browse.css" />--> +<link rel="STYLESHEET" type="text/css" href="http://static.bryannewbold.com/style/git_browse.css" /> {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/blob.html b/bn_django/git_browse/templates/git_browse/blob.html index 3730807..1fb1437 100644 --- a/bn_django/git_browse/templates/git_browse/blob.html +++ b/bn_django/git_browse/templates/git_browse/blob.html @@ -7,7 +7,7 @@ {{ size|filesizeformat }}<br /> <h3><a href="zip">Download zip</a></h3> <h3>Raw contents</h3> - <pre class="large">{{ contents|escape|wordwrap:80 }}</pre> + <pre class="large">{{ contents }}</pre> {% else %} <h3>No such object: {{ hash }}</h3> {% endif %} {% endblock %} diff --git a/bn_django/git_browse/templates/git_browse/commit.html b/bn_django/git_browse/templates/git_browse/commit.html index b4ee4a6..3a1aefd 100644 --- a/bn_django/git_browse/templates/git_browse/commit.html +++ b/bn_django/git_browse/templates/git_browse/commit.html @@ -22,7 +22,7 @@ <h3>Committer Date</h3> {{ commit.committer_date }}<br /> {% if commit.rawdiff %} - <pre class="large">{{ commit.rawdiff|escape|wordwrap:80 }}</pre> + <pre class="large">{{ commit.rawdiff }}</pre> {% else %}No diff{% endif %} {% else %} <h3>No such object: {{ hash }}</h3> diff --git a/bn_django/git_browse/templates/git_browse/full_log.html b/bn_django/git_browse/templates/git_browse/full_log.html index 913a3c4..d2a1311 100644 --- a/bn_django/git_browse/templates/git_browse/full_log.html +++ b/bn_django/git_browse/templates/git_browse/full_log.html @@ -11,7 +11,7 @@ <br /><b>Author: </b>{{ item.author }} <br /><b>Date: </b>{{ item.date }} <br /><b>Comment: </b> - <pre class="large">{{ item.comment|escape|wordwrap:80 }}</pre> + <pre class="large">{{ item.comment|wordwrap:80 }}</pre> {% endfor %} {% endif %} {% endblock %} diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py index ed653df..f28aa76 100644 --- a/bn_django/git_browse/views.py +++ b/bn_django/git_browse/views.py @@ -9,6 +9,11 @@ import os, commands from models import * try: + GITBROWSE_BASE = settings.GITBROWSE_BASE+'/' +except AttributeError: + GITBROWSE_BASE='/home/' + +try: GITCOMMAND = settings.GITCOMMAND except AttributeError: GITCOMMAND='git' @@ -36,9 +41,11 @@ def view_tree(request, repo, hash=None,branch=None): (GITPREFIX, heads, tags) = therepo.scan() if(hash == None): - head_ref = commands.getoutput('cd ' + therepo.path + '; cat HEAD') + head_ref = commands.getoutput('cd ' + GITBROWSE_BASE \ + + therepo.slug +'/.git; cat HEAD') head_ref = head_ref.split()[1] - hash = commands.getoutput('cd ' + therepo.path + '; 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() @@ -63,6 +70,9 @@ def view_log(request, repo, hash=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 ' + logtxt = commands.getoutput(GITPREFIX + ' log | cat') log_items = logtxt.split('\ncommit ') if (log_items[0] == ''): @@ -116,6 +126,11 @@ def view_obj(request, repo, hash, branch=None): (GITPREFIX, heads, tags) = therepo.scan() 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); + obj_contents = commands.getoutput(GITPREFIX + ' cat-file -p ' + hash) obj_size = commands.getoutput(GITPREFIX + ' cat-file -s ' + hash) |