Showing 7 changed files with 94 additions and 97 deletions
+4 -3
lib/Gitprep.pm
... ...
@@ -92,11 +92,12 @@ sub startup {
92 92
   # Projects
93 93
   $r->get('/(*home)/projects')->to('#projects')->name('projects');
94 94
   
95
-  # Download
96
-
95
+  # Archive
96
+  $r->get('/:user/:project/archive/(:rev).tar.gz')->to('#archive', archive_type => 'tar');
97
+  $r->get('/:user/:project/archive/(:rev).zip')->to('#archive', archive_type => 'zip');
98
+  
97 99
   # File cache
98 100
   $git->search_projects;
99
-
100 101
 }
101 102
 
102 103
 1;
+25 -9
lib/Gitprep/Main.pm
... ...
@@ -4,7 +4,7 @@ use File::Basename 'dirname';
4 4
 use Carp 'croak';
5 5
 use Gitprep::API;
6 6
 
7
-sub snapshot {
7
+sub archive {
8 8
   my $self = shift;
9 9
   
10 10
   # API
... ...
@@ -12,12 +12,25 @@ sub snapshot {
12 12
 
13 13
   # Parameter
14 14
   my $user = $self->param('user');
15
-  my $project_ns = $self->param('project');
16
-  my $project = "/$project_ns";
15
+  my $project = $self->param('project');
17 16
   my $root_ns = $api->root_ns($self->config->{root});
18 17
   my $rep_ns = "$root_ns/$user/$project.git";
19 18
   my $rep = "/$rep_ns";
20 19
   my $rev = $self->param('rev');
20
+  my $archive_type = $self->stash('archive_type');
21
+  my $content_type;
22
+  my $format;
23
+  my $ext;
24
+  if ($archive_type eq 'tar') {
25
+    $format = 'tar';
26
+    $ext = 'tar.gz';
27
+    $content_type = 'application/x-tar';
28
+  }
29
+  elsif ($archive_type eq 'zip') {
30
+    $format = 'zip';
31
+    $ext = 'zip';
32
+    $content_type = 'application/zip';
33
+  }
21 34
   
22 35
   # Git
23 36
   my $git = $self->app->git;
... ...
@@ -27,20 +40,22 @@ sub snapshot {
27 40
   if (!$type) { croak 404, 'Object does not exist' }
28 41
   elsif ($type eq 'blob') { croak 400, 'Object is not a tree-ish' }
29 42
   
30
-  my ($name, $prefix) = $git->snapshot_name($rep, $rev);
31
-  my $file = "$name.tar.gz";
43
+  my $name = "$project-$rev";
44
+  my $file = "$name.$ext";
45
+  
32 46
   my $cmd = $self->_quote_command(
33
-    $git->cmd($rep), 'archive', "--format=tar", "--prefix=$prefix/", $rev
47
+    $git->cmd($rep), 'archive', "--format=$format", "--prefix=$name/", $rev
34 48
   );
35
-  $cmd .= ' | ' . $self->_quote_command('gzip', '-n');
36
-
49
+  if ($archive_type eq 'tar') {
50
+    $cmd .= ' | ' . $self->_quote_command('gzip', '-n');
51
+  }
37 52
   $file =~ s/(["\\])/\\$1/g;
38 53
 
39 54
   open my $fh, '-|', $cmd
40 55
     or croak 'Execute git-archive failed';
41 56
   
42 57
   # Write chunk
43
-  $self->res->headers->content_type('application/x-tar');
58
+  $self->res->headers->content_type($content_type);
44 59
   $self->res->headers->content_disposition(qq/attachment; filename="$file"/);
45 60
   my $cb;
46 61
   $cb = sub {
... ...
@@ -50,6 +65,7 @@ sub snapshot {
50 65
     unless ($length) {
51 66
       close $fh;
52 67
       undef $cb;
68
+      $c->finish;
53 69
       return;
54 70
     }
55 71
     $c->write_chunk($buffer, $cb);
+54 -18
templates/include/code_menu.html.ep
... ...
@@ -1,5 +1,7 @@
1 1
 <%
2
-  my $tags_count = stash('tags_count');
2
+  my $tags_count = stash('tags_count') || 0;
3
+  my $branches_count = stash('branches_count') || 0;
4
+  my $display = stash('display') || '';
3 5
 %>
4 6
 
5 7
 %= stylesheet begin
... ...
@@ -10,61 +12,95 @@
10 12
     height:30px;
11 13
     overflow:hidden;
12 14
   }
13
-  .code_menu_left {
15
+  .code_menu .cleft {
14 16
     width:700px;
15 17
     float:left;
16 18
     overflow:hidden;
17 19
   }
18
-  .code_menu_current_ref {
20
+  .code_menu .ccurrent_rev {
19 21
     float:left;
20 22
     padding:5px 10px 10px 10px;
21 23
   }
22
-  .code_menu_current_ref_button {
24
+  .code_menu .ccurrent_rev_button {
23 25
     border:1px solid #E5E5E5;
24 26
   }
25
-  .code_menu_left li {
27
+  .code_menu .cleft li {
26 28
     float:left;
27 29
     padding:5px 10px;
28 30
   }
29
-  .code_menu_right {
31
+  .code_menu .cright {
30 32
     text-align:right;
31 33
     overflow:hidden;
32 34
     height:27px;
33 35
   }
34
-  .code_menu_right li {
36
+  .code_menu .cright li {
35 37
     float:right;
36 38
     padding:5px 10px;
37 39
     height:27px;
38 40
   }
39
-  .code_menu_under {
41
+  .code_menu .cunder {
40 42
     border-top:1px solid #E5E5E5;
41 43
     margin-top:-1px;
42 44
   }
43 45
   .code_menu a {
44 46
     color:#666;
45 47
   }
48
+  .code_menu .ccount {
49
+    display:inline-block;
50
+    font-weight:normal;
51
+    border:1px solid #CCC;
52
+    background-color:#EEE;
53
+    padding:2px;
54
+    padding-left:5px;
55
+    padding-right:5px;
56
+    border-radius:9px;
57
+    font-size:75%;
58
+  }
59
+  
60
+  % if ($display) {
61
+    /* Code menu */
62
+    .code_menu .c<%= $display %> {
63
+      border:1px solid #E5E5E5;
64
+      border-bottom:none;
65
+      background-color:white;
66
+      font-weight:bold;
67
+    }
68
+    .code_menu .c<%= $display %> a {
69
+      color:#333
70
+    }
71
+  % }
72
+
46 73
 % end
47 74
 
48 75
 <div class="code_menu">
49
-  <ul class="code_menu_left">
76
+  <ul class="cleft">
50 77
     
51 78
     % if (defined(my $rev = stash('rev'))) {
52
-      <li class="code_menu_current_ref">
53
-        <div class="code_menu_current_ref_button">
79
+      <li class="ccurrent_rev">
80
+        <div class="ccurrent_rev_button">
54 81
           branch <b><%= $rev %></b>
55 82
         </div>
56 83
       </li>
57 84
     % }
58
-    <li class="code_menu_files"><a href="<%= url_for("/$user/$project") %>">Files</a></li>
59
-    <li class="code_menu_commits"><a href="<%= url_for("/$user/$project/commits/master") %>">Commits</a></li>
60
-    <li class="code_menu_branches"><a href="<%= url_for("/$user/$project/branches") %>">Branches</a></li>
85
+    <li class="cfiles"><a href="<%= url_for("/$user/$project") %>">Files</a></li>
86
+    <li class="ccommits"><a href="<%= url_for("/$user/$project/commits/master") %>">Commits</a>
87
+      </li>
88
+    <li class="cbranches">
89
+      <a href="<%= url_for("/$user/$project/branches") %>">Branches</a>
90
+      % if ($display eq 'branches') {
91
+        <span class="ccount"><%= $branches_count %></span>
92
+      % }
93
+    </li>
61 94
   </ul>
62
-  <ul class="code_menu_right">
63
-    <li class="code_menu_tags">
95
+  <ul class="cright">
96
+    <li class="ctags">
64 97
       <a href="<%= url_for("/$user/$project/tags") %>">
65
-        Tags <span><%= defined $tags_count ? " $tags_count" : '' %></span>
98
+        Tags
99
+        % if ($display eq 'tags') {
100
+          <span class="ccount"><%= $tags_count %></span>
101
+        % }
66 102
       </a>
67 103
      </li>
68 104
   </ul>
69
-  <div class="code_menu_under"></div>
105
+  <div class="cunder"></div>
70 106
 </div>
+1 -15
templates/main/branches.html.ep
... ...
@@ -90,21 +90,7 @@
90 90
 
91 91
   <div class="main_panel">
92 92
     %= include '/include/sub_header';
93
-    
94
-    %= include '/include/code_menu';
95
-    %= stylesheet begin
96
-      /* Code menu */
97
-      .code_menu_branches {
98
-        border:1px solid #E5E5E5;
99
-        border-bottom:none;
100
-        background-color:white;
101
-        font-weight:bold;
102
-      }
103
-      .code_menu_branches a {
104
-        color:#333
105
-      }
106
-      
107
-    % end
93
+    %= include '/include/code_menu', display => 'branches', branches_count => scalar @$branches;
108 94
     
109 95
     <h2>Branches</h2>
110 96
     
+1 -13
templates/main/commits.html.ep
... ...
@@ -133,19 +133,7 @@
133 133
   <div class="main_panel">
134 134
     %= include '/include/sub_header';
135 135
     
136
-    %= include '/include/code_menu';
137
-    %= stylesheet begin
138
-    /* Code menu */
139
-    .code_menu_commits {
140
-      border:1px solid #E5E5E5;
141
-      border-bottom:none;
142
-      background-color:white;
143
-      font-weight:bold;
144
-    }
145
-    .code_menu_commits a {
146
-      color:#333
147
-    }
148
-    % end
136
+    %= include '/include/code_menu', display => 'commits';
149 137
         
150 138
     <div class="commit_history">
151 139
       % if (defined $blob) {
+3 -15
templates/main/project.html.ep
... ...
@@ -207,7 +207,7 @@
207 207
     <div class="description"><%= $desc %></div>
208 208
     
209 209
     <div class="git_url">
210
-      <div class="git_url_zip"><a href="<%= url_for('/archive/master.zip') %>"><s>ZIP</s></a></div>
210
+      <div class="git_url_zip"><a href="<%= url_for("/$user/$project/archive/master.zip") %>">ZIP</a></div>
211 211
       <div class="git_url_http">HTTP</div>
212 212
       <div class="git_url_ssh">SSH</div>
213 213
       <!-- <div class="git_url_git">Git Read-Only</div> -->
... ...
@@ -215,20 +215,8 @@
215 215
       <div class="git_url_access">Read-only access</div>
216 216
     </div>
217 217
     
218
-    %= include '/include/code_menu';
219
-    %= stylesheet begin
220
-      /* Code menu */
221
-      .code_menu_files {
222
-        border:1px solid #E5E5E5;
223
-        border-bottom:none;
224
-        background-color:white;
225
-        font-weight:bold;
226
-      }
227
-      .code_menu_files a {
228
-        color:#333
229
-      }
230
-    % end
231
-        
218
+    %= include '/include/code_menu', display => 'files';
219
+    
232 220
     <div class="commit_number">
233 221
       <div class="commit_number_left">
234 222
         <a href="<%= url_for %>"><%= $project %></a>
+6 -24
templates/main/tags.html.ep
... ...
@@ -2,24 +2,20 @@
2 2
   # API
3 3
   my $api = Gitprep::API->new($self);
4 4
 
5
+  # Parameters
5 6
   my $user = param('user');
6 7
   my $project = param('project');
7
-
8 8
   my $root_ns = $api->root_ns(config->{root});
9
-  
10
-  # Parameters
11
-  my $project_ns = "$root_ns/$user/$project.git";
12
-  my $project = "/$project_ns";
13
-  my $home_ns = $api->dirname($project_ns);
14
-  my $home = "/$home_ns";
9
+  my $rep_ns = "$root_ns/$user/$project.git";
10
+  my $rep = "/$rep_ns";
15 11
   
16 12
   # Git
17 13
   my $git = $self->app->git;
18 14
   
19 15
   # Ref names
20
-  my $tags  = $git->tags($project);
16
+  my $tags  = $git->tags($rep);
21 17
   for my $tag (@$tags) {
22
-    $tag->{commit} = $git->parse_commit($project, $tag->{name});
18
+    $tag->{commit} = $git->parse_commit($rep, $tag->{name});
23 19
   }
24 20
 %>
25 21
 
... ...
@@ -84,21 +80,7 @@
84 80
 
85 81
   <div class="main_panel">
86 82
     %= include '/include/sub_header';
87
-    
88
-    %= include '/include/code_menu', tags_count => scalar @$tags;
89
-    %= stylesheet begin
90
-      /* Code menu */
91
-      .code_menu_tags {
92
-        border:1px solid #E5E5E5;
93
-        border-bottom:none;
94
-        background-color:white;
95
-        font-weight:bold;
96
-      }
97
-      .code_menu_tags a {
98
-        color:#333
99
-      }
100
-      
101
-    % end
83
+    %= include '/include/code_menu', display => 'tags', tags_count => scalar @$tags;
102 84
     
103 85
     <div class="tags">
104 86
       % for (my $i = 0; $i < @$tags; $i++) {