Showing 5 changed files with 67 additions and 25 deletions
+9 -4
templates/include/blob_diff_body.html.ep
... ...
@@ -3,11 +3,12 @@
3 3
   my $from_rev = stash('from_rev');
4 4
   my $diff_tree = stash('diff_tree');
5 5
   my $blob_diff = stash('blob_diff');
6
-  my $lines = $blob_diff->{lines};
6
+  my $lines = $blob_diff->{lines} || [];
7 7
   my $file = $blob_diff->{file};
8
+  $file = '' unless defined $file;
8 9
   my $from_file = $blob_diff->{from_file};
9 10
   $from_file = $file unless defined $from_file;
10
-  my $status = $blob_diff->{status};
11
+  my $status = $blob_diff->{status} || '';
11 12
 %>
12 13
 
13 14
   <div style="margin-bottom:20px;">
... ...
@@ -33,7 +34,7 @@
33 34
       </div>
34 35
     </div>
35 36
     <table class="border-gray" style="border-top:none">
36
-      % if ($lines) {
37
+      % if (@$lines) {
37 38
         % for my $line (@$lines) {
38 39
           % my $class = $line->{class};
39 40
           % my $value = $line->{value};
... ...
@@ -87,7 +88,11 @@
87 88
         % }
88 89
       % } else {
89 90
         <div class="border-gray" style="padding:10px;margin-bottom:30px;border-top:none">
90
-          No changes.
91
+          % if ($status eq 'R') {
92
+            File renamed without changes.
93
+          % } else {
94
+            No changes.
95
+          % }
91 96
         </div>
92 97
       % }
93 98
     </table>
+3 -2
templates/include/commit_body.html.ep
... ...
@@ -15,9 +15,11 @@
15 15
     $from_rev,
16 16
     $parents
17 17
   );
18
+
18 19
   my $diff_trees_h = {};
19 20
   for my $diff_tree (@$diff_trees) {
20
-    my $file = $diff_tree->{file};
21
+    my $file = $diff_tree->{to_file};
22
+    $file = $diff_tree->{from_file} unless defined $file;
21 23
     $diff_trees_h->{$file} = $diff_tree if defined $file;
22 24
   }
23 25
   
... ...
@@ -75,7 +77,6 @@
75 77
 % for my $file (sort keys %$diff_trees_h) {
76 78
   <div id="diff-<%= $num %>">
77 79
     % my $blob_diff = $blob_diffs_h->{$file};
78
-    % $blob_diff ||= {status => 'A', file => $file};
79 80
     %= include '/include/blob_diff_body', blob_diff => $blob_diff, diff_tree => $diff_trees_h->{$file};
80 81
   </div>
81 82
   % $num++;
+8 -1
templates/include/diff_status_bar.html.ep
... ...
@@ -5,9 +5,13 @@
5 5
   my $delete_line_count = $diff_tree->{delete_line_count} || 0;
6 6
   my $diff_line_count = $add_line_count + $delete_line_count;
7 7
   my $diff_count_text;
8
-  if ($diff_tree->{status} eq 'A' && $add_line_count == 0) {
8
+  my $status = $diff_tree->{status};
9
+  if ($status eq 'A' && $add_line_count == 0) {
9 10
     $diff_count_text = 'Empty file added';
10 11
   }
12
+  elsif ($diff_tree->{status} eq 'R' && $add_line_count == 0 && $delete_line_count == 0) {
13
+    $diff_count_text = 'Empty file renamed';
14
+  }
11 15
   else {
12 16
     $diff_count_text = "$add_line_count additions";
13 17
     $diff_count_text .= " & $delete_line_count deletions" if $delete_line_count > 0;
... ...
@@ -20,6 +24,9 @@
20 24
     $add_block_count = 5;
21 25
     $delete_block_count = 0;
22 26
   }
27
+  elsif ($diff_tree->{status} eq 'R' && $add_line_count == 0 && $delete_line_count == 0) {
28
+    $add_block_count = 5;
29
+  }
23 30
   if ($diff_tree->{status} eq 'D') {
24 31
     $add_block_count = 0;
25 32
     $delete_block_count = 5;
+35 -18
templates/include/diff_tree.html.ep
... ...
@@ -46,6 +46,20 @@
46 46
     height:9px;
47 47
     font-size:11px;
48 48
   }
49
+
50
+  .file-renamed {
51
+    color:#677a85;
52
+    border:2px #677a85 solid;
53
+    margin-left:3px;
54
+    font-weight:bold;
55
+    line-height:0;
56
+    display:table-cell;
57
+    text-align:center;
58
+    vertical-align:middle;
59
+    width:9px;
60
+    height:9px;
61
+    font-size:7px;
62
+  }
49 63
 % end
50 64
   
51 65
 <table style="margin-bottom:10px;width:100%">
... ...
@@ -138,13 +152,13 @@
138 152
         % my $from_mode = $diff_tree->{from_mode};
139 153
         % my $from_mode_str = $diff_tree->{from_mode_str};
140 154
         % my $from_mode_oct = $diff_tree->{from_mode_oct};
141
-        <td style="padding:7px 0; width:12px">
155
+        <td style="padding:7px 5px 7px 0; width:12px">
142 156
           % if ($status eq 'A') {
143
-            <div class="file-add">+</div>
157
+            <div class="file-add" title="added">+</div>
144 158
           % } elsif ($status eq 'D') {
145
-            <div class="file-del">-</div>
159
+            <div class="file-del" title="deleted">-</div>
146 160
           % } elsif ($status eq 'M' || $status eq 'T') {
147
-            <div class="file-modified">●</div>
161
+            <div class="file-modified" title="modified">●</div>
148 162
             % if ($from_mode != $mode) {
149 163
               <span>
150 164
                 [
... ...
@@ -162,27 +176,30 @@
162 176
                 ]
163 177
               </span>
164 178
             % }
179
+          % } elsif ($status eq 'R') {
180
+            <div class="file-renamed" title="renamed">▶</div>
181
+          % } elsif ($status eq 'C') {
182
+            <div class="file-copied" title="copied">→</div>
183
+          % }
184
+        </td>
185
+        <td>
186
+          % if ($status eq 'A' || $status eq 'M' || $status eq 'D') {
187
+            <a style="margin-left:5px" href="#<%= "diff-$num" %>"><%= $file %></a>
188
+          % } elsif ($status eq 'T') {
189
+            
165 190
           % } elsif ($status eq 'R' || $status eq 'C') {
166
-            % my $status_name = $status eq 'R' ? 'moved' : 'copied';
167
-
168
-            % my $mode_change = "";
191
+            % my $mode_change;
169 192
             % if ($diff_tree->{'from_mode'} != $diff_tree->{'to_mode'}) {
170 193
               % $mode_change = sprintf(", mode: %04o", oct $diff_tree->{to_mode} & 0777);
171 194
             % }
172 195
             
173
-            <span>
174
-              [
175
-                <%= $status_name %> from
176
-                <a href="#"><%= $diff_tree->{from_file} %></a>
177
-                with <%= $diff_tree->{similarity} %>%
178
-                <%= $mode_change %>
179
-              ]
180
-            </span>
196
+            <a href="#<%= "diff-$num" %>"><%= $diff_tree->{from_file} %> → <%= $file %></a>
197
+            % unless ($diff_tree->{similarity} == 100) {
198
+              with <%= $diff_tree->{similarity} %>
199
+            % }
200
+            <%= $mode_change || '' %>
181 201
           % }
182 202
         </td>
183
-        <td>
184
-          <a style="margin-left:5px" href="#<%= "diff-$num" %>"><%= $file %></a>
185
-        </td>
186 203
         <td style="text-align:right">
187 204
           %= include '/include/diff_status_bar', diff_tree => $diff_tree, fragment => "diff-$num";
188 205
         </td>
+12
xt/basic.t
... ...
@@ -105,8 +105,20 @@ note 'Commit page';
105 105
     
106 106
     # Empty file is added
107 107
     $t->content_like(qr/No changes/);
108
+    $t->content_like(qr/Empty file added/);
109
+    $t->content_like(qr/class="file-add"/);
108 110
   }
109 111
   
112
+  note 'rename';
113
+  {
114
+    $t->get_ok("/$user/$project/commit/15ea9d711617abda5eed7b4173a3349d30bca959");
115
+    $t->content_like(qr/File renamed without changes/);
116
+    $t->content_like(qr/a.txt → a_renamed.txt/);
117
+    $t->content_like(qr/class="file-renamed"/);
118
+  }
119
+  
120
+
121
+  
110 122
   note 'Branch name';
111 123
   {
112 124
     # Page access (branch name)