... | ... |
@@ -16,7 +16,7 @@ has text_exts => sub { ['txt'] }; |
16 | 16 |
|
17 | 17 |
# Encode |
18 | 18 |
use Encode qw/encode decode/; |
19 |
-sub enc { |
|
19 |
+sub _enc { |
|
20 | 20 |
my ($self, $str) = @_; |
21 | 21 |
|
22 | 22 |
my $enc = $self->encoding; |
... | ... |
@@ -24,7 +24,7 @@ sub enc { |
24 | 24 |
return encode($enc, $str); |
25 | 25 |
} |
26 | 26 |
|
27 |
-sub dec { |
|
27 |
+sub _dec { |
|
28 | 28 |
my ($self, $str) = @_; |
29 | 29 |
|
30 | 30 |
my $enc = $self->encoding; |
... | ... |
@@ -51,7 +51,7 @@ sub authors { |
51 | 51 |
open my $fh, "-|", @cmd |
52 | 52 |
or croak 500, "Open git-cat-file failed"; |
53 | 53 |
my $authors = {}; |
54 |
- while (my $line = $self->dec(<$fh>)) { |
|
54 |
+ while (my $line = $self->_dec(<$fh>)) { |
|
55 | 55 |
$line =~ s/[\r\n]//g; |
56 | 56 |
$authors->{$line} = 1; |
57 | 57 |
} |
... | ... |
@@ -80,7 +80,7 @@ sub blobdiffs { |
80 | 80 |
open my $fh, '-|', @cmd |
81 | 81 |
or croak('Open self-diff-tree failed'); |
82 | 82 |
my @file_info_raws; |
83 |
- while (my $line = $self->dec(scalar <$fh>)) { |
|
83 |
+ while (my $line = $self->_dec(scalar <$fh>)) { |
|
84 | 84 |
chomp $line; |
85 | 85 |
push @file_info_raws, $line if $line =~ /^:/; |
86 | 86 |
last if $line =~ /^\n/; |
... | ... |
@@ -110,7 +110,7 @@ sub blobdiffs { |
110 | 110 |
); |
111 | 111 |
open my $fh_blobdiff, '-|', @cmd |
112 | 112 |
or croak('Open self-diff-tree failed'); |
113 |
- my @lines = map { $self->dec($_) } <$fh_blobdiff>; |
|
113 |
+ my @lines = map { $self->_dec($_) } <$fh_blobdiff>; |
|
114 | 114 |
close $fh_blobdiff; |
115 | 115 |
my $blobdiff = { |
116 | 116 |
file => $file, |
... | ... |
@@ -131,6 +131,33 @@ sub blobdiffs { |
131 | 131 |
return $blobdiffs; |
132 | 132 |
} |
133 | 133 |
|
134 |
+sub blob { |
|
135 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
136 |
+ |
|
137 |
+ # Blob content |
|
138 |
+ my $bid = $self->id_by_path($user, $project, $rev, $file, 'blob') |
|
139 |
+ or croak 'Cannot find file'; |
|
140 |
+ my @cmd = $self->cmd( |
|
141 |
+ $user, |
|
142 |
+ $project, |
|
143 |
+ 'cat-file', |
|
144 |
+ 'blob', |
|
145 |
+ $bid |
|
146 |
+ ); |
|
147 |
+ open my $fh, '-|', @cmd |
|
148 |
+ or croak "Can't cat $file, $bid"; |
|
149 |
+ |
|
150 |
+ # Parse lines |
|
151 |
+ my $lines =[]; |
|
152 |
+ while (my $line = $self->_dec(scalar <$fh>)) { |
|
153 |
+ chomp $line; |
|
154 |
+ $line = $self->_tab_to_space($line); |
|
155 |
+ push @$lines, $line; |
|
156 |
+ } |
|
157 |
+ |
|
158 |
+ return $lines; |
|
159 |
+} |
|
160 |
+ |
|
134 | 161 |
sub blob_plain { |
135 | 162 |
my ($self, $user, $project, $rev, $path) = @_; |
136 | 163 |
|
... | ... |
@@ -139,14 +166,27 @@ sub blob_plain { |
139 | 166 |
open my $fh, "-|", @cmd |
140 | 167 |
or croak 500, "Open git-cat-file failed"; |
141 | 168 |
local $/; |
142 |
- my $content = $self->dec(scalar <$fh>); |
|
169 |
+ my $content = $self->_dec(scalar <$fh>); |
|
143 | 170 |
close $fh or croak 'Reading git-shortlog failed'; |
144 | 171 |
|
145 | 172 |
return $content; |
146 | 173 |
} |
147 | 174 |
|
148 | 175 |
sub blob_mimetype { |
149 |
- my ($self, $fh, $file) = @_; |
|
176 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
177 |
+ |
|
178 |
+ # Blob content |
|
179 |
+ my $bid = $self->id_by_path($user, $project, $rev, $file, 'blob') |
|
180 |
+ or croak 'Cannot find file'; |
|
181 |
+ my @cmd = $self->cmd( |
|
182 |
+ $user, |
|
183 |
+ $project, |
|
184 |
+ 'cat-file', |
|
185 |
+ 'blob', |
|
186 |
+ $bid |
|
187 |
+ ); |
|
188 |
+ open my $fh, '-|', @cmd |
|
189 |
+ or croak "Can't cat $file, $bid"; |
|
150 | 190 |
|
151 | 191 |
return 'text/plain' unless $fh; |
152 | 192 |
|
... | ... |
@@ -167,10 +207,10 @@ sub blob_mimetype { |
167 | 207 |
} |
168 | 208 |
|
169 | 209 |
sub blob_contenttype { |
170 |
- my ($self, $fh, $file, $type) = @_; |
|
210 |
+ my ($self, $user, $project, $rev, $file) = @_; |
|
171 | 211 |
|
172 | 212 |
# Content type |
173 |
- $type ||= $self->blob_mimetype($fh, $file); |
|
213 |
+ my $type = $self->blob_mimetype($user, $project, $rev, $file); |
|
174 | 214 |
if ($type eq 'text/plain') { |
175 | 215 |
$type .= "; charset=" . $self->encoding; |
176 | 216 |
} |
... | ... |
@@ -191,7 +231,7 @@ sub blob_size_kb { |
191 | 231 |
); |
192 | 232 |
open my $fh, "-|", @cmd |
193 | 233 |
or croak 500, "Open cat-file failed"; |
194 |
- my $size = $self->dec(scalar <$fh>); |
|
234 |
+ my $size = $self->_dec(scalar <$fh>); |
|
195 | 235 |
chomp $size; |
196 | 236 |
close $fh or croak 'Reading cat-file failed'; |
197 | 237 |
|
... | ... |
@@ -271,7 +311,7 @@ sub commits_number { |
271 | 311 |
my @cmd = $self->cmd($user, $project, 'shortlog', '-s', $ref); |
272 | 312 |
open my $fh, "-|", @cmd |
273 | 313 |
or croak 500, "Open git-shortlog failed"; |
274 |
- my @commits_infos = map { chomp; $self->dec($_) } <$fh>; |
|
314 |
+ my @commits_infos = map { chomp; $self->_dec($_) } <$fh>; |
|
275 | 315 |
close $fh or croak 'Reading git-shortlog failed'; |
276 | 316 |
|
277 | 317 |
my $commits_num = 0; |
... | ... |
@@ -383,7 +423,7 @@ sub difftree { |
383 | 423 |
); |
384 | 424 |
open my $fh, "-|", @cmd |
385 | 425 |
or croak 500, "Open git-diff-tree failed"; |
386 |
- my @difftree = map { chomp; $self->dec($_) } <$fh>; |
|
426 |
+ my @difftree = map { chomp; $self->_dec($_) } <$fh>; |
|
387 | 427 |
close $fh or croak 'Reading git-diff-tree failed'; |
388 | 428 |
|
389 | 429 |
# Parse "git diff-tree" output |
... | ... |
@@ -449,7 +489,7 @@ sub branches { |
449 | 489 |
open my $fh, '-|', @cmd or return; |
450 | 490 |
|
451 | 491 |
my @branch_names |
452 |
- = map { s/^\*//; s/^\s*//; s/\s*$//; $self->dec($_) } <$fh>; |
|
492 |
+ = map { s/^\*//; s/^\s*//; s/\s*$//; $self->_dec($_) } <$fh>; |
|
453 | 493 |
close $fh or croak qq/Can't open "git branch"/; |
454 | 494 |
|
455 | 495 |
# Branches |
... | ... |
@@ -480,7 +520,7 @@ sub id_by_path { |
480 | 520 |
); |
481 | 521 |
open my $fh, '-|', @cmd |
482 | 522 |
or croak 'Open git-ls-tree failed'; |
483 |
- my $line = $self->dec(scalar <$fh>); |
|
523 |
+ my $line = $self->_dec(scalar <$fh>); |
|
484 | 524 |
close $fh or return; |
485 | 525 |
my ($t, $id) = ($line || '') =~ m/^[0-9]+ (.+) ([0-9a-fA-F]{40})\t/; |
486 | 526 |
return if defined $type && $type ne $t; |
... | ... |
@@ -511,7 +551,7 @@ sub references { |
511 | 551 |
|
512 | 552 |
# Parse references |
513 | 553 |
my %refs; |
514 |
- while (my $line = $self->dec(scalar <$fh>)) { |
|
554 |
+ while (my $line = $self->_dec(scalar <$fh>)) { |
|
515 | 555 |
chomp $line; |
516 | 556 |
if ($line =~ m!^([0-9a-fA-F]{40})\srefs/$type/(.*)$!) { |
517 | 557 |
if (defined $refs{$1}) { push @{$refs{$1}}, $2 } |
... | ... |
@@ -570,7 +610,7 @@ sub last_activity { |
570 | 610 |
'--count=1', 'refs/heads' |
571 | 611 |
); |
572 | 612 |
open my $fh, '-|', @cmd or return; |
573 |
- my $most_recent = $self->dec(scalar <$fh>); |
|
613 |
+ my $most_recent = $self->_dec(scalar <$fh>); |
|
574 | 614 |
close $fh or return; |
575 | 615 |
|
576 | 616 |
# Parse most recent |
... | ... |
@@ -596,7 +636,7 @@ sub object_type { |
596 | 636 |
$cid |
597 | 637 |
); |
598 | 638 |
open my $fh, '-|', @cmd or return; |
599 |
- my $type = $self->dec(scalar <$fh>); |
|
639 |
+ my $type = $self->_dec(scalar <$fh>); |
|
600 | 640 |
close $fh or return; |
601 | 641 |
chomp $type; |
602 | 642 |
|
... | ... |
@@ -619,7 +659,7 @@ sub project_urls { |
619 | 659 |
# Project URLs |
620 | 660 |
open my $fh, '<', "$project/cloneurl" |
621 | 661 |
or return; |
622 |
- my @urls = map { chomp; $self->dec($_) } <$fh>; |
|
662 |
+ my @urls = map { chomp; $self->_dec($_) } <$fh>; |
|
623 | 663 |
close $fh; |
624 | 664 |
|
625 | 665 |
return \@urls; |
... | ... |
@@ -632,7 +672,7 @@ sub projects { |
632 | 672 |
my $dir = "$home/$user"; |
633 | 673 |
|
634 | 674 |
# Repositories |
635 |
- opendir my $dh, $self->enc($dir) |
|
675 |
+ opendir my $dh, $self->_enc($dir) |
|
636 | 676 |
or croak qq/Can't open directory $dir: $!/; |
637 | 677 |
my @reps; |
638 | 678 |
while (my $rep_name = readdir $dh) { |
... | ... |
@@ -731,7 +771,7 @@ sub tags { |
731 | 771 |
# Parse Tags |
732 | 772 |
my @tags; |
733 | 773 |
my $line_num = 1; |
734 |
- while (my $line = $self->dec(scalar <$fh>)) { |
|
774 |
+ while (my $line = $self->_dec(scalar <$fh>)) { |
|
735 | 775 |
|
736 | 776 |
if ($line_num > $offset && $line_num < $offset + $count + 1) { |
737 | 777 |
|
... | ... |
@@ -818,7 +858,7 @@ sub latest_commit_log { |
818 | 858 |
or croak 'Open git-log failed'; |
819 | 859 |
|
820 | 860 |
local $/; |
821 |
- my $commit_log_text = $self->dec(scalar <$fh>); |
|
861 |
+ my $commit_log_text = $self->_dec(scalar <$fh>); |
|
822 | 862 |
|
823 | 863 |
if ($commit_log_text =~ /^([0-9a-zA-Z]+) - (.+) - (.+?) : (.+)/) { |
824 | 864 |
$commit_log->{commit} = $1; |
... | ... |
@@ -861,7 +901,7 @@ sub last_change_commit { |
861 | 901 |
or croak 'Open git-log failed'; |
862 | 902 |
|
863 | 903 |
local $/; |
864 |
- my $commit_log_text = $self->dec(scalar <$fh>); |
|
904 |
+ my $commit_log_text = $self->_dec(scalar <$fh>); |
|
865 | 905 |
|
866 | 906 |
my $commit; |
867 | 907 |
if ($commit_log_text =~ /^([0-9a-zA-Z]+)/) { |
... | ... |
@@ -945,7 +985,7 @@ sub get_commit { |
945 | 985 |
|
946 | 986 |
# Parse commit |
947 | 987 |
local $/ = "\0"; |
948 |
- my $content = $self->dec(scalar <$fh>); |
|
988 |
+ my $content = $self->_dec(scalar <$fh>); |
|
949 | 989 |
my $commit = $self->parse_commit_text($content, 1); |
950 | 990 |
close $fh; |
951 | 991 |
|
... | ... |
@@ -1063,7 +1103,7 @@ sub get_commits { |
1063 | 1103 |
# Prase Commits text |
1064 | 1104 |
local $/ = "\0"; |
1065 | 1105 |
my @commits; |
1066 |
- while (my $line = $self->dec(scalar <$fh>)) { |
|
1106 |
+ while (my $line = $self->_dec(scalar <$fh>)) { |
|
1067 | 1107 |
my $commit = $self->parse_commit_text($line); |
1068 | 1108 |
push @commits, $commit; |
1069 | 1109 |
} |
... | ... |
@@ -1282,6 +1322,9 @@ sub _age_string { |
1282 | 1322 |
} else { |
1283 | 1323 |
$age_str .= ' right now'; |
1284 | 1324 |
} |
1325 |
+ |
|
1326 |
+ $age_str =~ s/^1 /a /; |
|
1327 |
+ |
|
1285 | 1328 |
return $age_str; |
1286 | 1329 |
} |
1287 | 1330 |
|
... | ... |
@@ -1378,7 +1421,7 @@ sub trees { |
1378 | 1421 |
or $self->croak('Open git-ls-tree failed'); |
1379 | 1422 |
{ |
1380 | 1423 |
local $/ = "\0"; |
1381 |
- @entries = map { chomp; $self->dec($_) } <$fh>; |
|
1424 |
+ @entries = map { chomp; $self->_dec($_) } <$fh>; |
|
1382 | 1425 |
} |
1383 | 1426 |
close $fh |
1384 | 1427 |
or $self->croak(404, "Reading tree failed"); |
... | ... |
@@ -1451,7 +1494,7 @@ sub _slurp { |
1451 | 1494 |
# Slurp |
1452 | 1495 |
open my $fh, '<', $file |
1453 | 1496 |
or croak qq/Can't open file "$file": $!/; |
1454 |
- my $content = do { local $/; $self->dec(scalar <$fh>) }; |
|
1497 |
+ my $content = do { local $/; $self->_dec(scalar <$fh>) }; |
|
1455 | 1498 |
close $fh; |
1456 | 1499 |
|
1457 | 1500 |
return $content; |
... | ... |
@@ -20,31 +20,15 @@ |
20 | 20 |
# Authors |
21 | 21 |
my $authors = $git->authors($user, $project, $rev, $file); |
22 | 22 |
|
23 |
- # Blob content |
|
24 |
- my $bid = $git->id_by_path($user, $project, $rev, $file, 'blob') |
|
25 |
- or $api->croak('Cannot find file'); |
|
26 |
- my @cmd = $git->cmd( |
|
27 |
- $user, |
|
28 |
- $project, |
|
29 |
- 'cat-file', |
|
30 |
- 'blob', |
|
31 |
- $bid |
|
32 |
- ); |
|
33 |
- open my $fh, '-|', @cmd |
|
34 |
- or $api->croak(qq/Couldn't cat "$file", "$bid"/); |
|
35 |
- |
|
36 |
- # Blob info |
|
37 |
- my $file_size = $git->blob_size_kb($user, $project, $rev, $file); |
|
38 |
- my $mimetype = $git->blob_mimetype($fh, $file); |
|
23 |
+ # Blob lines |
|
24 |
+ my $lines = $git->blob($user, $project, $rev, $file); |
|
39 | 25 |
|
40 |
- # Parse line |
|
41 |
- my $lines =[]; |
|
42 |
- while (my $line = $git->dec(scalar <$fh>)) { |
|
43 |
- chomp $line; |
|
44 |
- $line = $git->_tab_to_space($line); |
|
45 |
- push @$lines, $line; |
|
46 |
- } |
|
26 |
+ # File size |
|
27 |
+ my $file_size = $git->blob_size_kb($user, $project, $rev, $file); |
|
47 | 28 |
|
29 |
+ # MIME type |
|
30 |
+ my $mimetype = $git->blob_mimetype($user, $project, $rev, $file); |
|
31 |
+ |
|
48 | 32 |
# Variables for included template |
49 | 33 |
stash(id => $rev, project => $project); |
50 | 34 |
%> |
... | ... |
@@ -17,6 +17,7 @@ |
17 | 17 |
# Blob content |
18 | 18 |
my $bid = $git->id_by_path($user, $project, $rev, $file, 'blob') |
19 | 19 |
or $api->croak('Cannot find file'); |
20 |
+ |
|
20 | 21 |
my @cmd = $git->cmd( |
21 | 22 |
$user, |
22 | 23 |
$project, |
... | ... |
@@ -33,7 +34,7 @@ |
33 | 34 |
my $lines =[]; |
34 | 35 |
|
35 | 36 |
# Content type |
36 |
- my $type = $git->blob_contenttype($fh, $file); |
|
37 |
+ my $type = $git->blob_contenttype($user, $project, $rev, $file); |
|
37 | 38 |
|
38 | 39 |
# Convert text/* content type to text/plain |
39 | 40 |
if ($self->config('prevent_xss') && |
... | ... |
@@ -60,7 +61,8 @@ |
60 | 61 |
# Render |
61 | 62 |
$self->res->headers->content_disposition($content_disposition); |
62 | 63 |
$self->res->headers->content_type($type); |
63 |
- |
|
64 |
+ use D;d $type; |
|
65 |
+ |
|
64 | 66 |
$self->render(text => $content); |
65 | 67 |
|
66 | 68 |
return $self->res->body; |
... | ... |
@@ -72,7 +72,6 @@ |
72 | 72 |
</div> |
73 | 73 |
</div> |
74 | 74 |
% } |
75 |
- % use D;d [$page_count, $tags_count]; |
|
76 | 75 |
% if ($tags_count > $page_count) { |
77 | 76 |
<ul class="pager" style="text-align:left"> |
78 | 77 |
% if ($page == 1) { |