{% extends 'allura:templates/repo/repo_master.html' %}
{% do g.register_forge_css('css/forge/diff.css') %}
{% block title %}
{{c.project.name}} / {{c.app.config.options.mount_label}} / Commit {{commit.shorthand_id()}}
{% endblock %}
{% block header -%}
Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(commit)}}
{%- endblock %}
{% block actions %}
<a href="{{commit.url()}}log/">
<b data-icon="{{g.icons.history.char}}" class="ico {{g.icons.history.css}}" title="History"> </b> History
</a>
{% endblock %}
{% block extra_js %}
{{ super() }}
<script type="text/javascript">
var MAX_REQUESTS = 5; // max simultaneous load requests
var WAIT_FOR = 500; // wait for 100ms when requests queue is full and try again
var diff_queue = []; // queue of diffs waiting for load
var called_count = 0; // count of running load requests
function ld(diff, callback) {
$(diff.selector).load(encodeURI(diff.url), callback);
}
function load_diff() {
if (called_count >= MAX_REQUESTS || diff_queue.length == 0) {
return;
}
called_count++;
var diff = diff_queue.shift();
ld(diff, function(response, status, xhr) {
if (status == 'error') {
if (xhr.status == 500) {
// retry once
ld(diff, function(response, status, xhr) {
if (status == 'error') {
$(this).text('Can\'t load diff');
}
called_count--;
});
} else {
$(this).text('Can\'t load diff');
called_count--;
}
} else {
called_count--;
}
if (diff_queue.length == 0) {
clearInterval(document.diff_queue_timer);
}
});
}
$(document).ready(function() {
document.diff_queue_timer = setInterval(load_diff, WAIT_FOR);
$('.switch-diff-format-link').click(function() {
var diformat = $(this).attr('data-diformat');
var href = $(this).attr('href');
var diffid = $(this).attr('data-diffid');
self = $(this);
if (diformat == 'sidebyside') {
href = href + '&diformat=regular';
$('#' + diffid).load(href, function() {
self.attr('data-diformat', 'regular');
self.text('Switch to side-by-side view');
});
} else {
href = href + '&diformat=sidebyside';
$('#' + diffid).load(href, function() {
self.attr('data-diformat', 'sidebyside');
self.text('Switch to unified view');
});
}
return false;
});
});
</script>
{% endblock %}
{% block content %}
{{c.revision_widget.display(value=commit, prev=prev, next=next)}}
{{c.page_list.display(page=page, limit=limit, count=count)}}
<table>
<tbody>
{% for type, file in artifacts %}
<tr>
<td>{{ type }}</td>
<td><a href="#diff-{{loop.index}}">
{% if type == 'copied' %}
{{ '%s -> %s' % (h.really_unicode(file.old), h.really_unicode(file.new)) }}
{% else %}
{{h.really_unicode(file)}}
{% endif %}
</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% for type, file in artifacts %}
<div class="inline-diff">
<h6>
{% if type in ('added', 'changed') %}
<a href="{{commit.url()}}tree/{{h.really_unicode(file)}}">{{h.really_unicode(file)}}</a>
<a class="commit-diff-link" href="{{commit.url()}}tree/{{h.really_unicode(file)}}?diff={{prev[0]._id if prev else ''}}">Diff</a>
<a class="commit-diff-link switch-diff-format-link" data-diformat="{{session.diformat}}" data-diffid="diff-{{loop.index}}" href="{{commit.url()}}tree/{{h.really_unicode(file)}}?barediff={{prev[0]._id if prev else ''}}">Switch to {{'unified' if session.diformat == 'sidebyside' else 'side-by-side'}} view</a>
{% elif type == 'removed' %}
<a href="{{prev[0].url()}}tree/{{h.really_unicode(file)}}">{{h.really_unicode(file)}}</a>
{% elif type == 'copied' %}
<a href="{{prev[0].url()}}tree/{{h.really_unicode(file.old)}}">{{h.really_unicode(file.old)}}</a>
to
<a href="{{commit.url()}}tree/{{h.really_unicode(file.new)}}">{{h.really_unicode(file.new)}}</a>
{% endif %}
</h6>
<div id="diff-{{loop.index}}" class="inline-diff-body">
{% if type == 'removed' %}
<span class="empty-diff">File was removed.</span>
{% elif type == 'copied' %}
{% if file.ratio == 1 %}
<span class="empty-diff">File was renamed.</span>
{% else %}
{{g.highlight(file.diff, lexer='diff')}}
{% endif %}
{% else %}
<img src="{{g.forge_static('images/spinner.gif')}}" class="loading_icon" alt="Loading..."/>
<script type="text/javascript">
$(document).ready(function() {
diff_queue.push({
selector: '#diff-{{loop.index}}',
url: '{{commit.url()}}tree/{{h.really_unicode(file)}}?barediff={{prev[0]._id if prev else ''}}'
});
});
</script>
{% endif %}
</div>
</div>
{% endfor %}
{{c.page_list.display(page=page, limit=limit, count=count)}}
{% endblock %}