Got VCS out of the dashboard model and its lib dir, put it in the browser app

This commit is contained in:
Correl Roush 2010-11-19 16:16:35 -05:00
parent 74d04a4ed0
commit 3cb107306a
5 changed files with 29 additions and 29 deletions

View file

@ -15,6 +15,14 @@ class VCS(object):
def log(self, commit=None, path=None, max=50, offset=0):
return []
def create(type, path):
cls = {
0: Git,
}.get(type, None)
if not cls:
raise Exception('Unknown VCS Type')
return cls(path)
class Blob(object):
def __init__(self, path, data):
self.path = path
@ -98,6 +106,7 @@ class Commit(object):
import git
class Git(VCS):
type = 'Git'
def __init__(self, path):
super(Git, self).__init__(path);
self._repo = git.Repo(self._path)

View file

@ -1,17 +1,18 @@
from django.http import Http404
from django.shortcuts import render_to_response
from codereview.dashboard.models import Repository
from codereview.browser import vcs
def log(request,repository):
try:
repo = Repository.objects.get(name=repository)
repository = Repository.objects.get(name=repository)
except:
raise Http404
vcs = repo.get_vcs()
ref = request.GET['c'] if 'c' in request.GET else vcs.ref()
repo = vcs.create(repository.type, repository.path)
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
offset = int(request.GET['o']) if 'o' in request.GET else 0
limit = 20
log = vcs.log(ref, max=limit, offset=offset)
log = repo.log(ref, max=limit, offset=offset)
newer = offset - limit if offset > limit else 0
# Inspect the last commit. If it has no parents, we can't go any further
@ -22,7 +23,7 @@ def log(request,repository):
return render_to_response('browser/log.html',
{
'repository': repository,
'vcs': vcs,
'repo': repo,
'log': log,
'ref': ref,
'offset': offset,
@ -31,17 +32,17 @@ def log(request,repository):
})
def view(request, repository, ref):
try:
repo = Repository.objects.get(name=repository)
repository = Repository.objects.get(name=repository)
except:
raise Http404
vcs = repo.get_vcs()
commit = vcs.commit(ref)
diffs = vcs.diff(ref)
repo = vcs.create(repository.type, repository.path)
commit = repo.commit(ref)
diffs = repo.diff(ref)
return render_to_response('browser/view.html',
{
'repository': repository,
'vcs': vcs,
'repo': repo,
'ref': ref,
'commit': commit,
'diffs': diffs,

View file

@ -1,16 +1,6 @@
from django.db import models
from codereview.lib import vcs
class Repository(models.Model):
Types = {
'Git': 0,
}
name = models.CharField(max_length=200, unique=True)
path = models.CharField(max_length=255)
type = models.IntegerField(default=0)
def get_vcs(self):
if self.type == 0:
return vcs.Git(self.path)
else:
raise Exception('Invalid VCS type')

View file

View file

@ -6,8 +6,8 @@
<h2>Commit Log</h2>
Branches:
<ul>
{% for branch, commit in vcs.branches.items %}
<li><a href="{% url codereview.browser.views.log repository=repository %}?c={{branch}}">{{ branch }}</a> ({{commit.id}})</li>
{% for branch, commit in repo.branches.items %}
<li><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{branch}}">{{ branch }}</a> ({{commit.id}})</li>
{% endfor %}
</ul>
<table class="vcs-log">
@ -24,30 +24,30 @@ Branches:
{{ commit.author }}
</td>
<td class="message">
{% for branch, c in vcs.branches.items %}
{% for branch, c in repo.branches.items %}
{% if commit.id == c.id %}
<span class="marker branch"><a href="{% url codereview.browser.views.log repository=repository %}?c={{ branch }}">{{ branch }}</a></span>
<span class="marker branch"><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ branch }}">{{ branch }}</a></span>
{% endif %}
{% endfor %}
{% for tag, c in vcs.tags.items %}
{% for tag, c in repo.tags.items %}
{% if commit.id == c.id %}
<span class="marker tag"><a href="{% url codereview.browser.views.log repository=repository %}?c={{ tag }}">{{ tag }}</a></span>
<span class="marker tag"><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ tag }}">{{ tag }}</a></span>
{% endif %}
{% endfor %}
<a href="{% url codereview.browser.views.view repository=repository ref=commit.id %}">{{ commit.message|oneline }}</a>
<a href="{% url codereview.browser.views.view repository=repository.name ref=commit.id %}">{{ commit.message|oneline }}</a>
</td>
</tr>
{% endfor %}
</table>
<div class="vcs-nav">
{% if older %}
<a href="{% url codereview.browser.views.log repository=repository %}?c={{ ref }}&o={{ older }}">Older</a>
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}&o={{ older }}">Older</a>
{% endif %}
{% if offset and older %}
&middot;
{% endif %}
{% if offset %}
<a href="{% url codereview.browser.views.log repository=repository %}?c={{ ref }}&o={{ newer }}">Newer</a>
<a href="{% url codereview.browser.views.log repository=repository.name %}?c={{ ref }}&o={{ newer }}">Newer</a>
{% endif %}
</div>
{% endblock %}