Showing 2 changed files with 25 additions and 33 deletions
+19 -31
lib/Gitprep/Git.pm
... ...
@@ -19,22 +19,20 @@ has text_exts => sub { ['txt'] };
19 19
 has 'time_zone_second';
20 20
 has 'app';
21 21
 
22
-sub branch {
23
-  my ($self, $user, $project, $branch_name) = @_;
22
+sub rep_work_current_branch {
23
+  my ($self, $user, $project) = @_;
24 24
   
25
-  # Branch
26
-  $branch_name =~ s/^\*//;
27
-  $branch_name =~ s/^\s*//;
28
-  $branch_name =~ s/\s*$//;
29
-  my $branch = {};
30
-  $branch->{name} = $branch_name;
31
-  my $commit = $self->get_commit($user, $project, $branch_name);
32
-  $branch->{commit} = $commit;
33
-
34
-  return $branch;
25
+  my @cmd = $self->cmd_work_rep($user, $project, 'rev-parse',  '--abbrev-ref', 'HEAD');
26
+  
27
+  open my $fh, '-|', @cmd
28
+    or croak "Can't get current branch: @cmd";
29
+  my $current_branch = <$fh>;
30
+  chomp $current_branch;
31
+  
32
+  return $current_branch;
35 33
 }
36 34
 
37
-sub branch_new {
35
+sub branch {
38 36
   my ($self, %opt) = @_;
39 37
   my $git_dir = $opt{git_dir};
40 38
   my $branch_name = $opt{name};
... ...
@@ -51,27 +49,17 @@ sub branch_new {
51 49
   return $branch;
52 50
 }
53 51
 
54
-sub rep_work_current_branch {
55
-  my ($self, $user, $project) = @_;
56
-  
57
-  my @cmd = $self->cmd_work_rep($user, $project, 'rev-parse',  '--abbrev-ref', 'HEAD');
58
-  
59
-  open my $fh, '-|', @cmd
60
-    or croak "Can't get current branch: @cmd";
61
-  my $current_branch = <$fh>;
62
-  chomp $current_branch;
63
-  
64
-  return $current_branch;
65
-}
66
-
67 52
 sub branch_status {
68
-  my ($self, $user, $project, $branch1, $branch2) = @_;
53
+  my ($self, %opt) = @_;
54
+  
55
+  my $git_dir = $opt{git_dir};
56
+  my $branch1 = $opt{from};
57
+  my $branch2 = $opt{to};
69 58
   
70 59
   # Branch status
71 60
   my $status = {ahead => 0, behind => 0};
72
-  my @cmd = $self->cmd_rep(
73
-    $user,
74
-    $project,
61
+  my @cmd = $self->cmd_dir(
62
+    $git_dir,
75 63
     'rev-list',
76 64
     '--left-right',
77 65
     "$branch1...$branch2"
... ...
@@ -130,7 +118,7 @@ sub branches {
130 118
       unless $start++;
131 119
     
132 120
     # Branch
133
-    my $branch = $self->branch_new(%{$self->app->rep_info($user, $project)}, name => $branch_name);
121
+    my $branch = $self->branch(%{$self->app->rep_info($user, $project)}, name => $branch_name);
134 122
     $branch->{no_merged} = 1 if $no_merged_branches_h->{$branch_name};
135 123
     push @$branches, $branch;
136 124
   }
+6 -2
templates/branches.html.ep
... ...
@@ -55,7 +55,7 @@
55 55
   
56 56
   # Default branch
57 57
   my $default_branch_name = app->manager->default_branch($user, $project);
58
-  my $default_branch = $git->branch_new(%{$self->app->rep_info($user, $project)}, name => $default_branch_name);
58
+  my $default_branch = $git->branch(%{$self->app->rep_info($user, $project)}, name => $default_branch_name);
59 59
   
60 60
   # Branches
61 61
   my $branch_types;
... ...
@@ -76,7 +76,11 @@
76 76
   my $stale_count = 0;
77 77
   my $all_count = 0;
78 78
   for my $branch (@$branches) {
79
-    $branch->{status} = $git->branch_status($user, $project, $default_branch->{name}, $branch->{name});
79
+    $branch->{status} = $git->branch_status(
80
+      %{$self->app->rep_info($user, $project)},
81
+      from => $default_branch->{name},
82
+      to => $branch->{name}
83
+    );
80 84
     $max = $branch->{status}{ahead} if $max < $branch->{status}{ahead};
81 85
     $max = $branch->{status}{behind} if $max < $branch->{status}{behind};
82 86