Showing 4 changed files with 106 additions and 66 deletions
+49
lib/Gitprep/Git.pm
... ...
@@ -50,6 +50,55 @@ sub authors {
50 50
   return [sort keys %$authors];
51 51
 }
52 52
 
53
+sub blobdiffs {
54
+  my ($self, $rep, $from_id, $id, $difftrees) = @_;
55
+  
56
+  my $blobdiffs = [];
57
+  my @cmd = ($self->cmd($rep), 'diff-tree', '-r', '-M',
58
+    '--no-commit-id', '--patch-with-raw', $from_id, $id, '--');
59
+  open my $fh, '-|', @cmd
60
+    or croak('Open self-diff-tree failed');
61
+  my @file_info_raws;
62
+  while (my $line = $self->dec(scalar <$fh>)) {
63
+    chomp $line;
64
+    push @file_info_raws, $line if $line =~ /^:/;
65
+    last if $line =~ /^\n/;
66
+  }
67
+  close $fh;
68
+  for my $line (@file_info_raws) {
69
+  
70
+    # Parse line
71
+    chomp $line;
72
+    my $diffinfo = $self->parse_difftree_raw_line($line);
73
+    my $from_file = $diffinfo->{from_file};
74
+    my $file = $diffinfo->{to_file};
75
+    
76
+    # Get blobdiff (command "self diff-tree")
77
+    my @cmd = ($self->cmd($rep), 'diff-tree', '-r', '-M', '-p',
78
+      $from_id, $id, '--', (defined $from_file ? $from_file : ()), $file);
79
+    open my $fh_blobdiff, '-|', @cmd
80
+      or croak('Open self-diff-tree failed');
81
+    my @lines = map { $self->dec($_) } <$fh_blobdiff>;
82
+    close $fh_blobdiff;
83
+    my $blobdiff = {
84
+      file => $file,
85
+      from_file => $from_file,
86
+      lines => $self->parse_blobdiff_lines(\@lines)
87
+    };
88
+    
89
+    # Status
90
+    for my $difftree (@$difftrees) {
91
+      if ($difftree->{to_file} eq $file) {
92
+        $blobdiff->{status} = $difftree->{status};
93
+        last;
94
+      }
95
+    }
96
+    push @$blobdiffs, $blobdiff;
97
+  }
98
+  
99
+  return $blobdiffs;
100
+}
101
+
53 102
 sub blob_plain {
54 103
   my ($self, $rep, $ref, $path) = @_;
55 104
   
+15 -63
templates/main/commit.html.ep
... ...
@@ -28,59 +28,13 @@
28 28
   $commit->{author_date} = $git->timestamp($author_date);
29 29
   $commit->{committer_date} = $git->timestamp($committer_date);
30 30
   $from_id = $commit->{parent} unless defined $from_id;
31
-  
32 31
 
33 32
   # Diff tree
34 33
   my $difftrees = $git->difftree($rep,
35 34
     $id, $commit->{parent}, $commit->{parents});
36 35
   
37 36
   # Get blob diffs (command "git diff-tree")
38
-  my @cmd = ($git->cmd($rep), 'diff-tree', '-r', '-M',
39
-    '--no-commit-id', '--patch-with-raw', $from_id, $id, '--');
40
-  open my $fh, '-|', @cmd
41
-    or $api->croak('Open git-diff-tree failed');
42
-
43
-
44
-  my @file_info_raws;
45
-  while (my $line = $git->dec(scalar <$fh>)) {
46
-    chomp $line;
47
-    push @file_info_raws, $line if $line =~ /^:/;
48
-    last if $line =~ /^\n/;
49
-  }
50
-  close $fh;
51
-  
52
-  # Parse output
53
-  my $blobdiffs = [];
54
-  for my $line (@file_info_raws) {
55
-  
56
-    # Parse line
57
-    chomp $line;
58
-    my $diffinfo = $git->parse_difftree_raw_line($line);
59
-    my $from_file = $diffinfo->{from_file};
60
-    my $file = $diffinfo->{to_file};
61
-    
62
-    # Get blobdiff (command "git diff-tree")
63
-    my @cmd = ($git->cmd($rep), 'diff-tree', '-r', '-M', '-p',
64
-      $from_id, $id, '--', (defined $from_file ? $from_file : ()), $file);
65
-    open my $fh_blobdiff, '-|', @cmd
66
-      or $api->croak('Open git-diff-tree failed');
67
-    my @lines = map { $git->dec($_) } <$fh_blobdiff>;
68
-    close $fh_blobdiff;
69
-    my $blobdiff = {
70
-      file => $file,
71
-      from_file => $from_file,
72
-      lines => $git->parse_blobdiff_lines(\@lines)
73
-    };
74
-    
75
-    # Status
76
-    for my $difftree (@$difftrees) {
77
-      if ($difftree->{to_file} eq $file) {
78
-        $blobdiff->{status} = $difftree->{status};
79
-        last;
80
-      }
81
-    }
82
-    push @$blobdiffs, $blobdiff;
83
-  }
37
+  my $blobdiffs = $git->blobdiffs($rep, $from_id, $id, $difftrees);
84 38
   
85 39
   # Render
86 40
   stash(
... ...
@@ -223,24 +177,22 @@
223 177
     </div>
224 178
     
225 179
     <div style="margin-top:10px;margin-bottom:10px;">
226
-    <%= include '/include/difftree', id => $commit->{id}, from_id => $commit->{parent},
227
-      difftrees => $difftrees, parents => $commit->{parents}, project_ns => $project %>
180
+      <%= include '/include/difftree', id => $commit->{id}, from_id => $commit->{parent},
181
+        difftrees => $difftrees, parents => $commit->{parents}, project_ns => $project %>
228 182
     </div>
229 183
     
230
-    <div>
231
-      <div class="patchset">
232
-        % for (my $i = 0; $i < @$blobdiffs; $i++) {
233
-          % my $blobdiff = $blobdiffs->[$i];
234
-          <div class="patch" id="<%= $i + 1 %>">
235
-            % my $lines = $blobdiff->{lines};
236
-            % my $file = $blobdiff->{file};
237
-            % my $from_file = $blobdiff->{from_file};
238
-            % $from_file = $file unless defined $from_file;
239
-            % my $status = $blobdiff->{status};
240
-            %= include '/include/blobdiff_body', file => $file, from_file => $from_file, status => $status, lines => $blobdiff->{lines}, project_ns => $project;
241
-          </div>
242
-        % }
243
-      </div>
184
+    <div class="patchset">
185
+      % for (my $i = 0; $i < @$blobdiffs; $i++) {
186
+        % my $blob_diff = $blobdiffs->[$i];
187
+        <div class="patch" id="<%= $i + 1 %>">
188
+          % my $lines = $blob_diff->{lines};
189
+          % my $file = $blob_diff->{file};
190
+          % my $from_file = $blob_diff->{from_file};
191
+          % $from_file = $file unless defined $from_file;
192
+          % my $status = $blob_diff->{status};
193
+          %= include '/include/blobdiff_body', file => $file, from_file => $from_file, status => $status, lines => $blob_diff->{lines}, project_ns => $project;
194
+        </div>
195
+      % }
244 196
     </div>
245 197
   </div>
246 198
   
+1 -1
templates/main/commits.html.ep
... ...
@@ -148,7 +148,7 @@
148 148
       % }
149 149
     </div>
150 150
     
151
-    % for my $date (sort keys %$commits_date) {
151
+    % for my $date (reverse sort keys %$commits_date) {
152 152
       <div class="commit">
153 153
         % my $commits = $commits_date->{$date};
154 154
         
+41 -2
templates/main/compare.html.ep
... ...
@@ -28,6 +28,24 @@
28 28
     push @{$commits_date->{$date}}, $commit;
29 29
   }
30 30
   my $authors_count = keys %$authors;
31
+
32
+  # Start commit
33
+  my $start_commit = $git->separated_commit($rep, $rev1, $rev2);
34
+
35
+  # End commit
36
+  my $end_commit = $git->parse_commit($rep, $rev2)
37
+    or $api->croak('Unknown commit object');
38
+  
39
+  use D;d [$start_commit->{id}, $end_commit->{id}];
40
+  
41
+  # Diff tree
42
+  my $difftrees = $git->difftree($rep,
43
+    ,$end_commit->{id}, $start_commit->{id}, []);
44
+  
45
+  use D;d $difftrees;
46
+  
47
+  # Get blob diffs (command "git diff-tree")
48
+  my $blobdiffs = $git->blobdiffs($rep, $start_commit->{id}, $end_commit->{id}, $difftrees);
31 49
   
32 50
   # Global variable
33 51
   stash(user => $user, project => $project);
... ...
@@ -156,7 +174,7 @@
156 174
     <h2>Compare View</h2>
157 175
     <div class="compare_header">
158 176
       <div class="cdate">Last commit <%= $commits->[0]{age_string_age} %></div>
159
-      <div class="ctarget">master ... next</div>
177
+      <div class="ctarget"><%= $rev1 %> ... <%= $rev2 %></div>
160 178
     </div>
161 179
 
162 180
     <div class="compare_tabs">
... ...
@@ -171,7 +189,7 @@
171 189
       Showing <%= @$commits %> commits by <%= $authors_count %> author.
172 190
     </div>
173 191
 
174
-    % for my $date (sort keys %$commits_date) {
192
+    % for my $date (reverse sort keys %$commits_date) {
175 193
       <div class="commits">
176 194
         % my $commits = $commits_date->{$date};
177 195
         
... ...
@@ -197,6 +215,27 @@
197 215
         % }
198 216
       </div>
199 217
     % }
218
+
219
+    <div style="margin-top:10px;margin-bottom:10px;">
220
+      <%= include '/include/difftree', id => $end_commit->{id}, from_id => $start_commit->{id},
221
+        difftrees => $difftrees, parents => [], project_ns => $project %>
222
+    </div>
223
+    
224
+    <div>
225
+      <div class="patchset">
226
+        % for (my $i = 0; $i < @$blobdiffs; $i++) {
227
+          % my $blobdiff = $blobdiffs->[$i];
228
+          <div class="patch" id="<%= $i + 1 %>">
229
+            % my $lines = $blobdiff->{lines};
230
+            % my $file = $blobdiff->{file};
231
+            % my $from_file = $blobdiff->{from_file};
232
+            % $from_file = $file unless defined $from_file;
233
+            % my $status = $blobdiff->{status};
234
+            %= include '/include/blobdiff_body', file => $file, from_file => $from_file, status => $status, lines => $blobdiff->{lines}, project_ns => $project, from_id => $start_commit->{id}, id => $end_commit->{id};
235
+          </div>
236
+        % }
237
+      </div>
238
+    </div>
200 239
   </div>
201 240
   
202 241
   %= include '/include/footer';