... | ... |
@@ -107,7 +107,7 @@ sub startup { |
107 | 107 |
$r->get('/:user/:project/tree/(*id_dir)')->to('#tree'); |
108 | 108 |
|
109 | 109 |
# Blob |
110 |
- $r->get('/:user/:project/blob/(*id_file)')->to('#blob'); |
|
110 |
+ $r->get('/:user/:project/blob/(*object)')->to('#blob'); |
|
111 | 111 |
|
112 | 112 |
# Raw |
113 | 113 |
$r->get('/:user/:project/raw/(*id_file)')->to('#raw'); |
... | ... |
@@ -2,69 +2,52 @@ |
2 | 2 |
# API |
3 | 3 |
my $api = Gitprep::API->new($self); |
4 | 4 |
|
5 |
+ # Parameter |
|
5 | 6 |
my $user = param('user'); |
6 | 7 |
my $project = param('project'); |
7 |
- my $plain = param('plain'); |
|
8 |
- |
|
9 | 8 |
my $root_ns = $api->root_ns(config->{root}); |
10 | 9 |
|
11 | 10 |
# Parameters |
12 | 11 |
my $rep_ns = "$root_ns/$user/$project.git"; |
13 | 12 |
my $rep = "/$rep_ns"; |
14 |
- my $home_ns = $api->dirname($rep_ns); |
|
15 |
- my $home = "/$home_ns"; |
|
16 |
- my $id_file = param('id_file'); |
|
13 |
+ my $object = param('object'); |
|
17 | 14 |
|
18 |
- # Id and file |
|
19 |
- my ($id, $file) = $api->parse_id_path($rep, $id_file); |
|
15 |
+ # Revision and blob |
|
16 |
+ my ($rev, $blob) = $api->parse_id_path($rep, $object); |
|
20 | 17 |
|
21 | 18 |
# Git |
22 | 19 |
my $git = $self->app->git; |
23 | 20 |
|
21 |
+ # Commit log |
|
22 |
+ my $commit_log = $git->latest_commit_log($rep, $rev, $blob); |
|
23 |
+ |
|
24 | 24 |
# Commit |
25 |
- my $commit_log = $git->latest_commit_log($rep, $id, $file); |
|
25 |
+ my $commit = $git->parse_commit($rep, $rev); |
|
26 | 26 |
|
27 | 27 |
# Authors |
28 |
- my $authors = $git->authors($rep, $id, $file); |
|
28 |
+ my $authors = $git->authors($rep, $rev, $blob); |
|
29 | 29 |
|
30 | 30 |
# Blob content |
31 |
- my $bid = $git->id_by_path($rep, $id, $file, 'blob') |
|
31 |
+ my $bid = $git->id_by_path($rep, $rev, $blob, 'blob') |
|
32 | 32 |
or $api->croak('Cannot find file'); |
33 | 33 |
my @cmd = ($git->cmd($rep), 'cat-file', 'blob', $bid); |
34 | 34 |
open my $fh, '-|', @cmd |
35 |
- or $api->croak(qq/Couldn't cat "$file", "$bid"/); |
|
36 |
- |
|
37 |
- # Blob size |
|
38 |
- my $blob_size = $git->blob_size_kb($rep, $id, $file); |
|
39 |
- |
|
40 |
- # Blob plain |
|
41 |
- my $commit; |
|
42 |
- my $mimetype; |
|
43 |
- my $lines =[]; |
|
44 |
- # MIME type |
|
45 |
- $mimetype = $git->blob_mimetype($fh, $file); |
|
35 |
+ or $api->croak(qq/Couldn't cat "$blob", "$bid"/); |
|
46 | 36 |
|
47 |
- # Redirect to blob-plain if no display MIME type |
|
48 |
- if ($mimetype !~ m#^(?:text/|image/(?:gif|png|jpeg)$)# && -B $fh) { |
|
49 |
- close $fh; |
|
50 |
- my $url = $self->url_for('blob_plain', |
|
51 |
- project => $rep_ns, id_file => "$id/$file"); |
|
52 |
- |
|
53 |
- return $self->redirect_to($url); |
|
54 |
- } |
|
55 |
- |
|
56 |
- # Commit |
|
57 |
- $commit = $git->parse_commit($rep, $id); |
|
37 |
+ # Blob info |
|
38 |
+ my $blob_size = $git->blob_size_kb($rep, $rev, $blob); |
|
39 |
+ my $mimetype = $git->blob_mimetype($fh, $blob); |
|
58 | 40 |
|
59 | 41 |
# Parse line |
42 |
+ my $lines =[]; |
|
60 | 43 |
while (my $line = $git->dec(scalar <$fh>)) { |
61 | 44 |
chomp $line; |
62 | 45 |
$line = $git->_tab_to_space($line); |
63 | 46 |
push @$lines, $line; |
64 | 47 |
} |
65 | 48 |
|
66 |
- # Global variable |
|
67 |
- stash(id => $id, project => $project); |
|
49 |
+ # Variables for included template |
|
50 |
+ stash(id => $rev, project => $project); |
|
68 | 51 |
%> |
69 | 52 |
|
70 | 53 |
% layout 'common'; |
... | ... |
@@ -76,17 +59,17 @@ |
76 | 59 |
.blob_header { |
77 | 60 |
border:1px solid gray; |
78 | 61 |
} |
79 |
- .blob_header .top { |
|
62 |
+ .blob_header .htop { |
|
80 | 63 |
background-color:#E6F1F6; |
81 | 64 |
padding:10px; |
82 | 65 |
} |
83 |
- .blob_header .author_date { |
|
66 |
+ .blob_header .hauthor_date { |
|
84 | 67 |
color: #666; |
85 | 68 |
} |
86 |
- .blob_header a.comment { |
|
69 |
+ .blob_header a.hcomment { |
|
87 | 70 |
color:#4183C4; |
88 | 71 |
} |
89 |
- .blob_header .bottom { |
|
72 |
+ .blob_header .hbottom { |
|
90 | 73 |
padding:5px; |
91 | 74 |
padding-left:10px; |
92 | 75 |
} |
... | ... |
@@ -172,17 +155,17 @@ |
172 | 155 |
} |
173 | 156 |
% end |
174 | 157 |
|
175 |
- %= include '/include/page_path', type => 'blob', Path => $file; |
|
158 |
+ %= include '/include/page_path', type => 'blob', Path => $blob; |
|
176 | 159 |
|
177 | 160 |
<div class="blob_header"> |
178 |
- <div class="top"> |
|
161 |
+ <div class="htop"> |
|
179 | 162 |
<b><%= $commit_log->{author} %></b> |
180 |
- <span class="author_date"><%= $commit_log->{author_date} %></span> |
|
181 |
- <a class="comment" href="<%= url_for("/$user/$project/commit/$id") %>"> |
|
163 |
+ <span class="hauthor_date"><%= $commit_log->{author_date} %></span> |
|
164 |
+ <a class="hcomment" href="<%= url_for("/$user/$project/commit/$rev") %>"> |
|
182 | 165 |
<%= $commit->{title} %> |
183 | 166 |
</a> |
184 | 167 |
</div> |
185 |
- <div class="bottom"> |
|
168 |
+ <div class="hbottom"> |
|
186 | 169 |
<%= @$authors %> contributor |
187 | 170 |
</div> |
188 | 171 |
</div> |
... | ... |
@@ -193,18 +176,18 @@ |
193 | 176 |
file <span style="color:gray">|</span> <%= @$lines %> lines <span style="color:gray">|</span> <%= $blob_size %>kb |
194 | 177 |
</div> |
195 | 178 |
<div class="sright_header"> |
196 |
- <a class="sraw" href="<%= url_for("/$user/$project/raw/$id/$file") %>">Raw</a> |
|
197 |
- <!-- TODO: <a class="sblame" href="<%= url_for("/$user/$project/blame/$id/$file") %>">Blame</a> --> |
|
198 |
- <a class="shistory" href="<%= url_for("/$user/$project/commits/$id/$file") %>">History</a> |
|
179 |
+ <a class="sraw" href="<%= url_for("/$user/$project/raw/$rev/$blob") %>">Raw</a> |
|
180 |
+ <!-- TODO: <a class="sblame" href="<%= url_for("/$user/$project/blame/$rev/$blob") %>">Blame</a> --> |
|
181 |
+ <a class="shistory" href="<%= url_for("/$user/$project/commits/$rev/$blob") %>">History</a> |
|
199 | 182 |
</div> |
200 | 183 |
</div> |
201 | 184 |
<div class="sbody"> |
202 | 185 |
% if ($mimetype =~ m#^image/#) { |
203 | 186 |
<img type="<%= $mimetype %> |
204 |
- % if (defined $file) { |
|
205 |
- alt="<%= $file %>" title="<%= $file %>" |
|
187 |
+ % if (defined $blob) { |
|
188 |
+ alt="<%= $blob %>" title="<%= $blob %>" |
|
206 | 189 |
% } |
207 |
- src="<%= url_for('blob_plain', project => $rep_ns, id_file => "$id/$file") %>" |
|
190 |
+ src="<%= url_for('blob_plain', project => $rep_ns, id_file => "$rev/$blob") %>" |
|
208 | 191 |
/> |
209 | 192 |
% } else { |
210 | 193 |
% my $nr = 1; |