Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Gitweb compatibility #44

Open
wants to merge 4 commits into from

1 participant

@seveas

These patches improve backwards compatibility with gitweb.

  • Patch 1 adds the repository summary back to the summary page
  • Patch 2 improves URL compatibility

More details can be found in the commitmessages.

seveas added some commits
@seveas seveas Gitweb compat: repository summary
- Show the summary data again, but nicely formatted
- Repository owner and clone url can be set in the gitweb section of .git/config
- Add the url to the model and template
5896108
@seveas seveas Gitweb compat: URL structure
One can use gitweb with the following apache config to have
parameter-less urls:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.git/(HEAD|refs|info|objects)
RewriteRule ^.*\.git.*$ /gitweb.cgi%{REQUEST_URI} [PT]

We use this on perl5.git.perl.org, some other sites do this too. We'd
like these URLs to be supported by Gitalist for backwards compatibility.
This commit adds those urls to the relevant Controllers as redirects to
their new location.
7a8de81
@seveas seveas Compatibility with older perls 0ac7bd6
@seveas seveas Bugfix: commitdiff_compat was not redirecting properly 64211a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 28, 2012
  1. @seveas

    Gitweb compat: repository summary

    seveas authored
    - Show the summary data again, but nicely formatted
    - Repository owner and clone url can be set in the gitweb section of .git/config
    - Add the url to the model and template
Commits on Jul 29, 2012
  1. @seveas

    Gitweb compat: URL structure

    seveas authored
    One can use gitweb with the following apache config to have
    parameter-less urls:
    
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !\.git/(HEAD|refs|info|objects)
    RewriteRule ^.*\.git.*$ /gitweb.cgi%{REQUEST_URI} [PT]
    
    We use this on perl5.git.perl.org, some other sites do this too. We'd
    like these URLs to be supported by Gitalist for backwards compatibility.
    This commit adds those urls to the relevant Controllers as redirects to
    their new location.
  2. @seveas

    Compatibility with older perls

    seveas authored
Commits on Jul 30, 2012
  1. @seveas
This page is out of date. Refresh to see the latest.
View
14 lib/Gitalist/Git/Repository.pm
@@ -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(
View
109 lib/Gitalist/URIStructure/Ref.pm
@@ -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;
View
13 lib/Gitalist/URIStructure/Repository.pm
@@ -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;
View
11 root/fragment/repository/summary.tt2
@@ -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>
View
4 root/repository/summary.tt2
@@ -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
12 root/static/css/core.css
@@ -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
Something went wrong with that request. Please try again.