diff --git a/browser/templatetags/vcs.py b/browser/templatetags/vcs.py index 6f738c3..fd12105 100644 --- a/browser/templatetags/vcs.py +++ b/browser/templatetags/vcs.py @@ -1,3 +1,4 @@ +import os from django.template import Library from django.template.defaultfilters import stringfilter @@ -8,3 +9,13 @@ register = Library() def oneline(value): line = value.split('\n')[0].strip() return line + +@register.filter +@stringfilter +def dirname(value): + return os.path.dirname(value) + +@register.filter +@stringfilter +def basename(value): + return os.path.basename(value) diff --git a/browser/urls.py b/browser/urls.py index 8e2468a..b37f950 100644 --- a/browser/urls.py +++ b/browser/urls.py @@ -2,5 +2,6 @@ from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^(?P.*?)/log/$', 'codereview.browser.views.log'), + (r'^(?P.*?)/log/(?P.*?/?)$', 'codereview.browser.views.log'), (r'^(?P.*?)/view/(?P.*?)/$', 'codereview.browser.views.view'), ) diff --git a/browser/vcs.py b/browser/vcs.py index 1d23509..782da36 100644 --- a/browser/vcs.py +++ b/browser/vcs.py @@ -144,7 +144,7 @@ class Git(VCS): def log(self, commit=None, path=None, max=50, offset=0): commit = commit if commit else self._ref result = [] - for c in self._repo.iter_commits(commit, path, max_count=max, + for c in self._repo.iter_commits(rev=commit, paths=path, max_count=max, skip=offset): result.append(self.commit(c)) return result @@ -176,6 +176,26 @@ class Git(VCS): diff.b_blob.data_stream.read()) result.append(d) return result + def browse(self, commit=None, path=''): + if not commit: + commit = self.ref() + files = [] + dirs = [] + # Locate the tree matching the requested path + tree = self._repo.commit(commit).tree + if path: + for i in tree.traverse(): + if type(i) == git.objects.Tree and i.path == path: + tree = i + if path != tree.path: + raise Exception('Path not found') + + for node in tree: + if type(node) == git.objects.Blob: + files.append(node.path) + elif type(node) == git.objects.Tree: + dirs.append(node.path) + return dirs, files if __name__ == '__main__': g = Git('/home/correlr/code/voiceaxis') diff --git a/browser/views.py b/browser/views.py index 7c929f9..a33510d 100755 --- a/browser/views.py +++ b/browser/views.py @@ -1,9 +1,10 @@ +import os 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): +def log(request,repository, path=None): try: repository = Repository.objects.get(name=repository) except: @@ -12,7 +13,10 @@ def log(request,repository): 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 = repo.log(ref, max=limit, offset=offset) + + path = path if path else '' + log = repo.log(ref, path=path, max=limit, offset=offset) + navigation = dict(zip(('dirs', 'files'), repo.browse(ref, os.path.dirname(path)))) newer = offset - limit if offset > limit else 0 # Inspect the last commit. If it has no parents, we can't go any further @@ -23,8 +27,10 @@ def log(request,repository): return render_to_response('browser/log.html', { 'repository': repository, + 'path': path, 'repo': repo, 'log': log, + 'navigation': navigation, 'ref': ref, 'offset': offset, 'newer': newer, diff --git a/dashboard/fixtures/localrepos.json b/dashboard/fixtures/localrepos.json index f8a43ef..f15b58e 100644 --- a/dashboard/fixtures/localrepos.json +++ b/dashboard/fixtures/localrepos.json @@ -16,5 +16,14 @@ "type": 0, "name": "MTG" } + }, + { + "pk": 3, + "model": "dashboard.repository", + "fields": { + "path": "/srv/git/codereview.git", + "type": 0, + "name": "CodeReview" + } } ] diff --git a/media/default.css b/media/default.css index 87c38e4..89d61bb 100644 --- a/media/default.css +++ b/media/default.css @@ -5,6 +5,20 @@ body, th, td { a { color: black; } +div.navigation { + width: 300px; + float: left; + overflow: hidden; +} +div.content { + margin-left: 300px; +} +ul.tree li.dir { + list-style-type: circle; +} +ul.tree li.file { + list-style-type: square; +} span.marker { display: block; float: left; diff --git a/templates/browser/log.html b/templates/browser/log.html index 76d5908..3f2ce32 100644 --- a/templates/browser/log.html +++ b/templates/browser/log.html @@ -1,15 +1,13 @@ {% extends "layouts/default.html" %} {% load gravatar %} - {% load vcs %} + +{% block navigation %} +{% include "browser/navigation.html" %} +{% endblock %} + {% block content %}

Commit Log

-Branches: -
    -{% for branch, commit in repo.branches.items %} -
  • {{ branch }} ({{commit.id}})
  • -{% endfor %} -
diff --git a/templates/browser/navigation.html b/templates/browser/navigation.html new file mode 100644 index 0000000..a1b689d --- /dev/null +++ b/templates/browser/navigation.html @@ -0,0 +1,35 @@ +{% load vcs %} +

{{ repository.name }}

+

Branches

+
    + {% for branch, commit in repo.branches.items %} +
  • + {% if ref == branch or ref == commit.id %} + {{ branch }} + {% else %} + {{ branch }} + {% endif %} +
  • + {% endfor %} +
+

Browse

+{% if path|dirname %} + {{ path|dirname }}/
+ Up one +{% endif %} +
    + {% for dir in navigation.dirs %} +
  • + {{ dir|basename }} +
  • + {% endfor %} + {% for file in navigation.files %} +
  • + {% if file == path %} + {{ file|basename }} + {% else %} + {{ file|basename }} + {% endif %} +
  • + {% endfor %} +
diff --git a/templates/browser/view.html b/templates/browser/view.html index 803a0d1..299bd50 100644 --- a/templates/browser/view.html +++ b/templates/browser/view.html @@ -2,6 +2,10 @@ {% load gravatar %} {% load vcs %} +{% block navigation %} +{% include "browser/navigation.html" %} +{% endblock %} + {% block content %}

{{ commit.message|oneline }}

diff --git a/templates/dashboard/index.html b/templates/dashboard/index.html index 9076031..055dee2 100644 --- a/templates/dashboard/index.html +++ b/templates/dashboard/index.html @@ -1,6 +1,6 @@ {% extends "layouts/default.html" %} -{% block content %} +{% block navigation %}

Repositories

    diff --git a/templates/layouts/default.html b/templates/layouts/default.html index 6f8b759..9210fa6 100644 --- a/templates/layouts/default.html +++ b/templates/layouts/default.html @@ -11,6 +11,8 @@

    CodeReview
    {% block content %}

Commit Date