aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django
diff options
context:
space:
mode:
authorbnewbold <bnewbold@manus.(none)>2007-02-21 00:17:17 -0800
committerbnewbold <bnewbold@manus.(none)>2007-02-21 00:17:17 -0800
commitc2c9c271553775e9481e8a8f70ddc25bc3273eac (patch)
treeccfc306d20a3a00da1d4646d0340f3a86c879576 /bn_django
parent90f58b36ecc39a1e2108bbdf65da3f184bc57247 (diff)
downloadbnewnet-c2c9c271553775e9481e8a8f70ddc25bc3273eac.tar.gz
bnewnet-c2c9c271553775e9481e8a8f70ddc25bc3273eac.zip
misc forgot to -a
Diffstat (limited to 'bn_django')
-rw-r--r--bn_django/git_browse/models.py103
-rw-r--r--bn_django/git_browse/templates/git_browse/full_log.html4
-rw-r--r--bn_django/git_browse/templates/git_browse/tree.html2
-rw-r--r--bn_django/git_browse/urls.py11
-rw-r--r--bn_django/git_browse/views.py29
5 files changed, 111 insertions, 38 deletions
diff --git a/bn_django/git_browse/models.py b/bn_django/git_browse/models.py
index edddf60..4cc73a3 100644
--- a/bn_django/git_browse/models.py
+++ b/bn_django/git_browse/models.py
@@ -23,17 +23,19 @@ 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.FilePathField("relative path to repository", path='/home/bnewbold/code/',recursive=True,match=".*\.git$",unique=True,blank=False)
+ 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\'")
+ git_version = models.CharField(_("git version"), maxlength=100, \
+ default="git version 1.4.4", blank=True, \
+ help_text="Output of \'git --version\'")
description = models.TextField("description of repo",blank=True)
class Admin:
ordering = ['slug']
-
def __str__(self):
return self.name
def get_absolute_url(self):
@@ -41,11 +43,16 @@ class Repository(models.Model):
def get_admin_url(self):
return "%s/code/repository/%s/" % (ADMIN_URL, self.slug)
+ def getGITPREFIX(self):
+ """returns the glued together combination of GITCOMMAND and
+ GITBROWSE_BASE needed to call git commands on this repository"""
+ 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 = 'cd ' + GITBROWSE_BASE + self.slug + '; ' + GITCOMMAND \
- + ' --git-dir=' + GITBROWSE_BASE + self.slug + '/.git '
+ GITPREFIX = self.getGITPREFIX()
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')
@@ -58,13 +65,12 @@ class Repository(models.Model):
f.close()
return (GITPREFIX, heads, tags)
-
def shortlog(self):
import commands
-
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')
+ logtxt = commands.getoutput(GITPREFIX \
+ + ' log --relative-date --max-count=6 | cat')
log_items = logtxt.split('\ncommit ')
if (log_items[0] == ''):
log_items.pop(0)
@@ -87,8 +93,6 @@ class Repository(models.Model):
logobj['shortdescription'] = logobj['description'][:128]
shortlog.append(logobj)
return shortlog
-
-
class Tree(models.Model):
repo = models.ForeignKey(Repository)
@@ -104,7 +108,7 @@ class Tree(models.Model):
def __str__(self):
return self.name
def get_absolute_url(self):
- return "/code/%s/%s" % (self.repo.slug, self.hash)
+ return "/code/%s/tree/%s/" % (self.repo.slug, self.hash)
def get_admin_url(self):
return "%s/code/tree/%s/" % (ADMIN_URL, self.id)
@@ -119,31 +123,84 @@ class Blob(models.Model):
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)
- size = models.IntField("filesize in byte", maxlength=128,blank=False)
+ size = models.IntegerField("filesize in byte", maxlength=128,blank=False)
contents = models.TextField("ASCII contents of the file")
type='blob'
class Admin:
- ordering = ['repo','path']
-
+ ordering = ['repo','path','name']
def __str__(self):
return self.name
def get_absolute_url(self):
- return "/code/%s/%s" % (self.repo.slug, self.hash)
+ return "/code/%s/blob/%s/" % (self.repo.slug, self.hash)
def get_admin_url(self):
- return "%s/code/tree/%s/" % (ADMIN_URL, self.id)
+ return "%s/code/blob/%s/" % (ADMIN_URL, self.id)
def update(self):
import commands
+ if (not self.id) or (not self.repo): return
+
+ GITPREFIX = self.repo.getGITPREFIX()
- if not self.id: return
self.id = self.id.strip()
- self.contents = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id)
- self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + hash)
-
-
+ self.contents = commands.getoutput(GITPREFIX + ' cat-file -p ' \
+ + self.id)
+ self.size = commands.getoutput(GITPREFIX + ' cat-file -s ' + self.id)
+ return
def blob_from_str(s):
s = s.split();
if len(s) != 4: return
return Blob(mode=s[0],id=s[2],name=s[3])
+
+class Commit(models.Model):
+ repo = models.ForeignKey(Repository)
+ id = models.CharField("hash", maxlength=40,blank=False,primary_key=True)
+ rawdiff = models.TextField("ASCII contents of full commit diff")
+ commit_date = models.DateField("Date of commit to repository")
+ author_date = models.DateField("Date commit was writen/created")
+ author = models.CharField("Name of commit author")
+ author_email = models.DateField("Email address of commit author")
+ committer = models.CharField("Name of committer")
+ committer_email = models.DateField("Email address of committer")
+ comment = models.TextField("Notes on the commit")
+ parenthash = models.CharField("parent's hash", maxlength=40)
+ #TODO: parent = models.ForeignKey()
+ treehash = models.CharField("tree object's hash", maxlength=40)
+ tree = models.ForeignKey(Tree)
+ type='commit'
+
+ class Admin:
+ ordering = ['repo','commit_date','author_date','author']
+ def __str__(self):
+ return self.id
+ def get_absolute_url(self):
+ return "/code/%s/commit/%s/" % (self.repo.slug, self.hash)
+ def get_admin_url(self):
+ return "%s/code/commit/%s/" % (ADMIN_URL, self.id)
+
+ def update(self):
+ import commands,time
+ if (not self.id) or (not self.repo): return
+
+ GITPREFIX = self.repo.getGITPREFIX()
+
+ self.id = self.id.strip()
+ raw = commands.getoutput(GITPREFIX + ' cat-file -p ' + self.id)
+ self.rawdiff = commands.getoutput(GITPREFIX + ' diff ' + self.id \
+ +' | cat')
+
+ raw = raw.splitlines()
+ if len(raw) < 3: return
+ self.treehash = raw[0].split()[-1].strip()
+ self.parenthash = raw[1][6:].strip()
+ self.author = raw[2].split()[1]
+ self.author_date = time.ctime(int(raw[2].split()[-2]))
+ self.committer = raw[3].split()[1]
+ self.committer_date = time.ctime(int(raw[3].split()[-2]))
+ if len(raw) > 4:
+ for l in raw[4:]:
+ self.comment += str(l) + '\n'
+ else:
+ self.comment = '(none)'
+ return
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 75ea2ab..d2a1311 100644
--- a/bn_django/git_browse/templates/git_browse/full_log.html
+++ b/bn_django/git_browse/templates/git_browse/full_log.html
@@ -5,7 +5,9 @@
<h3>Full Log</h3><br />
{% for item in log_objs %}
<hr>
- <b>Hash: </b>{{ item.hash }}
+ <b>Hash: </b>
+ <a href="/code/{{object.slug}}/commit/{{ item.hash }}/">
+ <span class="hash">{{ item.hash }}</span></a>
<br /><b>Author: </b>{{ item.author }}
<br /><b>Date: </b>{{ item.date }}
<br /><b>Comment: </b>
diff --git a/bn_django/git_browse/templates/git_browse/tree.html b/bn_django/git_browse/templates/git_browse/tree.html
index 79a8f39..b177af8 100644
--- a/bn_django/git_browse/templates/git_browse/tree.html
+++ b/bn_django/git_browse/templates/git_browse/tree.html
@@ -4,6 +4,8 @@
<h3>Tree sha1 hash:</h3>
<span class="hash">{{ hash }}</span>
+ <h3>Shortlog:</h3>
+ {% include "git_browse/shortlog_table" %}
<h3>Directory listing:</h3>
{% include "git_browse/tree_table" %}
{% endblock %}
diff --git a/bn_django/git_browse/urls.py b/bn_django/git_browse/urls.py
index caede9d..a0c31fe 100644
--- a/bn_django/git_browse/urls.py
+++ b/bn_django/git_browse/urls.py
@@ -33,13 +33,12 @@ urlpatterns += patterns('bn_django.git_browse.views',
(r'^(?P<repo>[\w\-\_]*)/branches/$', 'view_branches',),
(r'^(?P<repo>[\w\-\_]*)/log/$', 'view_log',),
(r'^(?P<repo>[\w\-\_]*)/obj/(?P<hash>[0-9a-z]{40})/$', 'view_obj',),
- (r'^(?P<repo>[\w\-\_]*)/commit/(?P<hash>[0-9a-z]{40})/$', 'view_obj',),
- (r'^(?P<repo>[\w\-\_]*)/commit/$', 'view_obj',),
- (r'^(?P<repo>[\w\-\_]*)/tag/(?P<hash>[0-9a-z]{40})/$', 'view_tag',),
+ (r'^(?P<repo>[\w\-\_]*)/commit/(?P<hash>[0-9a-z]{40})/$', 'view_commit',),
+ (r'^(?P<repo>[\w\-\_]*)/commit/$', 'view_commit',),
+ (r'^(?P<repo>[\w\-\_]*)/tag/(?P<name>[\w\-\_]+)/$', 'view_tag',),
+ (r'^(?P<repo>[\w\-\_]*)/head/(?P<name>[\w\-\_]+)/$', 'view_head',),
(r'^(?P<repo>[\w\-\_]*)/blob/(?P<hash>[0-9a-z]{40})/$', 'view_blob',),
- (r'^(?P<repo>[\w\-\_]*)/blob/(?P<hash>[0-9a-z]{40})/raw/$', 'view_blob',),
(r'^(?P<repo>[\w\-\_]*)/tree/$', 'view_tree',),
(r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/$', 'view_tree',),
- (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/gz/$', 'view_tree',),
- (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/tar/$', 'view_tree',),
+ (r'^(?P<repo>[\w\-\_]*)/tree/(?P<hash>[0-9a-z]{40})/zip/$', 'view_tree',),
)
diff --git a/bn_django/git_browse/views.py b/bn_django/git_browse/views.py
index e27d949..f28aa76 100644
--- a/bn_django/git_browse/views.py
+++ b/bn_django/git_browse/views.py
@@ -66,7 +66,7 @@ def view_tree(request, repo, hash=None,branch=None):
hash=hash,
all_objs=tree_objs+blob_objs,))
-def view_log(request, repo, tree_hash=None, branch=None):
+def view_log(request, repo, hash=None):
therepo = get_object_or_404(Repository, slug=repo)
(GITPREFIX, heads, tags) = therepo.scan()
@@ -96,17 +96,30 @@ def view_log(request, repo, tree_hash=None, branch=None):
return render_to_response('git_browse/full_log.html',
dict(object=therepo,
log_objs=log_objs,))
-def view_blob(request, repo, hash, branch=None):
+
+def view_blob(request, repo, hash):
therepo = get_object_or_404(Repository, slug=repo)
(GITPREFIX, heads, tags) = therepo.scan()
- blob = Blob(hash=hash,repo=therepo)
- blob.update()
+ b = Blob(id=hash,repo=therepo)
+ b.update()
- return render_to_response('git_browse/obj.html',
+ return render_to_response('git_browse/blob.html',
dict(object=therepo,
- hash=blob.id,
- size=blob.size,
- contents=blob.contents))
+ heads=heads,
+ tags=tags,
+ hash=b.id,
+ size=b.size,
+ contents=b.contents))
+
+def view_commit(request, repo, hash):
+ therepo = get_object_or_404(Repository, slug=repo)
+ (GITPREFIX, heads, tags) = therepo.scan()
+ c = Commit(id=hash,repo=therepo)
+ c.update()
+
+ return render_to_response('git_browse/commit.html',
+ dict(object=therepo, heads=heads, tags=tags,
+ commit=c))
def view_obj(request, repo, hash, branch=None):
therepo = get_object_or_404(Repository, slug=repo)