diff options
author | Bryan Newbold <bnewbold@animus.robocracy.org> | 2007-02-24 21:38:38 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@animus.robocracy.org> | 2007-02-24 21:38:38 -0800 |
commit | 71520ba4e171195c983320b9c00e37c215fad39c (patch) | |
tree | 680c3bcfb72600cb6a167c92f5d39c7fd5a38833 /bn_django/git_browse/models.py | |
parent | cfeab0aadf7ba357a997c4a0203bcf4176ecc0d3 (diff) | |
download | bnewnet-71520ba4e171195c983320b9c00e37c215fad39c.tar.gz bnewnet-71520ba4e171195c983320b9c00e37c215fad39c.zip |
i'm confused?
Diffstat (limited to 'bn_django/git_browse/models.py')
-rw-r--r-- | bn_django/git_browse/models.py | 36 |
1 files changed, 20 insertions, 16 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])) |