diff --git a/lib/vcs.py b/browser/vcs.py similarity index 96% rename from lib/vcs.py rename to browser/vcs.py index a8c15c5..84ca734 100644 --- a/lib/vcs.py +++ b/browser/vcs.py @@ -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) diff --git a/browser/views.py b/browser/views.py index 05210b4..7c929f9 100755 --- a/browser/views.py +++ b/browser/views.py @@ -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, diff --git a/dashboard/models.py b/dashboard/models.py index 5af557f..55e1616 100755 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -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') diff --git a/lib/__init__.py b/lib/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/templates/browser/log.html b/templates/browser/log.html index 41d9baf..76d5908 100644 --- a/templates/browser/log.html +++ b/templates/browser/log.html @@ -6,8 +6,8 @@