From c2c9c271553775e9481e8a8f70ddc25bc3273eac Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 21 Feb 2007 00:17:17 -0800 Subject: misc forgot to -a --- bn_django/git_browse/models.py | 103 ++++++++++++++++----- .../git_browse/templates/git_browse/full_log.html | 4 +- .../git_browse/templates/git_browse/tree.html | 2 + bn_django/git_browse/urls.py | 11 +-- bn_django/git_browse/views.py | 29 ++++-- 5 files changed, 111 insertions(+), 38 deletions(-) (limited to 'bn_django') 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 @@

Full Log


{% for item in log_objs %}
- Hash: {{ item.hash }} + Hash: + + {{ item.hash }}
Author: {{ item.author }}
Date: {{ item.date }}
Comment: 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 @@

Tree sha1 hash:

{{ hash }} +

Shortlog:

+ {% include "git_browse/shortlog_table" %}

Directory listing:

{% 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[\w\-\_]*)/branches/$', 'view_branches',), (r'^(?P[\w\-\_]*)/log/$', 'view_log',), (r'^(?P[\w\-\_]*)/obj/(?P[0-9a-z]{40})/$', 'view_obj',), - (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/$', 'view_obj',), - (r'^(?P[\w\-\_]*)/commit/$', 'view_obj',), - (r'^(?P[\w\-\_]*)/tag/(?P[0-9a-z]{40})/$', 'view_tag',), + (r'^(?P[\w\-\_]*)/commit/(?P[0-9a-z]{40})/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/commit/$', 'view_commit',), + (r'^(?P[\w\-\_]*)/tag/(?P[\w\-\_]+)/$', 'view_tag',), + (r'^(?P[\w\-\_]*)/head/(?P[\w\-\_]+)/$', 'view_head',), (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/$', 'view_blob',), - (r'^(?P[\w\-\_]*)/blob/(?P[0-9a-z]{40})/raw/$', 'view_blob',), (r'^(?P[\w\-\_]*)/tree/$', 'view_tree',), (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/$', 'view_tree',), - (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/gz/$', 'view_tree',), - (r'^(?P[\w\-\_]*)/tree/(?P[0-9a-z]{40})/tar/$', 'view_tree',), + (r'^(?P[\w\-\_]*)/tree/(?P[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) -- cgit v1.2.3