... | ... |
@@ -183,16 +183,16 @@ sub startup { |
183 | 183 |
$r->get('/tags')->name('tags'); |
184 | 184 |
|
185 | 185 |
# Tree |
186 |
- $r->get('/tree/(*object)')->name('tree'); |
|
186 |
+ $r->get('/tree/:rev/(*dir)', {dir => undef})->name('tree'); |
|
187 | 187 |
|
188 | 188 |
# Blob |
189 |
- $r->get('/blob/(*object)')->name('blob'); |
|
189 |
+ $r->get('/blob/:rev/(*file)', {file => undef})->name('blob'); |
|
190 | 190 |
|
191 | 191 |
# Blob diff |
192 | 192 |
$r->get('/blobdiff/(#diff)/(*file)')->name('blobdiff'); |
193 | 193 |
|
194 | 194 |
# Raw |
195 |
- $r->get('/raw/(*object)')->name('raw'); |
|
195 |
+ $r->get('/raw/:rev/(*file)', {file => undef})->name('raw'); |
|
196 | 196 |
|
197 | 197 |
# Archive |
198 | 198 |
$r->get('/archive/(#rev).tar.gz')->name('archive')->to(archive_type => 'tar'); |
... | ... |
@@ -36,7 +36,7 @@ sub dec { |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
sub authors { |
39 |
- my ($self, $user, $project, $ref, $file) = @_; |
|
39 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
40 | 40 |
|
41 | 41 |
# Command "git log FILE" |
42 | 42 |
my @cmd = $self->cmd( |
... | ... |
@@ -44,7 +44,7 @@ sub authors { |
44 | 44 |
$project, |
45 | 45 |
'log', |
46 | 46 |
'--format=%an', |
47 |
- $ref, |
|
47 |
+ $rev, |
|
48 | 48 |
'--', |
49 | 49 |
$file |
50 | 50 |
); |
... | ... |
@@ -132,10 +132,10 @@ sub blobdiffs { |
132 | 132 |
} |
133 | 133 |
|
134 | 134 |
sub blob_plain { |
135 |
- my ($self, $user, $project, $ref, $path) = @_; |
|
135 |
+ my ($self, $user, $project, $rev, $path) = @_; |
|
136 | 136 |
|
137 | 137 |
# Get blob |
138 |
- my @cmd = $self->cmd($user, $project, 'cat-file', 'blob', "$ref:$path"); |
|
138 |
+ my @cmd = $self->cmd($user, $project, 'cat-file', 'blob', "$rev:$path"); |
|
139 | 139 |
open my $fh, "-|", @cmd |
140 | 140 |
or croak 500, "Open git-cat-file failed"; |
141 | 141 |
local $/; |
... | ... |
@@ -466,7 +466,7 @@ sub branches { |
466 | 466 |
} |
467 | 467 |
|
468 | 468 |
sub id_by_path { |
469 |
- my ($self, $user, $project, $commit_id, $path, $type) = @_; |
|
469 |
+ my ($self, $user, $project, $rev, $path, $type) = @_; |
|
470 | 470 |
|
471 | 471 |
# Get blob id or tree id (command "git ls-tree") |
472 | 472 |
$path =~ s#/+$##; |
... | ... |
@@ -474,7 +474,7 @@ sub id_by_path { |
474 | 474 |
$user, |
475 | 475 |
$project, |
476 | 476 |
'ls-tree', |
477 |
- $commit_id, |
|
477 |
+ $rev, |
|
478 | 478 |
'--', |
479 | 479 |
$path |
480 | 480 |
); |
... | ... |
@@ -531,34 +531,6 @@ sub root_ns { |
531 | 531 |
return $root; |
532 | 532 |
} |
533 | 533 |
|
534 |
-sub parse_object { |
|
535 |
- my ($self, $user, $project, $id_path) = @_; |
|
536 |
- |
|
537 |
- # Parse id and path |
|
538 |
- my $refs = $self->references($user, $project); |
|
539 |
- my $id; |
|
540 |
- my $path; |
|
541 |
- for my $rs (values %$refs) { |
|
542 |
- for my $ref (@$rs) { |
|
543 |
- $ref =~ s#^heads/##; |
|
544 |
- $ref =~ s#^tags/##; |
|
545 |
- if ($id_path =~ s#^\Q$ref(/|$)##) { |
|
546 |
- $id = $ref; |
|
547 |
- $path = $id_path; |
|
548 |
- last; |
|
549 |
- } |
|
550 |
- } |
|
551 |
- } |
|
552 |
- unless (defined $id) { |
|
553 |
- if ($id_path =~ s#(^[^/]+)(/|$)##) { |
|
554 |
- $id = $1; |
|
555 |
- $path = $id_path; |
|
556 |
- } |
|
557 |
- } |
|
558 |
- |
|
559 |
- return [$id, $path]; |
|
560 |
-} |
|
561 |
- |
|
562 | 534 |
sub path_by_id { |
563 | 535 |
my ($self, $user, $project, $base, $hash) = @_; |
564 | 536 |
|
... | ... |
@@ -791,7 +763,7 @@ sub id_set_multi { |
791 | 763 |
} |
792 | 764 |
|
793 | 765 |
sub latest_commit_log { |
794 |
- my ($self, $user, $project, $ref, $file) = @_; |
|
766 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
795 | 767 |
|
796 | 768 |
my $commit_log = {}; |
797 | 769 |
$file = '' unless defined $file; |
... | ... |
@@ -804,7 +776,7 @@ sub latest_commit_log { |
804 | 776 |
'-n', |
805 | 777 |
'1', |
806 | 778 |
'--pretty=format:%H - %an - %ar : %s', |
807 |
- $ref, |
|
779 |
+ $rev, |
|
808 | 780 |
'--', |
809 | 781 |
$file |
810 | 782 |
); |
... | ... |
@@ -1313,9 +1285,18 @@ sub timestamp { |
1313 | 1285 |
} |
1314 | 1286 |
|
1315 | 1287 |
sub trees { |
1316 |
- my ($self, $user, $project, $tid, $ref, $dir) = @_; |
|
1288 |
+ my ($self, $user, $project, $rev, $dir) = @_; |
|
1289 |
+ $dir = '' unless defined $dir; |
|
1317 | 1290 |
|
1318 | 1291 |
# Get tree |
1292 |
+ my $tid; |
|
1293 |
+ if (defined $dir && $dir ne '') { |
|
1294 |
+ $tid = $self->id_by_path($user, $project, $rev, $dir, 'tree'); |
|
1295 |
+ } |
|
1296 |
+ else { |
|
1297 |
+ my $commit = $self->parse_commit($user, $project, $rev); |
|
1298 |
+ $tid = $commit->{tree}; |
|
1299 |
+ } |
|
1319 | 1300 |
my @entries = (); |
1320 | 1301 |
my $show_sizes = 0; |
1321 | 1302 |
my @cmd = $self->cmd( |
... | ... |
@@ -1343,7 +1324,7 @@ sub trees { |
1343 | 1324 |
|
1344 | 1325 |
# Commit log |
1345 | 1326 |
my $name = defined $dir && $dir ne '' ? "$dir/$tree->{name}" : $tree->{name}; |
1346 |
- my $commit_log = $self->latest_commit_log($user, $project, $ref, $name); |
|
1327 |
+ my $commit_log = $self->latest_commit_log($user, $project, $rev, $name); |
|
1347 | 1328 |
$tree = {%$tree, %$commit_log}; |
1348 | 1329 |
|
1349 | 1330 |
push @$trees, $tree; |
... | ... |
@@ -1,29 +1,27 @@ |
1 | 1 |
<% |
2 | 2 |
# API |
3 |
- my $api = Gitprep::API->new($self); |
|
3 |
+ my $api = gitprep_api; |
|
4 | 4 |
|
5 | 5 |
# Parameters |
6 | 6 |
my $user = param('user'); |
7 | 7 |
my $project = param('project'); |
8 |
- my $object = param('object'); |
|
8 |
+ my $rev = param('rev'); |
|
9 |
+ my $file = param('file'); |
|
9 | 10 |
|
10 | 11 |
# Git |
11 | 12 |
my $git = $self->app->git; |
12 |
- |
|
13 |
- # Revision and blob |
|
14 |
- my ($rev, $blob) = @{$git->parse_object($user, $project, $object)}; |
|
15 | 13 |
|
16 | 14 |
# Commit log |
17 |
- my $commit_log = $git->latest_commit_log($user, $project, $rev, $blob); |
|
15 |
+ my $commit_log = $git->latest_commit_log($user, $project, $rev, $file); |
|
18 | 16 |
|
19 | 17 |
# Commit |
20 | 18 |
my $commit = $git->parse_commit($user, $project, $rev); |
21 | 19 |
|
22 | 20 |
# Authors |
23 |
- my $authors = $git->authors($user, $project, $rev, $blob); |
|
21 |
+ my $authors = $git->authors($user, $project, $rev, $file); |
|
24 | 22 |
|
25 | 23 |
# Blob content |
26 |
- my $bid = $git->id_by_path($user, $project, $rev, $blob, 'blob') |
|
24 |
+ my $bid = $git->id_by_path($user, $project, $rev, $file, 'blob') |
|
27 | 25 |
or $api->croak('Cannot find file'); |
28 | 26 |
my @cmd = $git->cmd( |
29 | 27 |
$user, |
... | ... |
@@ -33,11 +31,11 @@ |
33 | 31 |
$bid |
34 | 32 |
); |
35 | 33 |
open my $fh, '-|', @cmd |
36 |
- or $api->croak(qq/Couldn't cat "$blob", "$bid"/); |
|
34 |
+ or $api->croak(qq/Couldn't cat "$file", "$bid"/); |
|
37 | 35 |
|
38 | 36 |
# Blob info |
39 |
- my $blob_size = $git->blob_size_kb($user, $project, $rev, $blob); |
|
40 |
- my $mimetype = $git->blob_mimetype($fh, $blob); |
|
37 |
+ my $file_size = $git->blob_size_kb($user, $project, $rev, $file); |
|
38 |
+ my $mimetype = $git->blob_mimetype($fh, $file); |
|
41 | 39 |
|
42 | 40 |
# Parse line |
43 | 41 |
my $lines =[]; |
... | ... |
@@ -58,7 +56,7 @@ |
58 | 56 |
<div class="container"> |
59 | 57 |
%= include '/include/project_header'; |
60 | 58 |
%= include '/include/code_menu', display => 'files'; |
61 |
- %= include '/include/page_path', type => 'blob', Path => $blob; |
|
59 |
+ %= include '/include/page_path', type => 'blob', Path => $file; |
|
62 | 60 |
|
63 | 61 |
<div class="border-gray" style="margin-bottom:20px"> |
64 | 62 |
<div class="bk-blue-light padding5"> |
... | ... |
@@ -80,20 +78,20 @@ |
80 | 78 |
<span style="color:gray">|</span> |
81 | 79 |
<%= @$lines %> lines |
82 | 80 |
<span style="color:gray">|</span> |
83 |
- <%= $blob_size %>kb |
|
81 |
+ <%= $file_size %>kb |
|
84 | 82 |
</div> |
85 | 83 |
<div class="span4 offset1-mini text-right"> |
86 |
- <a class="btn" href="<%= url_for("/$user/$project/raw/$rev/$blob") %>">Raw</a><a class="btn" href="<%= url_for("/$user/$project/commits/$rev/$blob") %>">History</a> |
|
84 |
+ <a class="btn" href="<%= url_for("/$user/$project/raw/$rev/$file") %>">Raw</a><a class="btn" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a> |
|
87 | 85 |
</div> |
88 | 86 |
</div> |
89 | 87 |
</div> |
90 | 88 |
% if ($mimetype =~ m#^image/#) { |
91 | 89 |
<div> |
92 | 90 |
<img type="<%= $mimetype %> |
93 |
- % if (defined $blob) { |
|
94 |
- alt="<%= $blob %>" title="<%= $blob %>" |
|
91 |
+ % if (defined $file) { |
|
92 |
+ alt="<%= $file %>" title="<%= $file %>" |
|
95 | 93 |
% } |
96 |
- src="<%= url_for("/$user/$project/raw/$rev/$blob") %>" |
|
94 |
+ src="<%= url_for("/$user/$project/raw/$rev/$file") %>" |
|
97 | 95 |
/> |
98 | 96 |
</div> |
99 | 97 |
% } else { |
... | ... |
@@ -31,7 +31,7 @@ |
31 | 31 |
|
32 | 32 |
# End commit |
33 | 33 |
my $end_commit = $git->parse_commit($user, $project, $rev2) |
34 |
- or $api->croak('Unknown commit object'); |
|
34 |
+ or $api->croak('Unknown commit revision'); |
|
35 | 35 |
|
36 | 36 |
# Diff tree |
37 | 37 |
my $difftrees = $git->difftree( |
... | ... |
@@ -1,3 +1,7 @@ |
1 |
+<% |
|
2 |
+ my $dir = stash('dir'); |
|
3 |
+%> |
|
4 |
+ |
|
1 | 5 |
%= stylesheet begin |
2 | 6 |
/* Source tree */ |
3 | 7 |
.tree { |
... | ... |
@@ -96,9 +100,9 @@ |
96 | 100 |
<div class="padding5 border-bottom-gray"> |
97 | 101 |
<div class="row"> |
98 | 102 |
<div class="span8"> |
99 |
- <b><%= $latest_commit_log->{author} %></b> |
|
103 |
+ <b><%= $commit->{author} %></b> |
|
100 | 104 |
<span class="muted"> |
101 |
- authored <%= $latest_commit_log->{author_date} %> |
|
105 |
+ authored <%= $commit->{author_date} %> |
|
102 | 106 |
</span> |
103 | 107 |
</div> |
104 | 108 |
<div class="span3 offset1-mini text-right"> |
... | ... |
@@ -19,23 +19,13 @@ |
19 | 19 |
my $commits_number; |
20 | 20 |
my $readme; |
21 | 21 |
if ($git->branch_exists($user, $project)) { |
22 |
- # Id and directory |
|
23 |
- my ($id, $dir) = @{$git->parse_object($user, $project, "$rev/")}; |
|
22 |
+ # Directory |
|
24 | 23 |
|
25 |
- # Tree id |
|
26 |
- my $tid; |
|
27 |
- my $commit = $git->parse_commit($user, $project, $id); |
|
28 |
- if (defined $dir && $dir ne '') { |
|
29 |
- $tid = $git->id_by_path($user, $project, $id, $dir, 'tree'); |
|
30 |
- } |
|
31 |
- else { $tid = $commit->{tree} } |
|
32 |
- $self->render_not_found unless defined $tid; |
|
33 |
- |
|
34 |
- # Commit log |
|
35 |
- my $latest_commit_log = $git->latest_commit_log($user, $project, $rev); |
|
24 |
+ # Commit |
|
25 |
+ my $commit = $git->parse_commit($user, $project, $rev); |
|
36 | 26 |
|
37 | 27 |
# Tree |
38 |
- my $trees = $git->trees($user, $project, $tid, $rev); |
|
28 |
+ my $trees = $git->trees($user, $project, $rev); |
|
39 | 29 |
|
40 | 30 |
# Commits number |
41 | 31 |
$commits_number = $git->commits_number($user, $project, $rev); |
... | ... |
@@ -47,9 +37,7 @@ |
47 | 37 |
# Variable for included template |
48 | 38 |
stash( |
49 | 39 |
commit => $commit, |
50 |
- latest_commit_log => $latest_commit_log, |
|
51 | 40 |
trees => $trees, |
52 |
- dir => $dir, |
|
53 | 41 |
rev => $rev, |
54 | 42 |
title => "$user/$project" |
55 | 43 |
); |
... | ... |
@@ -5,19 +5,17 @@ |
5 | 5 |
# Parameters |
6 | 6 |
my $user = param('user'); |
7 | 7 |
my $project = param('project'); |
8 |
- my $object = param('object'); |
|
8 |
+ my $rev = param('rev'); |
|
9 |
+ my $file = param('file'); |
|
9 | 10 |
|
10 | 11 |
# Git |
11 | 12 |
my $git = $self->app->git; |
12 |
- |
|
13 |
- # Id and file |
|
14 |
- my ($rev, $blob) = @{$git->parse_object($user, $project, $object)}; |
|
15 | 13 |
|
16 | 14 |
# Commit |
17 |
- my $commit_log = $git->latest_commit_log($user, $project, $rev, $blob); |
|
15 |
+ my $commit_log = $git->latest_commit_log($user, $project, $rev, $file); |
|
18 | 16 |
|
19 | 17 |
# Blob content |
20 |
- my $bid = $git->id_by_path($user, $project, $rev, $blob, 'blob') |
|
18 |
+ my $bid = $git->id_by_path($user, $project, $rev, $file, 'blob') |
|
21 | 19 |
or $api->croak('Cannot find file'); |
22 | 20 |
my @cmd = $git->cmd( |
23 | 21 |
$user, |
... | ... |
@@ -27,7 +25,7 @@ |
27 | 25 |
$bid |
28 | 26 |
); |
29 | 27 |
open my $fh, '-|', @cmd |
30 |
- or $api->croak(qq/Couldn't cat "$blob", "$bid"/); |
|
28 |
+ or $api->croak(qq/Couldn't cat "$file", "$bid"/); |
|
31 | 29 |
|
32 | 30 |
# Blob plain |
33 | 31 |
my $commit; |
... | ... |
@@ -35,7 +33,7 @@ |
35 | 33 |
my $lines =[]; |
36 | 34 |
|
37 | 35 |
# Content type |
38 |
- my $type = $git->blob_contenttype($fh, $blob); |
|
36 |
+ my $type = $git->blob_contenttype($fh, $file); |
|
39 | 37 |
|
40 | 38 |
# Convert text/* content type to text/plain |
41 | 39 |
if ($self->config('prevent_xss') && |
... | ... |
@@ -48,16 +46,16 @@ |
48 | 46 |
} |
49 | 47 |
|
50 | 48 |
# File name |
51 |
- my $blob_name = $rev; |
|
52 |
- if (defined $blob) { $blob_name = $blob } |
|
53 |
- elsif ($type =~ m/^text\//) { $blob_name .= '.txt' } |
|
49 |
+ my $file_name = $rev; |
|
50 |
+ if (defined $file) { $file_name = $file } |
|
51 |
+ elsif ($type =~ m/^text\//) { $file_name .= '.txt' } |
|
54 | 52 |
|
55 | 53 |
# Content |
56 | 54 |
my $content = do { local $/; <$fh> }; |
57 | 55 |
my $sandbox = $self->config('prevent_xss') && |
58 | 56 |
$type !~ m#^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)#; |
59 | 57 |
my $content_disposition = $sandbox ? 'attachment' : 'inline'; |
60 |
- $content_disposition .= "; filename=$blob_name"; |
|
58 |
+ $content_disposition .= "; filename=$file_name"; |
|
61 | 59 |
|
62 | 60 |
# Render |
63 | 61 |
$self->res->headers->content_disposition($content_disposition); |
... | ... |
@@ -5,35 +5,19 @@ |
5 | 5 |
# Parameters |
6 | 6 |
my $user = param('user'); |
7 | 7 |
my $project = param('project'); |
8 |
- my $object ||= param('object') || 'master'; |
|
8 |
+ my $rev = param('rev'); |
|
9 |
+ my $dir = param('dir'); |
|
9 | 10 |
|
10 | 11 |
# Git |
11 | 12 |
my $git = app->git; |
12 |
- |
|
13 |
- # Id and directory |
|
14 |
- my ($rev, $dir) = @{$git->parse_object($user, $project, $object)}; |
|
15 | 13 |
|
16 | 14 |
# Tree id |
17 | 15 |
my $commit = $git->parse_commit($user, $project, $rev); |
18 |
- my $tid; |
|
19 | 16 |
my $top; |
20 |
- if (defined $dir && $dir ne '') { |
|
21 |
- $tid = $git->id_by_path($user, $project, $rev, $dir, 'tree'); |
|
22 |
- } |
|
23 |
- else { |
|
24 |
- $top = 1; |
|
25 |
- $tid = $commit->{tree}; |
|
26 |
- } |
|
27 |
- $self->render_not_found unless defined $tid; |
|
28 |
- |
|
29 |
- # Commit log |
|
30 |
- my $latest_commit_log = $git->latest_commit_log($user, $project, $rev); |
|
17 |
+ $top = 1 unless defined $dir && $dir ne ''; |
|
31 | 18 |
|
32 | 19 |
# Tree |
33 |
- my $trees = $git->trees($user, $project, $tid, $rev, $dir); |
|
34 |
- |
|
35 |
- # Repository description |
|
36 |
- my $desc = $git->description($user, $project); |
|
20 |
+ my $trees = $git->trees($user, $project, $rev, $dir); |
|
37 | 21 |
|
38 | 22 |
# Commits number |
39 | 23 |
my $commits_number = $git->commits_number($user, $project, $rev); |
... | ... |
@@ -47,7 +31,6 @@ |
47 | 31 |
stash( |
48 | 32 |
rev => $rev, |
49 | 33 |
commit => $commit, |
50 |
- latest_commit_log => $latest_commit_log, |
|
51 | 34 |
trees => $trees, |
52 | 35 |
dir => $dir, |
53 | 36 |
title => "$project/$dir at $rev - $user/$project" |