Added ability to diff a tree against an arbitrary revision

This commit is contained in:
Correl Roush 2010-12-17 14:50:26 -05:00
parent 0c29fa19fe
commit 52ea400423
4 changed files with 64 additions and 0 deletions

View file

@ -10,4 +10,7 @@ urlpatterns = patterns('',
# Commit view
(r'^(?P<repository>.*?)/commit/(?P<ref>.*?)/$',
'codereview.browser.views.commit'),
# Diff view
(r'^(?P<repository>.*?)/diff/$',
'codereview.browser.views.diff'),
)

View file

@ -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, {

View file

@ -0,0 +1,27 @@
{% extends "layouts/default.html" %}
{% load gravatar %}
{% load vcs %}
{% block navigation %}
{% include "browser/navigation.html" %}
{% endblock %}
{% block content %}
<h2>Diff View</h2>
<strong>{{ a.id }} => {{ b.id }}</strong>
{% comment %}
** ADD THIS WHEN REVIEWS SUPPORT MANUAL A/B DIFFS **
<form name="review" method="post" action="{% url codereview.review.views.new%}">
{{ form }}
{% csrf_token %}
<input type="submit" value="Create New Review" />
</form>
{% endcomment %}
<div class="diff-container">
<div class="diff-html">
{% for diff in diffs %}
{% include "components/diff.html" %}
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -5,5 +5,11 @@
{% endblock %}
{% block content %}
<form action="{% url codereview.browser.views.diff repository=repository %}">
<label>Diff tree from revision:</label>
<input type="text" name="a" />
<input type="hidden" name="b" value="{{ ref }}" />
<input type="submit" value="Diff" />
</form>
{% include "browser/commitlog.html" %}
{% endblock %}