... | ... |
@@ -107,7 +107,10 @@ sub startup { |
107 | 107 |
|
108 | 108 |
# Blob |
109 | 109 |
$r->get('/:user/:repository/blob/(*id_file)')->to('#blob'); |
110 |
- |
|
110 |
+ |
|
111 |
+ # Raw |
|
112 |
+ $r->get('/:user/:repository/raw/(*id_file)')->to('#raw'); |
|
113 |
+ |
|
111 | 114 |
# Projects |
112 | 115 |
$r->get('/(*home)/projects')->to('#projects')->name('projects'); |
113 | 116 |
|
... | ... |
@@ -122,10 +125,6 @@ sub startup { |
122 | 125 |
$r->get('/commitdiff-plain/(*diff)') |
123 | 126 |
->to('#commitdiff', plain => 1)->name('commitdiff_plain'); |
124 | 127 |
|
125 |
- # Blob plain |
|
126 |
- $r->get('/blob-plain/(*id_file)') |
|
127 |
- ->to('#blob', plain => 1)->name('blob_plain'); |
|
128 |
- |
|
129 | 128 |
# Blob diff |
130 | 129 |
$r->get('/blobdiff/(#diff)/(*file)') |
131 | 130 |
->to('#blobdiff')->name('blobdiff'); |
... | ... |
@@ -238,64 +238,6 @@ sub snapshot { |
238 | 238 |
$self->$cb; |
239 | 239 |
} |
240 | 240 |
|
241 |
-sub summary { |
|
242 |
- my $self = shift; |
|
243 |
- |
|
244 |
- # Parameters |
|
245 |
- my $project_ns = $self->param('project'); |
|
246 |
- my $project = "/$project_ns"; |
|
247 |
- my $home_ns = dirname $project_ns; |
|
248 |
- my $home = "/$home_ns"; |
|
249 |
- |
|
250 |
- # Git |
|
251 |
- my $git = $self->app->git; |
|
252 |
- |
|
253 |
- # HEAd commit |
|
254 |
- my $project_description = $git->project_description($project); |
|
255 |
- my $project_owner = $git->project_owner($project); |
|
256 |
- my $head_commit = $git->parse_commit($project, 'HEAD'); |
|
257 |
- my $committer_date |
|
258 |
- = $git->parse_date($head_commit->{committer_epoch}, $head_commit->{committer_tz}); |
|
259 |
- my $last_change = $git->timestamp($committer_date); |
|
260 |
- my $head_id = $head_commit->{id}; |
|
261 |
- my $urls = $git->project_urls($project); |
|
262 |
- |
|
263 |
- # Commits |
|
264 |
- my $commit_count = 20; |
|
265 |
- my $commits = $head_id ? $git->parse_commits($project, $head_id, $commit_count) : (); |
|
266 |
- |
|
267 |
- # References |
|
268 |
- my $refs = $git->references($project); |
|
269 |
- |
|
270 |
- # Tags |
|
271 |
- my $tag_count = 20; |
|
272 |
- my $tags = $git->tags($project, $tag_count - 1); |
|
273 |
- |
|
274 |
- # Heads |
|
275 |
- my $head_count = 20; |
|
276 |
- my $heads = $git->heads($project, $head_count - 1); |
|
277 |
- |
|
278 |
- # Render |
|
279 |
- $self->render( |
|
280 |
- home => $home, |
|
281 |
- home_ns => $home_ns, |
|
282 |
- project => $project, |
|
283 |
- project_ns => $project_ns, |
|
284 |
- project_description => $project_description, |
|
285 |
- project_owner => $project_owner, |
|
286 |
- last_change => $last_change, |
|
287 |
- urls => $urls, |
|
288 |
- commits => $commits, |
|
289 |
- tags => $tags, |
|
290 |
- head_id => $head_id, |
|
291 |
- heads => $heads, |
|
292 |
- refs => $refs, |
|
293 |
- commit_count => $commit_count, |
|
294 |
- tag_count => $tag_count, |
|
295 |
- head_count => $head_count |
|
296 |
- ); |
|
297 |
-} |
|
298 |
- |
|
299 | 241 |
sub tag { |
300 | 242 |
my $self = shift; |
301 | 243 |
|
... | ... |
@@ -41,61 +41,26 @@ |
41 | 41 |
my $commit; |
42 | 42 |
my $mimetype; |
43 | 43 |
my $lines =[]; |
44 |
- if ($plain) { |
|
45 |
- # Content type |
|
46 |
- my $type = $git->blob_contenttype($fh, $file); |
|
47 |
- |
|
48 |
- # Convert text/* content type to text/plain |
|
49 |
- if ($self->config('prevent_xss') && |
|
50 |
- ($type =~ m#^text/[a-z]+\b(.*)$# || |
|
51 |
- ($type =~ m#^[a-z]+/[a-z]\+xml\b(.*)$# && -T $fh))) |
|
52 |
- { |
|
53 |
- my $rest = $1; |
|
54 |
- $rest = defined $rest ? $rest : ''; |
|
55 |
- $type = "text/plain$rest"; |
|
56 |
- } |
|
57 |
- |
|
58 |
- # File name |
|
59 |
- my $file_name = $id; |
|
60 |
- if (defined $file) { $file_name = $file } |
|
61 |
- elsif ($type =~ m/^text\//) { $file_name .= '.txt' } |
|
62 |
- |
|
63 |
- # Content |
|
64 |
- my $content = do { local $/; <$fh> }; |
|
65 |
- my $sandbox = $self->config('prevent_xss') && |
|
66 |
- $type !~ m#^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)#; |
|
67 |
- my $content_disposition = $sandbox ? 'attachment' : 'inline'; |
|
68 |
- $content_disposition .= "; filename=$file_name"; |
|
44 |
+ # MIME type |
|
45 |
+ $mimetype = $git->blob_mimetype($fh, $file); |
|
46 |
+ |
|
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"); |
|
69 | 52 |
|
70 |
- # Render |
|
71 |
- $self->res->headers->content_disposition($content_disposition); |
|
72 |
- $self->res->headers->content_type($type); |
|
73 |
- $self->render_data($content); |
|
53 |
+ return $self->redirect_to($url); |
|
74 | 54 |
} |
75 | 55 |
|
76 |
- # Blob |
|
77 |
- else { |
|
78 |
- # MIME type |
|
79 |
- $mimetype = $git->blob_mimetype($fh, $file); |
|
80 |
- |
|
81 |
- # Redirect to blob-plain if no display MIME type |
|
82 |
- if ($mimetype !~ m#^(?:text/|image/(?:gif|png|jpeg)$)# && -B $fh) { |
|
83 |
- close $fh; |
|
84 |
- my $url = $self->url_for('blob_plain', |
|
85 |
- project => $rep_ns, id_file => "$id/$file"); |
|
86 |
- |
|
87 |
- return $self->redirect_to($url); |
|
88 |
- } |
|
89 |
- |
|
90 |
- # Commit |
|
91 |
- $commit = $git->parse_commit($rep, $id); |
|
56 |
+ # Commit |
|
57 |
+ $commit = $git->parse_commit($rep, $id); |
|
92 | 58 |
|
93 |
- # Parse line |
|
94 |
- while (my $line = $git->dec(scalar <$fh>)) { |
|
95 |
- chomp $line; |
|
96 |
- $line = $git->_tab_to_space($line); |
|
97 |
- push @$lines, $line; |
|
98 |
- } |
|
59 |
+ # Parse line |
|
60 |
+ while (my $line = $git->dec(scalar <$fh>)) { |
|
61 |
+ chomp $line; |
|
62 |
+ $line = $git->_tab_to_space($line); |
|
63 |
+ push @$lines, $line; |
|
99 | 64 |
} |
100 | 65 |
|
101 | 66 |
# Global variable |
... | ... |
@@ -0,0 +1,67 @@ |
1 |
+<% |
|
2 |
+ # API |
|
3 |
+ my $api = Gitprep::API->new($self); |
|
4 |
+ |
|
5 |
+ my $user = param('user'); |
|
6 |
+ my $repository = param('repository'); |
|
7 |
+ my $root_ns = $api->root_ns(config->{root}); |
|
8 |
+ |
|
9 |
+ # Parameters |
|
10 |
+ my $rep_ns = "$root_ns/$user/$repository.git"; |
|
11 |
+ my $rep = "/$rep_ns"; |
|
12 |
+ my $home_ns = $api->dirname($rep_ns); |
|
13 |
+ my $home = "/$home_ns"; |
|
14 |
+ my $id_file = param('id_file'); |
|
15 |
+ |
|
16 |
+ # Id and file |
|
17 |
+ my ($id, $file) = $api->parse_id_path($rep, $id_file); |
|
18 |
+ |
|
19 |
+ # Git |
|
20 |
+ my $git = $self->app->git; |
|
21 |
+ |
|
22 |
+ # Commit |
|
23 |
+ my $commit_log = $git->latest_commit_log($rep, $id, $file); |
|
24 |
+ |
|
25 |
+ # Blob content |
|
26 |
+ my $bid = $git->id_by_path($rep, $id, $file, 'blob') |
|
27 |
+ or $api->croak('Cannot find file'); |
|
28 |
+ my @cmd = ($git->cmd($rep), 'cat-file', 'blob', $bid); |
|
29 |
+ open my $fh, '-|', @cmd |
|
30 |
+ or $api->croak(qq/Couldn't cat "$file", "$bid"/); |
|
31 |
+ |
|
32 |
+ # Blob plain |
|
33 |
+ my $commit; |
|
34 |
+ my $mimetype; |
|
35 |
+ my $lines =[]; |
|
36 |
+ |
|
37 |
+ # Content type |
|
38 |
+ my $type = $git->blob_contenttype($fh, $file); |
|
39 |
+ |
|
40 |
+ # Convert text/* content type to text/plain |
|
41 |
+ if ($self->config('prevent_xss') && |
|
42 |
+ ($type =~ m#^text/[a-z]+\b(.*)$# || |
|
43 |
+ ($type =~ m#^[a-z]+/[a-z]\+xml\b(.*)$# && -T $fh))) |
|
44 |
+ { |
|
45 |
+ my $rest = $1; |
|
46 |
+ $rest = defined $rest ? $rest : ''; |
|
47 |
+ $type = "text/plain$rest"; |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ # File name |
|
51 |
+ my $file_name = $id; |
|
52 |
+ if (defined $file) { $file_name = $file } |
|
53 |
+ elsif ($type =~ m/^text\//) { $file_name .= '.txt' } |
|
54 |
+ |
|
55 |
+ # Content |
|
56 |
+ my $content = do { local $/; <$fh> }; |
|
57 |
+ my $sandbox = $self->config('prevent_xss') && |
|
58 |
+ $type !~ m#^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)#; |
|
59 |
+ my $content_disposition = $sandbox ? 'attachment' : 'inline'; |
|
60 |
+ $content_disposition .= "; filename=$file_name"; |
|
61 |
+ |
|
62 |
+ # Render |
|
63 |
+ $self->res->headers->content_disposition($content_disposition); |
|
64 |
+ $self->res->headers->content_type($type); |
|
65 |
+ |
|
66 |
+ return $content; |
|
67 |
+%> |