Showing 4 changed files with 103 additions and 48 deletions
+3
gitprep.conf
... ...
@@ -5,6 +5,9 @@
5 5
 ;;; Git command path
6 6
 ;git_bin=/usr/local/bin/git
7 7
 
8
+;;; Tags limit
9
+;tags_limit=1000
10
+
8 11
 [admin]
9 12
 ;;; If you forget admin password,
10 13
 ;;; set this value to 1 and access /reset-password page.
+67 -33
lib/Gitprep/Git.pm
... ...
@@ -686,8 +686,33 @@ sub tag {
686 686
   return;
687 687
 }
688 688
 
689
+sub tags_count {
690
+  my ($self, $user, $project) = @_;
691
+  
692
+  my $limit = 1000;
693
+  
694
+  # Get tags
695
+  my @cmd = $self->cmd(
696
+    $user,
697
+    $project,
698
+    'for-each-ref',
699
+    ($limit ? '--count='.($limit+1) : ()),
700
+    'refs/tags'
701
+  );
702
+  open my $fh, '-|', @cmd or return;
703
+  
704
+  # Tags count
705
+  my @lines = <$fh>;
706
+  
707
+  return scalar @lines;
708
+}
709
+
689 710
 sub tags {
690
-  my ($self, $user, $project, $limit) = @_;
711
+  my ($self, $user, $project, $limit, $count, $offset) = @_;
712
+  
713
+  $limit ||= 1000;
714
+  $count ||= 50;
715
+  $offset ||= 0;
691 716
   
692 717
   # Get tags
693 718
   my @cmd = $self->cmd(
... ...
@@ -702,46 +727,55 @@ sub tags {
702 727
   );
703 728
   open my $fh, '-|', @cmd or return;
704 729
   
730
+  
705 731
   # Parse Tags
706 732
   my @tags;
733
+  my $line_num = 1;
707 734
   while (my $line = $self->dec(scalar <$fh>)) {
708 735
     
709
-    my %tag;
710
-
711
-    chomp $line;
712
-    my ($refinfo, $creatorinfo) = split(/\0/, $line);
713
-    my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
714
-    my ($creator, $epoch, $tz) =
715
-      ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
716
-    $tag{fullname} = $name;
717
-    $name =~ s!^refs/tags/!!;
718
-
719
-    $tag{type} = $type;
720
-    $tag{id} = $id;
721
-    $tag{name} = $name;
722
-    if ($type eq 'tag') {
723
-      $tag{subject} = $title;
724
-      $tag{reftype} = $reftype;
725
-      $tag{refid}   = $refid;
726
-    } else {
727
-      $tag{reftype} = $type;
728
-      $tag{refid}   = $id;
729
-    }
730
-
731
-    if ($type eq 'tag' || $type eq 'commit') {
732
-      $tag{epoch} = $epoch;
733
-      if ($epoch) {
734
-        $tag{age} = $self->_age_string(time - $tag{epoch});
736
+    if ($line_num > $offset && $line_num < $offset + $count + 1) {
737
+    
738
+      my %tag;
739
+
740
+      chomp $line;
741
+      my ($refinfo, $creatorinfo) = split(/\0/, $line);
742
+      my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
743
+      my ($creator, $epoch, $tz) =
744
+        ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
745
+      $tag{fullname} = $name;
746
+      $name =~ s!^refs/tags/!!;
747
+
748
+      $tag{type} = $type;
749
+      $tag{id} = $id;
750
+      $tag{name} = $name;
751
+      if ($type eq 'tag') {
752
+        $tag{subject} = $title;
753
+        $tag{reftype} = $reftype;
754
+        $tag{refid}   = $refid;
735 755
       } else {
736
-        $tag{age} = 'unknown';
756
+        $tag{reftype} = $type;
757
+        $tag{refid}   = $id;
737 758
       }
738
-    }
739
-    
740
-    $tag{comment_short} = $self->_chop_str($tag{subject}, 30, 5)
741
-      if $tag{subject};
742 759
 
743
-    push @tags, \%tag;
760
+      if ($type eq 'tag' || $type eq 'commit') {
761
+        $tag{epoch} = $epoch;
762
+        if ($epoch) {
763
+          $tag{age} = $self->_age_string(time - $tag{epoch});
764
+        } else {
765
+          $tag{age} = 'unknown';
766
+        }
767
+      }
768
+      
769
+      $tag{comment_short} = $self->_chop_str($tag{subject}, 30, 5)
770
+        if $tag{subject};
771
+
772
+      $tag{commit} = $self->get_commit($user, $project, $name);
773
+
774
+      push @tags, \%tag;
775
+    }
776
+    $line_num++;
744 777
   }
778
+  
745 779
   close $fh;
746 780
 
747 781
   return \@tags;
+4 -6
templates/include/code_menu.html.ep
... ...
@@ -1,12 +1,10 @@
1 1
 <%
2
-  my $tags_count = stash('tags_count') || 0;
3
-  my $branches_count = stash('branches_count') || 0;
4 2
   my $display = stash('display') || '';
5 3
   my $rev = stash('rev');
6 4
   $rev = app->manager->default_branch($user, $project)
7 5
     unless defined $rev;
8
-  my $no_merged_branch = app->git->no_merged_branches($user, $project);
9
-  my $tags = app->git->tags($user, $project);
6
+  my $branches_count = @{app->git->no_merged_branches($user, $project)};
7
+  my $tags_count = app->git->tags_count($user, $project);
10 8
 %>
11 9
 
12 10
 <ul class="nav nav-tabs" style="margin-bottom:20px">
... ...
@@ -38,13 +36,13 @@
38 36
   <li class="<%= $display eq 'branches' ? 'active' : '' %>">
39 37
     <a href="<%= url_for("/$user/$project/branches") %>">
40 38
       Branches
41
-      <span class="badge"><%= @$no_merged_branch || 0 %></span>
39
+      <span class="badge"><%= $branches_count %></span>
42 40
     </a>
43 41
   </li>
44 42
   <li class="<%= $display eq 'tags' ? 'active' : '' %>">
45 43
     <a href="<%= url_for("/$user/$project/tags") %>">
46 44
       Tags
47
-      <span class="badge"><%= @$tags || 0 %></span>
45
+      <span class="badge"><%= $tags_count > 999 ? '999+' : $tags_count %></span>
48 46
     </a>
49 47
   </li>
50 48
 </ul>
+29 -9
templates/tags.html.ep
... ...
@@ -5,19 +5,21 @@
5 5
   # Parameters
6 6
   my $user = param('user');
7 7
   my $project = param('project');
8
+  my $page = param('page') || 1;
8 9
   
9 10
   # Git
10 11
   my $git = $self->app->git;
11 12
   
12 13
   # Ref names
13
-  my $tags  = $git->tags($user, $project);
14
-  @$tags = sort {
15
-    $b->{commit}{age_string_date} cmp $a->{commit}{age_string_date}
16
-    || $b->{name} cmp $a->{name}
17
-  } @$tags;
18
-  for my $tag (@$tags) {
19
-    $tag->{commit} = $git->get_commit($user, $project, $tag->{name});
20
-  }
14
+  my $limit = app->config->{basic}{tags_limit};
15
+  my $page_count = 10;
16
+  my $tags = $git->tags(
17
+    $user,
18
+    $project,
19
+    $limit,
20
+    $page_count,
21
+    $page_count * ($page - 1)
22
+  );
21 23
 %>
22 24
 
23 25
 % layout 'common';
... ...
@@ -31,7 +33,6 @@
31 33
     <h3 style="font-size:20px">Tags</h3>
32 34
     
33 35
     % if (@$tags) {
34
-      % use D;d $tags;
35 36
       <div style="margin-bottom:30px">
36 37
         % for (my $i = 0; $i < @$tags; $i++) {
37 38
           % my $tag = $tags->[$i];
... ...
@@ -70,6 +71,25 @@
70 71
             </div>
71 72
           </div>
72 73
         % }
74
+
75
+        <ul class="pager" style="text-align:left">
76
+          % if ($page == 1) {
77
+            <li class="disabled">&laquo; Newer</li>
78
+          % } else {
79
+            % my $newer_page = $page - 1;
80
+            <li class="disable">
81
+              <a href="<%= url_for("/$user/$project/tags?page=$newer_page") %>">&laquo; Newer</a>
82
+            </li>
83
+          % }
84
+          % if (@$tags < $page_count) {
85
+            <li class="disabled">Older &raquo;</li>
86
+          % } else {
87
+            % my $older_page = $page + 1;
88
+            <li>
89
+              <a href="<%= url_for("/$user/$project/tags?page=$older_page") %>">Older &raquo;</a>
90
+            </li>
91
+          % }
92
+        </ul>
73 93
       </div>
74 94
     % } else {
75 95
       <div class="well">