From 52ea400423ee71fcfe3866f28ddae003d194e4d7 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 17 Dec 2010 14:50:26 -0500 Subject: [PATCH] Added ability to diff a tree against an arbitrary revision --- browser/urls.py | 3 +++ browser/views.py | 28 ++++++++++++++++++++++++++++ templates/browser/diff.html | 27 +++++++++++++++++++++++++++ templates/browser/log.html | 6 ++++++ 4 files changed, 64 insertions(+) create mode 100644 templates/browser/diff.html diff --git a/browser/urls.py b/browser/urls.py index 9607843..7c70d21 100644 --- a/browser/urls.py +++ b/browser/urls.py @@ -10,4 +10,7 @@ urlpatterns = patterns('', # Commit view (r'^(?P.*?)/commit/(?P.*?)/$', 'codereview.browser.views.commit'), + # Diff view + (r'^(?P.*?)/diff/$', + 'codereview.browser.views.diff'), ) diff --git a/browser/views.py b/browser/views.py index 1491552..6728133 100755 --- a/browser/views.py +++ b/browser/views.py @@ -74,6 +74,34 @@ def commit(request, repository, ref): }) return render_to_response('browser/view.html', data) @permission_required('dashboard.browse') +def diff(request, repository): + if not request.GET: + raise Http404 + if not request.GET['a']: + raise Http404 + try: + repository = Repository.objects.get(name=repository) + repo = vcs.create(repository.type, repository.path) + a = request.GET['a'] + commit_a = repo.commit(a) + b = None + if request.GET['b']: + b = request.GET['b'] + elif commit_a.parents: + b = commit_a.parents[0] + commit_b = repo.commit(b) + diffs = repo.diff(b, a) + except: + raise Http404 + data = RequestContext(request, { + 'repository': repository, + 'repo': repo, + 'a': commit_a, + 'b': commit_b, + 'diffs': diffs, + }) + return render_to_response('browser/diff.html', data) +@permission_required('dashboard.browse') def blob(request, repository, path): repo, ref = _repo(request, repository) data = RequestContext(request, { diff --git a/templates/browser/diff.html b/templates/browser/diff.html new file mode 100644 index 0000000..89c009f --- /dev/null +++ b/templates/browser/diff.html @@ -0,0 +1,27 @@ +{% extends "layouts/default.html" %} +{% load gravatar %} +{% load vcs %} + +{% block navigation %} +{% include "browser/navigation.html" %} +{% endblock %} + +{% block content %} +

Diff View

+{{ a.id }} => {{ b.id }} +{% comment %} +** ADD THIS WHEN REVIEWS SUPPORT MANUAL A/B DIFFS ** +
+ {{ form }} + {% csrf_token %} + +
+{% endcomment %} +
+
+ {% for diff in diffs %} + {% include "components/diff.html" %} + {% endfor %} +
+
+{% endblock %} diff --git a/templates/browser/log.html b/templates/browser/log.html index 4b11b26..92fb92e 100644 --- a/templates/browser/log.html +++ b/templates/browser/log.html @@ -5,5 +5,11 @@ {% endblock %} {% block content %} +
+ + + + +
{% include "browser/commitlog.html" %} {% endblock %}