Gitweb compatibility #44

Open
wants to merge 4 commits into
from
@@ -58,6 +58,11 @@ class Gitalist::Git::Repository with (Gitalist::Git::HasUtils, Gitalist::Git::Se
lazy_build => 1,
);
+ has url => ( isa => Str,
+ is => 'ro',
+ lazy_build => 1
+ );
+
has last_change => ( isa => Maybe[DateTime],
is => 'ro',
lazy_build => 1,
@@ -228,11 +233,20 @@ class Gitalist::Git::Repository with (Gitalist::Git::HasUtils, Gitalist::Git::Se
method _build_owner {
return 'system' if $^O =~ 'MSWin32';
+ my $owner = $self->run_cmd("config", "--get", "gitweb.owner");
+ chomp($owner);
+ return $owner if $owner;
my ($gecos, $name) = map { decode(langinfo(CODESET()), $_) } (getpwuid $self->path->stat->uid)[6,0];
$gecos =~ s/,+$//;
return length($gecos) ? $gecos : $name;
}
+ method _build_url {
+ my $url = $self->run_cmd("config", "--get", "gitweb.url");
+ chomp($url);
+ return $url;
+ }
+
method _build_last_change {
my $last_change;
my $output = $self->run_cmd(
@@ -88,4 +88,113 @@ sub blame : Chained('find') Does('FilenameArgs') Args() {}
sub history : Chained('find') Does('FilenameArgs') Args() {}
+# Redirect old gitweb-style urls
+sub commit_compat : Chained('base') PathPart('commit') Args(1) {
+ my ($self, $c, $sha1) = @_;
+ my $repo = $c->stash->{Repository};
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/commit", [$repo->name, $sha1]));
+}
+
+sub commitdiff_compat : Chained('base') PathPart('commitdiff') Args(1) {
+ my ($self, $c, $sha1) = @_;
+ my $repo = $c->stash->{Repository};
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/diff_fancy", [$repo->name, $sha1]));
+}
+
+sub tree_compat : Chained('base') PathPart('tree') Args(1) {
+ my ($self, $c, $sha1) = @_;
+ my $repo = $c->stash->{Repository};
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/tree", [$repo->name, $sha1]));
+}
+
+sub patch_compat : Chained('base') PathPart('patch') Args(1) {
+ my ($self, $c, $sha1) = @_;
+ my $repo = $c->stash->{Repository};
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/patch", [$repo->name, $sha1]));
+}
+
+sub commitdiff_plain_compat : Chained('base') PathPart('commitdiff_plain') Args(1) {
+ my ($self, $c, $sha1) = @_;
+ my $repo = $c->stash->{Repository};
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/patch", [$repo->name, $sha1]));
+}
+
+sub blob_compat : Chained('base') PathPart('blob') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ my $ref;
+ my $path = join("/", @{$c->req->args});
+ ($ref, $path) = split /:/, $path;
+ $path ||= "";
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/blob", [$repo->name, $ref]) . $path);
+}
+
+sub blob_plain_compat : Chained('base') PathPart('blob_plain') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ my $ref;
+ my $path = join("/", @{$c->req->args});
+ ($ref, $path) = split /:/, $path;
+ $path ||= "";
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/raw", [$repo->name, $ref]) . $path);
+}
+
+sub blame_compat : Chained('base') PathPart('blame') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ my $ref;
+ my $path = join("/", @{$c->req->args});
+ ($ref, $path) = split /:/, $path;
+ $path ||= "";
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/blame", [$repo->name, $ref]) . $path);
+}
+
+sub history_compat : Chained('base') PathPart('history') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ my $ref;
+ my $path = join("/", @{$c->req->args});
+ ($ref, $path) = split /:/, $path;
+ $path ||= "";
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/history", [$repo->name, $ref]) . $path);
+}
+
+sub ref_log_compat : Chained('base') PathPart('log/refs') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ shift @{$c->req->args};
+ my $ref = join('%2f', @{$c->req->args});
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/longlog", [$repo->name, $ref]));
+}
+
+sub ref_shortlog_compat : Chained('base') PathPart('shortlog/refs') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ shift @{$c->req->args};
+ my $ref = join('%2f', @{$c->req->args});
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/shortlog", [$repo->name, $ref]));
+}
+
+sub ref_tree_compat : Chained('base') PathPart('tree') Does('FilenameArgs') {
+ my ($self, $c) = @_;
+ my $repo = $c->stash->{Repository};
+ my $ref;
+ my $path = join('/', @{$c->req->args});
+ ($ref, $path) = split /:/, $path;
+ $path ||= "";
+ $c->res->status(302);
+ $c->res->redirect($c->uri_for_action("/ref/tree", [$repo->name, $ref]) . "$path");
+}
+
1;
@@ -49,4 +49,17 @@ sub heads : Chained('find') Args() {}
sub tags : Chained('find') Args() {}
+# Redirect old gitweb-style URL's
+sub object_compat : Chained('find') PathPart('object') Args(1) {
+ my ($self, $c, $sha1) = @_;
+
+ my $repo = $c->stash->{Repository};
+ my $obj = $c->stash->{Commit} = $repo->get_object($sha1);
+ my($act) = (ref($obj) || '') =~ /::(\w+)$/;
+
+ $c->res->redirect($c->uri_for_action("/ref/\L$act", [$repo->name, $obj->sha1]));
+ $c->res->status(301);
+
+}
+
1;
@@ -1,5 +1,6 @@
-<dl>
- <dt>description</dt><dd>[% Repository.description %]</dd>
- <dt>owner</dt><dd>[% Repository.owner %]</dd>
- <dt>last change</dt><dd>[% time_since(Repository.last_change) %]</dd>
-</dl>
+<h2>[% Repository.description %]</h2>
+<table class="summary">
+ <tr><th>Owner</th><td>[% Repository.owner %]</td></tr>
+ <tr><th>Last change</th><td>[% time_since(Repository.last_change) %]</td></tr>
+ <tr><th>Clone url</th><td>[% Repository.url %]</td></tr>
+</table>
@@ -1,8 +1,6 @@
+ [% subinclude('/fragment/repository/summary', c.req.captures) %]
- <!-- [% subinclude('/fragment/repository/summary', c.req.captures) %]
-
- <h2><a href='[% c.uri_for(c.controller.action_for('shortlog'), c.req.captures) %]'>shortlog</a></h2> -->
[% subinclude('/fragment/repository/shortlog', c.req.captures) %]
<h2><a href='[% c.uri_for(c.controller.action_for('heads'), c.req.captures) %]'>Branches</a></h2>
View
@@ -373,13 +373,6 @@ th a{
th a:hover{
color:#f0f0f0;
}
-.summary tr{
- background-color:#FAFAFA;
- border-bottom:1px solid #fff;
-}
-.summary td{
- vertical-align:middle !important;
-}
tr{
background-color:#fff;
}
@@ -426,6 +419,11 @@ table.listing thead {
padding-right: 10px;
}
+.summary th {
+ color: #666;
+ font-weight: bold;
+}
+
/*
puts the repo description on one line which gets truncated if the repo name is too long