mirror of
https://github.com/correl/codereview.git
synced 2024-12-18 03:00:08 +00:00
Got VCS out of the dashboard model and its lib dir, put it in the browser app
This commit is contained in:
parent
74d04a4ed0
commit
3cb107306a
5 changed files with 29 additions and 29 deletions
|
@ -15,6 +15,14 @@ class VCS(object):
|
||||||
def log(self, commit=None, path=None, max=50, offset=0):
|
def log(self, commit=None, path=None, max=50, offset=0):
|
||||||
return []
|
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):
|
class Blob(object):
|
||||||
def __init__(self, path, data):
|
def __init__(self, path, data):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -98,6 +106,7 @@ class Commit(object):
|
||||||
|
|
||||||
import git
|
import git
|
||||||
class Git(VCS):
|
class Git(VCS):
|
||||||
|
type = 'Git'
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super(Git, self).__init__(path);
|
super(Git, self).__init__(path);
|
||||||
self._repo = git.Repo(self._path)
|
self._repo = git.Repo(self._path)
|
|
@ -1,17 +1,18 @@
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from codereview.dashboard.models import Repository
|
from codereview.dashboard.models import Repository
|
||||||
|
from codereview.browser import vcs
|
||||||
|
|
||||||
def log(request,repository):
|
def log(request,repository):
|
||||||
try:
|
try:
|
||||||
repo = Repository.objects.get(name=repository)
|
repository = Repository.objects.get(name=repository)
|
||||||
except:
|
except:
|
||||||
raise Http404
|
raise Http404
|
||||||
vcs = repo.get_vcs()
|
repo = vcs.create(repository.type, repository.path)
|
||||||
ref = request.GET['c'] if 'c' in request.GET else vcs.ref()
|
ref = request.GET['c'] if 'c' in request.GET else repo.ref()
|
||||||
offset = int(request.GET['o']) if 'o' in request.GET else 0
|
offset = int(request.GET['o']) if 'o' in request.GET else 0
|
||||||
limit = 20
|
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
|
newer = offset - limit if offset > limit else 0
|
||||||
# Inspect the last commit. If it has no parents, we can't go any further
|
# 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',
|
return render_to_response('browser/log.html',
|
||||||
{
|
{
|
||||||
'repository': repository,
|
'repository': repository,
|
||||||
'vcs': vcs,
|
'repo': repo,
|
||||||
'log': log,
|
'log': log,
|
||||||
'ref': ref,
|
'ref': ref,
|
||||||
'offset': offset,
|
'offset': offset,
|
||||||
|
@ -31,17 +32,17 @@ def log(request,repository):
|
||||||
})
|
})
|
||||||
def view(request, repository, ref):
|
def view(request, repository, ref):
|
||||||
try:
|
try:
|
||||||
repo = Repository.objects.get(name=repository)
|
repository = Repository.objects.get(name=repository)
|
||||||
except:
|
except:
|
||||||
raise Http404
|
raise Http404
|
||||||
vcs = repo.get_vcs()
|
repo = vcs.create(repository.type, repository.path)
|
||||||
commit = vcs.commit(ref)
|
commit = repo.commit(ref)
|
||||||
diffs = vcs.diff(ref)
|
diffs = repo.diff(ref)
|
||||||
|
|
||||||
return render_to_response('browser/view.html',
|
return render_to_response('browser/view.html',
|
||||||
{
|
{
|
||||||
'repository': repository,
|
'repository': repository,
|
||||||
'vcs': vcs,
|
'repo': repo,
|
||||||
'ref': ref,
|
'ref': ref,
|
||||||
'commit': commit,
|
'commit': commit,
|
||||||
'diffs': diffs,
|
'diffs': diffs,
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from codereview.lib import vcs
|
|
||||||
|
|
||||||
class Repository(models.Model):
|
class Repository(models.Model):
|
||||||
Types = {
|
|
||||||
'Git': 0,
|
|
||||||
}
|
|
||||||
name = models.CharField(max_length=200, unique=True)
|
name = models.CharField(max_length=200, unique=True)
|
||||||
path = models.CharField(max_length=255)
|
path = models.CharField(max_length=255)
|
||||||
type = models.IntegerField(default=0)
|
type = models.IntegerField(default=0)
|
||||||
|
|
||||||
def get_vcs(self):
|
|
||||||
if self.type == 0:
|
|
||||||
return vcs.Git(self.path)
|
|
||||||
else:
|
|
||||||
raise Exception('Invalid VCS type')
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<h2>Commit Log</h2>
|
<h2>Commit Log</h2>
|
||||||
Branches:
|
Branches:
|
||||||
<ul>
|
<ul>
|
||||||
{% for branch, commit in vcs.branches.items %}
|
{% for branch, commit in repo.branches.items %}
|
||||||
<li><a href="{% url codereview.browser.views.log repository=repository %}?c={{branch}}">{{ branch }}</a> ({{commit.id}})</li>
|
<li><a href="{% url codereview.browser.views.log repository=repository.name %}?c={{branch}}">{{ branch }}</a> ({{commit.id}})</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<table class="vcs-log">
|
<table class="vcs-log">
|
||||||
|
@ -24,30 +24,30 @@ Branches:
|
||||||
{{ commit.author }}
|
{{ commit.author }}
|
||||||
</td>
|
</td>
|
||||||
<td class="message">
|
<td class="message">
|
||||||
{% for branch, c in vcs.branches.items %}
|
{% for branch, c in repo.branches.items %}
|
||||||
{% if commit.id == c.id %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for tag, c in vcs.tags.items %}
|
{% for tag, c in repo.tags.items %}
|
||||||
{% if commit.id == c.id %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% 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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
<div class="vcs-nav">
|
<div class="vcs-nav">
|
||||||
{% if older %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% if offset and older %}
|
{% if offset and older %}
|
||||||
·
|
·
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if offset %}
|
{% 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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue