Showing 2 changed files with 118 additions and 118 deletions
+117 -117
lib/Gitprep/Git.pm
... ...
@@ -15,6 +15,89 @@ has encoding => 'UTF-8';
15 15
 has 'rep_home';
16 16
 has text_exts => sub { ['txt'] };
17 17
 
18
+sub branch {
19
+  my ($self, $user, $project, $branch_name) = @_;
20
+  
21
+  # Branch
22
+  $branch_name =~ s/^\*//;
23
+  $branch_name =~ s/^\s*//;
24
+  $branch_name =~ s/\s*$//;
25
+  my $branch = {};
26
+  $branch->{name} = $branch_name;
27
+  my $commit = $self->get_commit($user, $project, $branch_name);
28
+  $branch->{commit} = $commit;
29
+
30
+  return $branch;
31
+}
32
+
33
+sub branch_status {
34
+  my ($self, $user, $project, $branch1, $branch2) = @_;
35
+  
36
+  # Branch status
37
+  my $status = {ahead => 0, behind => 0};
38
+  my @cmd = $self->cmd(
39
+    $user,
40
+    $project,
41
+    'rev-list',
42
+    '--left-right',
43
+    "$branch1...$branch2"
44
+  );
45
+  open my $fh, '-|', @cmd
46
+    or croak "Can't get branch status: @cmd";
47
+  while (my $line = <$fh>) {
48
+    if ($line =~ /^</) { $status->{behind}++ }
49
+    elsif ($line =~ /^>/) { $status->{ahead}++ }
50
+  }
51
+  
52
+  return $status;
53
+}
54
+
55
+sub branches {
56
+  my ($self, $user, $project, $opts) = @_;
57
+  
58
+  # No merged branches
59
+  my $no_merged_branches_h = {};
60
+  {
61
+    my @cmd = $self->cmd($user, $project, 'branch');
62
+    push @cmd, , '--no-merged';
63
+    open my $fh, '-|', @cmd or return;
64
+    
65
+    while (my $branch_name = $self->_dec(scalar <$fh>)) {
66
+      $branch_name =~ s/^\*//;
67
+      $branch_name =~ s/^\s*//;
68
+      $branch_name =~ s/\s*$//;
69
+      $no_merged_branches_h->{$branch_name} = 1;
70
+    }
71
+  }
72
+  
73
+  # Branches
74
+  my @cmd = $self->cmd($user, $project, 'branch');
75
+  open my $fh, '-|', @cmd or return;
76
+  my $branches = [];
77
+  while (my $branch_name = $self->_dec(scalar <$fh>)) {
78
+    
79
+    # Branch
80
+    my $branch = $self->branch($user, $project, $branch_name);
81
+    $branch->{no_merged} = 1 if $no_merged_branches_h->{$branch_name};
82
+    push @$branches, $branch;
83
+  }
84
+  @$branches = sort { $a->{commit}{age} <=> $b->{commit}{age} } @$branches;
85
+  
86
+  return $branches;
87
+}
88
+
89
+sub branches_count {
90
+  my ($self, $user, $project) = @_;
91
+  
92
+  # Branches count
93
+  my @cmd = $self->cmd($user, $project, 'branch');
94
+  open my $fh, '-|', @cmd or return;
95
+  my @branches = <$fh>;
96
+  my $branches_count = @branches;
97
+  
98
+  return $branches_count;
99
+}
100
+
18 101
 sub cmd {
19 102
   my ($self, $user, $project, @cmd) = @_;
20 103
   
... ...
@@ -264,67 +347,6 @@ sub blob_size {
264 347
   return $size_f;
265 348
 }
266 349
 
267
-sub exists_branch {
268
-  my ($self, $user, $project) = @_;
269
-  
270
-  # Exists branch
271
-  my $home = $self->rep_home;
272
-  my @cmd = $self->cmd($user, $project, 'branch');
273
-  open my $fh, "-|", @cmd
274
-    or croak 'git branch failed';
275
-  local $/;
276
-  my $branches = <$fh>;
277
-  
278
-  return $branches ne '' ? 1 : 0;
279
-}
280
-
281
-sub branch_diff {
282
-  my ($self, $user, $project, $branch1, $branch2) = @_;
283
-  
284
-  my @cmd = $self->cmd(
285
-    $user,
286
-    $project,
287
-    'rev-list',
288
-    '--left-right',
289
-    "$branch1...$branch2"
290
-  );
291
-  open my $fh, '-|', @cmd
292
-    or croak "Can't get branch status: @cmd";
293
-  
294
-  my $commits = [];
295
-  while (my $line = <$fh>) {
296
-    if ($line =~ /^>(.+)\s/) {
297
-      my $commit_id = $1;
298
-      my $commit = $self->get_commit($user, $project, $commit_id);
299
-      push @$commits, $commit;
300
-    }
301
-  }
302
-  
303
-  return $commits;
304
-}
305
-
306
-sub branch_status {
307
-  my ($self, $user, $project, $branch1, $branch2) = @_;
308
-  
309
-  my $status = {ahead => 0, behind => 0};
310
-  my @cmd = $self->cmd(
311
-    $user,
312
-    $project,
313
-    'rev-list',
314
-    '--left-right',
315
-    "$branch1...$branch2"
316
-  );
317
-  open my $fh, '-|', @cmd
318
-    or croak "Can't get branch status: @cmd";
319
-  
320
-  while (my $line = <$fh>) {
321
-    if ($line =~ /^</) { $status->{behind}++ }
322
-    elsif ($line =~ /^>/) { $status->{ahead}++ }
323
-  }
324
-  
325
-  return $status;
326
-}
327
-
328 350
 sub check_head_link {
329 351
   my ($self, $dir) = @_;
330 352
   
... ...
@@ -354,6 +376,20 @@ sub commits_number {
354 376
   return $commits_num;
355 377
 }
356 378
 
379
+sub exists_branch {
380
+  my ($self, $user, $project) = @_;
381
+  
382
+  # Exists branch
383
+  my $home = $self->rep_home;
384
+  my @cmd = $self->cmd($user, $project, 'branch');
385
+  open my $fh, "-|", @cmd
386
+    or croak 'git branch failed';
387
+  local $/;
388
+  my $branches = <$fh>;
389
+  
390
+  return $branches ne '' ? 1 : 0;
391
+}
392
+
357 393
 sub delete_branch {
358 394
   my ($self, $user, $project, $branch) = @_;
359 395
   
... ...
@@ -486,7 +522,7 @@ sub file_type {
486 522
 sub file_type_long {
487 523
   my ($self, $mode) = @_;
488 524
   
489
-  # File type
525
+  # File type long
490 526
   if ($mode !~ m/^[0-7]+$/) { return $mode }
491 527
   else { $mode = oct $mode }
492 528
   if ($self->_s_isgitlink($mode)) { return 'submodule' }
... ...
@@ -517,65 +553,29 @@ sub fill_from_file_info {
517 553
   return $diff;
518 554
 }
519 555
 
520
-sub branches {
521
-  my ($self, $user, $project, $opts) = @_;
556
+sub forward_commits {
557
+  my ($self, $user, $project, $rev1, $rev2) = @_;
522 558
   
523
-  # No merged branches
524
-  my $no_merged_branches_h = {};
525
-  {
526
-    my @cmd = $self->cmd($user, $project, 'branch');
527
-    push @cmd, , '--no-merged';
528
-    open my $fh, '-|', @cmd or return;
529
-    
530
-    while (my $branch_name = $self->_dec(scalar <$fh>)) {
531
-      $branch_name =~ s/^\*//;
532
-      $branch_name =~ s/^\s*//;
533
-      $branch_name =~ s/\s*$//;
534
-      $no_merged_branches_h->{$branch_name} = 1;
559
+  # Forwarding commits
560
+  my @cmd = $self->cmd(
561
+    $user,
562
+    $project,
563
+    'rev-list',
564
+    '--left-right',
565
+    "$rev1...$rev2"
566
+  );
567
+  open my $fh, '-|', @cmd
568
+    or croak "Can't get info: @cmd";
569
+  my $commits = [];
570
+  while (my $line = <$fh>) {
571
+    if ($line =~ /^>(.+)\s/) {
572
+      my $rev = $1;
573
+      my $commit = $self->get_commit($user, $project, $rev);
574
+      push @$commits, $commit;
535 575
     }
536 576
   }
537 577
   
538
-  # All branches
539
-  my @cmd = $self->cmd($user, $project, 'branch');
540
-  open my $fh, '-|', @cmd or return;
541
-  my $branches = [];
542
-  while (my $branch_name = $self->_dec(scalar <$fh>)) {
543
-    
544
-    my $branch = $self->branch($user, $project, $branch_name);
545
-    $branch->{no_merged} = 1 if $no_merged_branches_h->{$branch_name};
546
-
547
-    push @$branches, $branch;
548
-  }
549
-  
550
-  @$branches = sort { $a->{commit}{age} <=> $b->{commit}{age} } @$branches;
551
-  
552
-  return $branches;
553
-}
554
-
555
-sub branch {
556
-  my ($self, $user, $project, $branch_name) = @_;
557
-
558
-  $branch_name =~ s/^\*//;
559
-  $branch_name =~ s/^\s*//;
560
-  $branch_name =~ s/\s*$//;
561
-  
562
-  my $branch = {};
563
-  $branch->{name} = $branch_name;
564
-  my $commit = $self->get_commit($user, $project, $branch_name);
565
-  $branch->{commit} = $commit;
566
-
567
-  return $branch;
568
-}
569
-
570
-sub branches_count {
571
-  my ($self, $user, $project) = @_;
572
-  
573
-  my @cmd = $self->cmd($user, $project, 'branch');
574
-  open my $fh, '-|', @cmd or return;
575
-  my @branches = <$fh>;
576
-  my $branches_count = @branches;
577
-  
578
-  return $branches_count;
578
+  return $commits;
579 579
 }
580 580
 
581 581
 sub path_to_hash {
+1 -1
templates/compare.html.ep
... ...
@@ -13,7 +13,7 @@
13 13
   my $git = $self->app->git;
14 14
   
15 15
   # Commits
16
-  my $commits = $git->branch_diff($user, $project, $rev1, $rev2);
16
+  my $commits = $git->forward_commits($user, $project, $rev1, $rev2);
17 17
   my $commits_count = @$commits;
18 18
   my $commits_date = {};
19 19
   my $authors = {};