... | ... |
@@ -197,8 +197,8 @@ sub startup { |
197 | 197 |
$r->get('/raw/:rev/(*file)', {file => undef})->to('controller#raw'); |
198 | 198 |
|
199 | 199 |
# Archive |
200 |
- $r->get('/archive/(#rev).tar.gz')->name('archive')->to(archive_type => 'tar'); |
|
201 |
- $r->get('/archive/(#rev).zip')->name('archive')->to(archive_type => 'zip'); |
|
200 |
+ $r->get('/archive/(:rev).(tar.gz')->name('archive')->to(archive_type => 'tar'); |
|
201 |
+ $r->get('/archive/(:rev).zip')->name('archive')->to(archive_type => 'zip'); |
|
202 | 202 |
|
203 | 203 |
# Compare |
204 | 204 |
$r->get('/compare/(#rev1)...(#rev2)')->name('compare'); |
... | ... |
@@ -504,37 +504,66 @@ sub difftree { |
504 | 504 |
return $diffs; |
505 | 505 |
} |
506 | 506 |
|
507 |
-sub no_merged_branches { |
|
508 |
- my ($self, $user, $project) = @_; |
|
509 |
- |
|
510 |
- return $self->branches($user, $project, {no_merged => 1}); |
|
511 |
-} |
|
512 |
- |
|
513 | 507 |
sub branches { |
514 | 508 |
my ($self, $user, $project, $opts) = @_; |
515 | 509 |
|
516 |
- # Command "git branch --no-merged" |
|
510 |
+ # No merged branches |
|
511 |
+ my $no_merged_branches_h = {}; |
|
512 |
+ { |
|
513 |
+ my @cmd = $self->cmd($user, $project, 'branch'); |
|
514 |
+ push @cmd, , '--no-merged'; |
|
515 |
+ open my $fh, '-|', @cmd or return; |
|
516 |
+ |
|
517 |
+ while (my $branch_name = $self->_dec(scalar <$fh>)) { |
|
518 |
+ $branch_name =~ s/^\*//; |
|
519 |
+ $branch_name =~ s/^\s*//; |
|
520 |
+ $branch_name =~ s/\s*$//; |
|
521 |
+ $no_merged_branches_h->{$branch_name} = 1; |
|
522 |
+ } |
|
523 |
+ } |
|
524 |
+ |
|
525 |
+ # All branches |
|
517 | 526 |
my @cmd = $self->cmd($user, $project, 'branch'); |
518 |
- push @cmd, , '--no-merged' if $opts->{no_merged}; |
|
519 | 527 |
open my $fh, '-|', @cmd or return; |
520 |
- |
|
521 |
- my @branch_names |
|
522 |
- = map { s/^\*//; s/^\s*//; s/\s*$//; $self->_dec($_) } <$fh>; |
|
523 |
- close $fh or croak qq/Can't open "git branch"/; |
|
524 |
- |
|
525 |
- # Branches |
|
526 | 528 |
my $branches = []; |
527 |
- for my $branch_name (@branch_names) { |
|
529 |
+ while (my $branch_name = $self->_dec(scalar <$fh>)) { |
|
530 |
+ $branch_name =~ s/^\*//; |
|
531 |
+ $branch_name =~ s/^\s*//; |
|
532 |
+ $branch_name =~ s/\s*$//; |
|
533 |
+ |
|
528 | 534 |
my $branch = {}; |
529 | 535 |
$branch->{name} = $branch_name; |
530 | 536 |
my $commit = $self->get_commit($user, $project, $branch_name); |
531 | 537 |
$branch->{commit} = $commit; |
538 |
+ $branch->{no_merged} = 1 if $no_merged_branches_h->{$branch_name}; |
|
532 | 539 |
push @$branches, $branch; |
533 | 540 |
} |
534 | 541 |
|
535 | 542 |
return $branches; |
536 | 543 |
} |
537 | 544 |
|
545 |
+sub branches_count { |
|
546 |
+ my ($self, $user, $project) = @_; |
|
547 |
+ |
|
548 |
+ my @cmd = $self->cmd($user, $project, 'branch'); |
|
549 |
+ open my $fh, '-|', @cmd or return; |
|
550 |
+ my @branches = <$fh>; |
|
551 |
+ my $branches_count = @branches; |
|
552 |
+ |
|
553 |
+ return $branches_count; |
|
554 |
+} |
|
555 |
+ |
|
556 |
+sub no_merged_branches_count { |
|
557 |
+ my ($self, $user, $project) = @_; |
|
558 |
+ |
|
559 |
+ my @cmd = $self->cmd($user, $project, 'branch', '--no-merged'); |
|
560 |
+ open my $fh, '-|', @cmd or return; |
|
561 |
+ my @branches = <$fh>; |
|
562 |
+ my $branches_count = @branches; |
|
563 |
+ |
|
564 |
+ return $branches_count; |
|
565 |
+} |
|
566 |
+ |
|
538 | 567 |
sub id_by_path { |
539 | 568 |
my ($self, $user, $project, $rev, $path, $type) = @_; |
540 | 569 |
|
... | ... |
@@ -7,6 +7,7 @@ |
7 | 7 |
my $project = param('project'); |
8 | 8 |
my $rev = param('rev'); |
9 | 9 |
my $archive_type = stash('archive_type'); |
10 |
+ |
|
10 | 11 |
my $content_type; |
11 | 12 |
my $format; |
12 | 13 |
my $ext; |
... | ... |
@@ -1,64 +0,0 @@ |
1 |
-<% |
|
2 |
- # API |
|
3 |
- my $api = gitprep_api; |
|
4 |
- |
|
5 |
- # Parameters |
|
6 |
- my $project = param('project'); |
|
7 |
- my $diff = param('diff'); |
|
8 |
- my $file = param('file'); |
|
9 |
- my $from_file = param('from-file'); |
|
10 |
- $from_file = $file unless defined $from_file; |
|
11 |
- my $from_id; |
|
12 |
- my $id; |
|
13 |
- if ($diff =~ /\.\./) { ($from_id, $id) = $diff =~ /(.+)\.\.(.+)/ } |
|
14 |
- else { $id = $diff } |
|
15 |
- |
|
16 |
- # Git |
|
17 |
- my $git = $self->app->git; |
|
18 |
- |
|
19 |
- # Get blob diff |
|
20 |
- my @cmd = $git->cmd( |
|
21 |
- $user, |
|
22 |
- $project, |
|
23 |
- 'diff', |
|
24 |
- '-r', |
|
25 |
- '-M', |
|
26 |
- '-p', |
|
27 |
- $from_id, |
|
28 |
- $id, |
|
29 |
- '--', |
|
30 |
- $from_file, |
|
31 |
- $file |
|
32 |
- ); |
|
33 |
- open my $fh, '-|', @cmd |
|
34 |
- or $api->croak("Open git-diff-tree failed"); |
|
35 |
- |
|
36 |
- # Lines |
|
37 |
- my @lines = map { $git->dec($_) } <$fh>; |
|
38 |
- close $fh; |
|
39 |
- my $lines = $git->parse_blobdiff_lines(\@lines); |
|
40 |
- |
|
41 |
- # Commit |
|
42 |
- my $commit = $git->get_commit($user, $project, $id); |
|
43 |
- |
|
44 |
- # Variables for included templates |
|
45 |
- stash( |
|
46 |
- lines => $lines, |
|
47 |
- from_id => $from_id, |
|
48 |
- from_file => $from_file, |
|
49 |
- id => $id |
|
50 |
- ); |
|
51 |
-%> |
|
52 |
- |
|
53 |
-% layout 'common'; |
|
54 |
- |
|
55 |
- %= include '/include/header', title => 'Blob diff', project => $project; |
|
56 |
- |
|
57 |
- <div class="container"> |
|
58 |
- %= include '/include/project_header'; |
|
59 |
- %= include '/include/code_menu', display => 'files'; |
|
60 |
- %= include '/include/page_path', Path => $file, type => 'blob'; |
|
61 |
- %= include '/include/blobdiff_body'; |
|
62 |
- </div> |
|
63 |
- |
|
64 |
- %= include '/include/footer'; |
... | ... |
@@ -15,10 +15,38 @@ |
15 | 15 |
$default_branch->{commit} = $git->get_commit($user, $project, $default_branch->{name}); |
16 | 16 |
|
17 | 17 |
# No merged branches |
18 |
- my $branches = $git->no_merged_branches($user, $project); |
|
18 |
+ my $branches = $git->branches($user, $project); |
|
19 |
+ my $branches_count = $git->branches_count($user, $project); |
|
20 |
+ my $no_merged_branches_count = $git->no_merged_branches_count($user, $project); |
|
21 |
+ my $merged_branches_count = $branches_count - $no_merged_branches_count - 1; |
|
19 | 22 |
%> |
20 | 23 |
|
21 | 24 |
% layout 'common'; |
25 |
+ |
|
26 |
+ %= javascript begin |
|
27 |
+ $('document').ready(function () { |
|
28 |
+ |
|
29 |
+ // Swich merged branch or not merged branch |
|
30 |
+ var display_no_merged = true; |
|
31 |
+ $('#toggle-branch').on('click', function () { |
|
32 |
+ if (display_no_merged) { |
|
33 |
+ $(this).text('View unmerged branches'); |
|
34 |
+ $('#no-merged-branch-message').hide(); |
|
35 |
+ $('#merged-branch-message').show(); |
|
36 |
+ $('.no-merged-branch').css('display', 'none'); |
|
37 |
+ $('.merged-branch').css('display', 'inline'); |
|
38 |
+ } |
|
39 |
+ else { |
|
40 |
+ $(this).text('View merged branches'); |
|
41 |
+ $('#no-merged-branch-message').show(); |
|
42 |
+ $('#merged-branch-message').hide(); |
|
43 |
+ $('.no-merged-branch').css('display', 'inline'); |
|
44 |
+ $('.merged-branch').css('display', 'none'); |
|
45 |
+ } |
|
46 |
+ display_no_merged = !display_no_merged; |
|
47 |
+ }); |
|
48 |
+ }); |
|
49 |
+ % end |
|
22 | 50 |
|
23 | 51 |
%= include '/include/header'; |
24 | 52 |
|
... | ... |
@@ -29,7 +57,15 @@ |
29 | 57 |
<h3>Branches</h3> |
30 | 58 |
|
31 | 59 |
<div class="muted"> |
32 |
- Showing <%= @$branches %> branches not merged into master |
|
60 |
+ Showing |
|
61 |
+ <span id="no-merged-branch-message"> |
|
62 |
+ <%= $no_merged_branches_count %> branches not merged |
|
63 |
+ </span> |
|
64 |
+ <span style="display:none" id="merged-branch-message"> |
|
65 |
+ <%= $merged_branches_count %> branches merged |
|
66 |
+ </span> |
|
67 |
+ into <%= $default_branch->{name} %>. |
|
68 |
+ <a id="toggle-branch" href="#">View merged branches</a> |
|
33 | 69 |
</div> |
34 | 70 |
<div class="bk-black" style="padding:5px"> |
35 | 71 |
<div class="row"> |
... | ... |
@@ -48,7 +84,7 @@ |
48 | 84 |
</span> |
49 | 85 |
</div> |
50 | 86 |
</div> |
51 |
- <div class="span3 offset1-mini text-right font-white" style="padding-top:10px"> |
|
87 |
+ <div class="text-right font-white" style="padding-top:10px"> |
|
52 | 88 |
Base branch |
53 | 89 |
</div> |
54 | 90 |
</div> |
... | ... |
@@ -57,7 +93,7 @@ |
57 | 93 |
% my $branch = $branches->[$i]; |
58 | 94 |
% my $bname = $branch->{name}; |
59 | 95 |
% next if $bname eq $default_branch->{name}; |
60 |
- <div class="border-bottom-gray" style="padding:5px"> |
|
96 |
+ <div class="<%= $branch->{no_merged} ? 'no-merged-branch' : 'merged-branch' %> border-bottom-gray" style="padding:5px"> |
|
61 | 97 |
<div class="row"> |
62 | 98 |
<div class="span8"> |
63 | 99 |
<div> |
... | ... |
@@ -99,13 +99,13 @@ |
99 | 99 |
% for my $date (reverse sort keys %$commits_date) { |
100 | 100 |
% my $commits = $commits_date->{$date}; |
101 | 101 |
|
102 |
- <div class="bk-gray-light border-gray padding5" style="border-bottom:none"> |
|
102 |
+ <div class="bk-gray-light border-gray" style="padding:5px;border-bottom:none"> |
|
103 | 103 |
<%= $date %> |
104 | 104 |
</div> |
105 | 105 |
|
106 | 106 |
<div style="margin-bottom:20px"> |
107 | 107 |
% for my $commit (sort {$b->{author_epoch} <=> $a->{author_epoch}} @$commits) { |
108 |
- <div class="border-gray padding5"> |
|
108 |
+ <div class="border-gray" style="padding:5px"> |
|
109 | 109 |
<div class="row"> |
110 | 110 |
<div class="span2"> |
111 | 111 |
<%= $commit->{author_name} %> |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
my $rev = stash('rev'); |
4 | 4 |
$rev = app->manager->default_branch($user, $project) |
5 | 5 |
unless defined $rev; |
6 |
- my $branches_count = @{app->git->no_merged_branches($user, $project)}; |
|
6 |
+ my $branches_count = app->git->branches_count($user, $project); |
|
7 | 7 |
my $tags_count = app->git->tags_count($user, $project); |
8 | 8 |
%> |
9 | 9 |
|
... | ... |
@@ -2,6 +2,7 @@ |
2 | 2 |
my $api = gitprep_api; |
3 | 3 |
my $logined = $api->logined; |
4 | 4 |
my $user_is_valid = $logined && $user eq session('user'); |
5 |
+ my $default_branch = app->manager->default_branch($user, $project); |
|
5 | 6 |
|
6 | 7 |
my $git = app->git; |
7 | 8 |
|
... | ... |
@@ -212,7 +213,7 @@ |
212 | 213 |
Default Branch |
213 | 214 |
% my $branches = $git->branches($user, $project); |
214 | 215 |
% my $branch_names = [map { $_->{name} } @$branches]; |
215 |
- % push @$branch_names, 'master' unless @$branch_names; |
|
216 |
+ % push @$branch_names, $default_branch->{name} unless @$branch_names; |
|
216 | 217 |
%= select_field 'default_branch' => $branch_names, style => 'margin-top:5px'; |
217 | 218 |
</div> |
218 | 219 |
</div> |
... | ... |
@@ -122,7 +122,7 @@ |
122 | 122 |
</h3> |
123 | 123 |
% if ($state eq 'display') { |
124 | 124 |
<div class="border-gray radius" style="padding:0 3px;margin-bottom:10px;"> |
125 |
- <a class="btn" style="padding:3px 6px;margin-left:10px" href="<%= url_for("/$user/$project/archive/master.zip") %>"> |
|
125 |
+ <a class="btn" style="padding:3px 6px;margin-left:10px" href="<%= url_for("/$user/$project/archive/$rev.zip") %>"> |
|
126 | 126 |
<i class="icon-arrow-down"></i>ZIP |
127 | 127 |
</a> |
128 | 128 |
<div class="input-append" style="margin-top:10px"> |
... | ... |
@@ -144,7 +144,7 @@ |
144 | 144 |
<a href="<%= url_for %>"><%= $project %></a> |
145 | 145 |
</div> |
146 | 146 |
<div class="text-right"> |
147 |
- <a href="<%= url_for("/$user/$project/commits/master") %>"> |
|
147 |
+ <a href="<%= url_for("/$user/$project/commits/$rev") %>"> |
|
148 | 148 |
<%= $commits_number %> commits |
149 | 149 |
</a> |
150 | 150 |
</div> |
... | ... |
@@ -169,3 +169,14 @@ note 'raw page'; |
169 | 169 |
my $content = decode('UTF-8', $content_binary); |
170 | 170 |
like($content, qr/あああ/); |
171 | 171 |
} |
172 |
+ |
|
173 |
+note 'Aarchive'; |
|
174 |
+{ |
|
175 |
+ # Archive zip |
|
176 |
+ $t->get_ok("/$user/$project/archive/t1.zip"); |
|
177 |
+ $t->content_type_is('application/zip'); |
|
178 |
+ |
|
179 |
+ # Archice tar.gz |
|
180 |
+ $t->get_ok("/$user/$project/archive/t1.tar.gz"); |
|
181 |
+ $t->content_type_is('application/x-tar'); |
|
182 |
+} |