remove [basic]encoding_suspects option and move this...
...feature to project settings...
... | ... |
@@ -4,7 +4,10 @@ |
4 | 4 |
- add Mojolicious::Plugin::DBViewer to cpanfile |
5 | 5 |
- X-Forwarded-HTTPS header is DEPRECATED! use X-Forwarded-Proto header instead. |
6 | 6 |
- remove [basic]show_ignore_space_change_link option. |
7 |
- and enable this feature on in project settings page. |
|
7 |
+ and move this feature to project settings page. |
|
8 |
+ - remove [basic]encoding_suspects option |
|
9 |
+ and move this feature to project settings page. |
|
10 |
+ |
|
8 | 11 |
1.12 (7 Feb 2016) |
9 | 12 |
- Catch up latest Github design. |
10 | 13 |
- Fix bug that relative image path in README.md and blob html. |
... | ... |
@@ -452,14 +452,27 @@ If you install perl 5.10.1+ by perlbrew, you can install latest GitPrep. |
452 | 452 |
|
453 | 453 |
**2. remove [basic]show_ignore_space_change_link option** |
454 | 454 |
|
455 |
+remove [basic]show_ignore_space_change_link option. |
|
456 |
+and move this feature to project settings page. |
|
457 |
+ |
|
458 |
+ # Go to settings page in your project |
|
459 |
+ /kimoto/gitprep/settings |
|
460 |
+ |
|
461 |
+**2. remove [basic]show_ignore_space_change_link option** |
|
462 |
+ |
|
455 | 463 |
remove [basic]show_ignore_space_change_link option. |
456 | 464 |
but enable this feature on in project settings page. |
457 | 465 |
|
458 | 466 |
# Go to settings page in your project |
459 | 467 |
/kimoto/gitprep/settings |
460 |
- |
|
461 |
- # And see the following section |
|
462 |
- Ignore space change in diff |
|
468 |
+ |
|
469 |
+**3. remove [basic]encoding_suspects option** |
|
470 |
+ |
|
471 |
+remove [basic]encoding_suspects option |
|
472 |
+and move this feature to project settings page. |
|
473 |
+ |
|
474 |
+ # Go to settings page in your project |
|
475 |
+ /kimoto/gitprep/settings |
|
463 | 476 |
|
464 | 477 |
## For Developer |
465 | 478 |
|
... | ... |
@@ -29,11 +29,6 @@ |
29 | 29 |
;;; default is "$ENV{HOME}/.ssh/authorized_keys" |
30 | 30 |
; authorized_keys_file=/home/gitprep/.ssh/authorized_keys |
31 | 31 |
|
32 |
-;;; Suspects encoding list for source code character encoding (default:UTF-8) |
|
33 |
-;;; set comma separated encoding list if your source code is different from UTF-8. |
|
34 |
-;;; encoding name follow Perl encoding API. |
|
35 |
-;encoding_suspects=cp932,UTF-8 |
|
36 |
- |
|
37 | 32 |
[admin] |
38 | 33 |
;;; If you forget admin password, |
39 | 34 |
;;; set this value to 1 and access /reset-password page. |
... | ... |
@@ -58,14 +58,6 @@ sub startup { |
58 | 58 |
} |
59 | 59 |
$git->bin($git_bin); |
60 | 60 |
|
61 |
- # Encoding suspects list for Git |
|
62 |
- my $encoding_suspects_str = $conf->{basic}{encoding_suspects}; |
|
63 |
- my @encoding_suspects; |
|
64 |
- if ($encoding_suspects_str) { |
|
65 |
- @encoding_suspects = split /,/, $encoding_suspects_str; |
|
66 |
- } |
|
67 |
- $git->encoding_suspects(\@encoding_suspects); |
|
68 |
- |
|
69 | 61 |
# Repository Manager |
70 | 62 |
my $manager = Gitprep::Manager->new; |
71 | 63 |
$manager->app($self); |
... | ... |
@@ -15,7 +15,6 @@ use Gitprep::Util; |
15 | 15 |
# Attributes |
16 | 16 |
has 'bin'; |
17 | 17 |
has default_encoding => 'UTF-8'; |
18 |
-has 'encoding_suspects'; |
|
19 | 18 |
has 'rep_home'; |
20 | 19 |
has text_exts => sub { ['txt'] }; |
21 | 20 |
has 'time_zone_second'; |
... | ... |
@@ -191,8 +190,10 @@ sub blame { |
191 | 190 |
my $max_author_time; |
192 | 191 |
my $min_author_time; |
193 | 192 |
my @lines = <$fh>; |
193 |
+ |
|
194 |
+ my $enc = $self->decide_encoding($user, $project, \@lines); |
|
194 | 195 |
for my $line (@lines) { |
195 |
- $line = $self->_dec_guess($line); |
|
196 |
+ $line = decode($enc, $line); |
|
196 | 197 |
chomp $line; |
197 | 198 |
|
198 | 199 |
if ($blame_line) { |
... | ... |
@@ -283,8 +284,9 @@ sub blob { |
283 | 284 |
# Format lines |
284 | 285 |
my @lines = <$fh>; |
285 | 286 |
my @new_lines; |
287 |
+ my $enc = $self->decide_encoding($user, $project, \@lines); |
|
286 | 288 |
for my $line (@lines) { |
287 |
- $line = $self->_dec_guess($line); |
|
289 |
+ $line = decode($enc, $line); |
|
288 | 290 |
chomp $line; |
289 | 291 |
push @new_lines, $line; |
290 | 292 |
} |
... | ... |
@@ -318,9 +320,10 @@ sub blob_diffs { |
318 | 320 |
open my $fh, '-|', @cmd |
319 | 321 |
or croak('Open self-diff-tree failed'); |
320 | 322 |
my @diff_tree; |
321 |
- my @diff_treelines = <$fh>; |
|
322 |
- for my $line (@diff_treelines) { |
|
323 |
- $line = $self->_dec_guess($line); |
|
323 |
+ my @diff_tree_lines = <$fh>; |
|
324 |
+ my $diff_tree_enc = $self->decide_encoding($user, $project, \@diff_tree_lines); |
|
325 |
+ for my $line (@diff_tree_lines) { |
|
326 |
+ $line = decode($diff_tree_enc, $line); |
|
324 | 327 |
chomp $line; |
325 | 328 |
push @diff_tree, $line if $line =~ /^:/; |
326 | 329 |
last if $line =~ /^\n/; |
... | ... |
@@ -355,7 +358,8 @@ sub blob_diffs { |
355 | 358 |
open my $fh, '-|', @cmd |
356 | 359 |
or croak('Open self-diff-tree failed'); |
357 | 360 |
my @lines = <$fh>; |
358 |
- @lines = map { $self->_dec_guess($_) } @lines; |
|
361 |
+ my $enc = $self->decide_encoding($user, $project, \@lines); |
|
362 |
+ @lines = map { decode($enc, $_) } @lines; |
|
359 | 363 |
close $fh; |
360 | 364 |
my ($lines, $diff_info) = $self->parse_blob_diff_lines(\@lines); |
361 | 365 |
my $blob_diff = { |
... | ... |
@@ -1733,28 +1737,43 @@ sub _chop_str { |
1733 | 1737 |
} |
1734 | 1738 |
} |
1735 | 1739 |
|
1736 |
-sub _dec_guess { |
|
1737 |
- my ($self, $str) = @_; |
|
1740 |
+sub decide_encoding { |
|
1741 |
+ my ($self, $user, $project, $lines) = @_; |
|
1742 |
+ |
|
1743 |
+ my $guess_encoding_str = $self->app->dbi->model('project')->select( |
|
1744 |
+ 'guess_encoding', |
|
1745 |
+ where => {user_id => $user, name => $project} |
|
1746 |
+ )->value; |
|
1738 | 1747 |
|
1739 |
- my $encoding_suspects = $self->encoding_suspects; |
|
1748 |
+ my @guess_encodings; |
|
1749 |
+ if (length $guess_encoding_str) { |
|
1750 |
+ @guess_encodings = split(/\s*,\s*/, $guess_encoding_str); |
|
1751 |
+ } |
|
1740 | 1752 |
|
1741 |
- my $enc; |
|
1742 |
- if (@$encoding_suspects) { |
|
1743 |
- my $ret = Encode::Guess->guess($str, @$encoding_suspects); |
|
1753 |
+ my $encoding; |
|
1754 |
+ if (@guess_encodings) { |
|
1755 |
+ my @new_lines; |
|
1756 |
+ for (my $i = 0; $i < 100; $i++) { |
|
1757 |
+ last unless defined $lines->[$i]; |
|
1758 |
+ push @new_lines, $lines->[$i]; |
|
1759 |
+ } |
|
1760 |
+ |
|
1761 |
+ my $str = join('', @new_lines); |
|
1762 |
+ |
|
1763 |
+ my $ret = Encode::Guess->guess($str, @guess_encodings); |
|
1764 |
+ |
|
1744 | 1765 |
if (ref $ret) { |
1745 |
- $enc = $ret->name; |
|
1766 |
+ $encoding = $ret->name; |
|
1746 | 1767 |
} |
1747 | 1768 |
else { |
1748 |
- $enc = $self->default_encoding |
|
1769 |
+ $encoding = $self->default_encoding |
|
1749 | 1770 |
} |
1750 | 1771 |
} |
1751 | 1772 |
else { |
1752 |
- $enc = $self->default_encoding; |
|
1773 |
+ $encoding = $self->default_encoding; |
|
1753 | 1774 |
} |
1754 | 1775 |
|
1755 |
- $str = decode($enc, $str); |
|
1756 |
- |
|
1757 |
- return $str; |
|
1776 |
+ return $encoding; |
|
1758 | 1777 |
} |
1759 | 1778 |
|
1760 | 1779 |
sub _dec { |
... | ... |
@@ -434,12 +434,3 @@ note 'Markdown normal file'; |
434 | 434 |
$t->get_ok("/$user/$project/blob/12e44f2e4ecf55c5d3a307889829b47c05e216d3/dir/markdown.md"); |
435 | 435 |
$t->content_like(qr#<h1 .*?>Head</h1>#); |
436 | 436 |
} |
437 |
- |
|
438 |
-note 'encoding_suspects option'; |
|
439 |
-{ |
|
440 |
- my $app = Gitprep->new; |
|
441 |
- $app->git->encoding_suspects(['EUC-jp', 'UTF-8']); |
|
442 |
- my $t = Test::Mojo->new($app); |
|
443 |
- $t->get_ok("/$user/$project/blob/3cf14ade5e28ee0cd83b9a3b1e1c332aed66df53/euc-jp.txt"); |
|
444 |
- $t->content_like(qr/あああ/); |
|
445 |
-} |