Skip to content

Commit

Permalink
Fix bug where diff didn't distinguish between sha1s and paths.
Browse files Browse the repository at this point in the history
* The current approach to /diff + args is rather fragile, better suggestions welcome.
* Also fixed a link and made a few template tweaks.
* Added a redirect for /repo/tree to /repo/HEAD/tree.
  • Loading branch information
broquaint committed Mar 28, 2010
1 parent 9143f8d commit cbcd839
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 71 deletions.
17 changes: 6 additions & 11 deletions lib/Gitalist/Controller/Repository.pm
Expand Up @@ -39,21 +39,16 @@ sub search : Chained('find') Args(0) {
);
}

=head2 reflog
=head2 tree
Expose the local reflog. This may go away.
Provide a simple redirect to C</ref/tree>.
=cut

sub reflog : Chained('find') Args(0) {
my ( $self, $c ) = @_;
my @log = $c->stash->{Repository}->reflog(
'--since=yesterday'
);

$c->stash(
log => \@log,
);
sub tree : Chained('find') Args(0) {
my($self, $c) = @_;
$c->res->redirect($c->uri_for_action('/ref/tree', [$c->stash->{Repository}->name, 'HEAD']));
$c->res->status(301);
}

=head2 atom
Expand Down
29 changes: 19 additions & 10 deletions lib/Gitalist/URIStructure/Ref.pm
Expand Up @@ -3,6 +3,8 @@ use MooseX::MethodAttributes::Role;
use Moose::Autobox;
use namespace::autoclean;

use Gitalist::Git::Types qw/SHA1/;

requires 'base';

with qw/
Expand All @@ -24,22 +26,29 @@ sub find : Chained('base') PathPart('') CaptureArgs(1) {

sub diff : Chained('find') CaptureArgs(0) {}

sub diff_fancy : Chained('diff') PathPart('') Args() {
my($self, $c, $comparison, @rest) = @_;
sub _set_diff_args {
my($self, $c, @rest) = @_;

# FIXME - This ain't pretty
$c->stash(parent => $comparison)
if $comparison;
$c->stash(filename => $rest[0])
$c->stash(parent => shift @rest)
if @rest == 2
# Check that the single arg is unlikely to be a path.
or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object_or_head($rest[0]);
$c->stash(filename => $rest[-1])
if @rest;
}

sub diff_fancy : Chained('diff') PathPart('') Args() {
my($self, $c, @rest) = @_;

$self->_set_diff_args($c, @rest);
}

sub diff_plain : Chained('diff') PathPart('plain') Args() {
my($self, $c, $comparison, @rest) = @_;
# FIXME - This ain't pretty
$c->stash(parent => $comparison)
if $comparison;
$c->stash(filename => $rest[0])
if @rest;

$self->_set_diff_args($c, @rest);

$c->stash(no_wrapper => 1);
$c->response->content_type('text/plain; charset=utf-8');
}
Expand Down
8 changes: 4 additions & 4 deletions root/_diff_tree.tt2
@@ -1,4 +1,4 @@
<h2>[% diff_tree.size %] file[% "s" IF diff_tree.size > 1 %] in this commit <span>([%- Commit.sha1 || HEAD -%])</span></h2>
<h2>[% diff_tree.size %] file[% "s" IF diff_tree.size > 1 %] in this diff <span>([%- Commit.sha1 || HEAD -%])</span></h2>

<table class='diff-tree listing'>
<thead>
Expand All @@ -12,7 +12,7 @@
[% FOREACH line IN diff_tree -%]
<tr>
<td class='file-name'>
[% line.file %]
<a href="#diff[% loop.count %]">[% line.file %]</a>
</td>
<td class='status'>
[%
Expand All @@ -27,8 +27,8 @@
%]
</td>
<td class='action-list'>
[% IF !line.is_new %]<a href="[% c.uri_for_action("/ref/diff_fancy", [Repository.name, Commit.sha1], line.file.to_path) %]#diff[% loop.count %]" title="Difference" class="button diff">diff</a>[% END %]
[% IF !line.is_new %]<a href="[% c.uri_for("/ref/shortlog", [Repository.name, Commit.sha1], line.file.to_path) %]" title="History (Short Log)" class="button history">history</a>[% END %]
[% IF !line.is_new %]<a href="[% c.uri_for_action("/ref/diff_fancy", [Repository.name, Commit.sha1], line.file.to_path) %]" title="Difference" class="button diff">diff</a>[% END %]
[% IF !line.is_new %]<a href="[% c.uri_for_action("/ref/history", [Repository.name, Commit.sha1], line.file.to_path) %]" title="History (Short Log)" class="button history">history</a>[% END %]
<a href="[% c.uri_for_action("/ref/blob", [Repository.name, Commit.sha1], line.file.to_path) %]" title="Blob" class="button blob">blob</a>
</td>
</tr>
Expand Down
39 changes: 0 additions & 39 deletions root/_tree.tt2

This file was deleted.

2 changes: 1 addition & 1 deletion root/inc/chroma_hash.tt2
Expand Up @@ -7,7 +7,7 @@
END;
-%]

<div class='button sha1_holder[% "_invert" IF loop.count % 2 %]' style="background-color:#[% sha1part %]"></div>
<div class='button sha1_holder[% "_invert" IF loop.count && loop.count % 2 %]' style="background-color:#[% sha1part %]"></div>
[% IF !hide_sha1_output %]
<div class="sha1_label">[% sha1part %]</div>
[% END %]
6 changes: 0 additions & 6 deletions root/ref/tree.tt2
@@ -1,6 +1,3 @@



[%
IF path;
INCLUDE 'nav/path.tt2' filename = path;
Expand All @@ -9,6 +6,3 @@
subinclude('/fragment/ref/tree', c.req.captures, c.req.args.to_path);
%]

<div class='commit-message'>
[% short_cmt(commit.comment) | html %] ...
</div>

0 comments on commit cbcd839

Please sign in to comment.