Showing 2 changed files with 37 additions and 3 deletions
+23
lib/Gitprep/Git.pm
... ...
@@ -83,6 +83,29 @@ sub cmd {
83 83
   return ($self->bin, "--git-dir=$project");
84 84
 }
85 85
 
86
+sub commits_number {
87
+  my ($self, $rep, $ref) = @_;
88
+  
89
+  # Command "git diff-tree"
90
+  my @cmd = ($self->cmd($rep), 'shortlog', '-s', $ref);
91
+  open my $fh, "-|", @cmd
92
+    or croak 500, "Open git-shortlog failed";
93
+  my @commits_infos = map { chomp; $self->dec($_) } <$fh>;
94
+  close $fh or croak 'Reading git-shortlog failed';
95
+  
96
+  use Data::Dumper;
97
+  warn Dumper \@commits_infos;
98
+  
99
+  my $commits_num = 0;
100
+  for my $commits_info (@commits_infos) {
101
+    if ($commits_info =~ /^ *([0-9]+)/) {
102
+      $commits_num += $1;
103
+    }
104
+  }
105
+  
106
+  return $commits_num;
107
+}
108
+
86 109
 sub file_type {
87 110
   my ($self, $mode) = @_;
88 111
   
+14 -3
templates/main/repository.html.ep
... ...
@@ -1,6 +1,8 @@
1 1
 <%
2 2
   use Gitprep::API;
3 3
   
4
+  my $ref = 'master';
5
+  
4 6
   # Parameters
5 7
   my $user = param('user');
6 8
   my $repository = param('repository');
... ...
@@ -40,8 +42,10 @@
40 42
   open my $fh, '-|', $git->cmd($rep), 'ls-tree', '-z',
41 43
       ($show_sizes ? '-l' : ()), $tid
42 44
     or $api->croak('Open git-ls-tree failed');
43
-  local $/ = "\0";
44
-  @entries = map { chomp; $git->dec($_) } <$fh>;
45
+  {
46
+    local $/ = "\0";
47
+    @entries = map { chomp; $git->dec($_) } <$fh>;
48
+  }
45 49
   close $fh
46 50
     or $api->croak(404, "Reading tree failed");
47 51
   
... ...
@@ -58,6 +62,9 @@
58 62
   
59 63
   # Repository description
60 64
   my $desc = $git->repository_description($rep);
65
+  
66
+  # Commits number
67
+  my $commits_number = $git->commits_number($rep, $ref);
61 68
 %>
62 69
 
63 70
 % layout 'new_common';
... ...
@@ -294,7 +301,11 @@
294 301
       <div class="commit_number_left">
295 302
         <a href="<%= url_for %>"><%= $repository %></a>
296 303
       </div>
297
-      <div class="commit_number_right">Commit number</div>
304
+      <div class="commit_number_right">
305
+        <a href="<%= url_for("/$user/$repository/commits/master") %>">
306
+          <%= $commits_number %> commits
307
+        </a>
308
+      </div>
298 309
     </div>
299 310
     
300 311
     <div class="tree">