... | ... |
@@ -58,11 +58,13 @@ sub branch_status { |
58 | 58 |
|
59 | 59 |
# Branch status |
60 | 60 |
my $status = {ahead => 0, behind => 0}; |
61 |
- my @cmd = $self->cmd_dir( |
|
62 |
- $git_dir, |
|
63 |
- 'rev-list', |
|
64 |
- '--left-right', |
|
65 |
- "$branch1...$branch2" |
|
61 |
+ my @cmd = $self->cmd( |
|
62 |
+ git_dir => $git_dir, |
|
63 |
+ command => [ |
|
64 |
+ 'rev-list', |
|
65 |
+ '--left-right', |
|
66 |
+ "$branch1...$branch2" |
|
67 |
+ ] |
|
66 | 68 |
); |
67 | 69 |
open my $fh, '-|', @cmd |
68 | 70 |
or croak "Can't get branch status: @cmd"; |
... | ... |
@@ -139,6 +141,25 @@ sub branches_count { |
139 | 141 |
return $branches_count; |
140 | 142 |
} |
141 | 143 |
|
144 |
+sub cmd { |
|
145 |
+ my ($self, %opt) = @_; |
|
146 |
+ |
|
147 |
+ my $git_dir = $opt{git_dir}; |
|
148 |
+ my $work_tree = $opt{work_tree}; |
|
149 |
+ my $command = $opt{command}; |
|
150 |
+ |
|
151 |
+ my @command_all = ($self->bin); |
|
152 |
+ if (defined $git_dir) { |
|
153 |
+ push @command_all, "--git-dir=$git_dir"; |
|
154 |
+ } |
|
155 |
+ if (defined $work_tree) { |
|
156 |
+ push @command_all, "--work-tree=$work_tree"; |
|
157 |
+ } |
|
158 |
+ push @command_all, @$command; |
|
159 |
+ |
|
160 |
+ return @command_all; |
|
161 |
+} |
|
162 |
+ |
|
142 | 163 |
sub cmd_rep { |
143 | 164 |
my ($self, $user, $project, @cmd) = @_; |
144 | 165 |
|
... | ... |
@@ -1271,17 +1292,21 @@ sub get_commit_new { |
1271 | 1292 |
my ($self, %opt) = @_; |
1272 | 1293 |
|
1273 | 1294 |
my $git_dir = $opt{git_dir}; |
1295 |
+ my $work_tree = $opt{work_tree}; |
|
1274 | 1296 |
my $id = $opt{id}; |
1275 | 1297 |
|
1276 | 1298 |
# Git rev-list |
1277 |
- my @cmd = $self->cmd_dir( |
|
1278 |
- $git_dir, |
|
1279 |
- 'rev-list', |
|
1280 |
- '--parents', |
|
1281 |
- '--header', |
|
1282 |
- '--max-count=1', |
|
1283 |
- $id, |
|
1284 |
- '--' |
|
1299 |
+ my @cmd = $self->cmd( |
|
1300 |
+ git_dir => $git_dir, |
|
1301 |
+ work_tree => $work_tree, |
|
1302 |
+ command => [ |
|
1303 |
+ 'rev-list', |
|
1304 |
+ '--parents', |
|
1305 |
+ '--header', |
|
1306 |
+ '--max-count=1', |
|
1307 |
+ $id, |
|
1308 |
+ '--' |
|
1309 |
+ ] |
|
1285 | 1310 |
); |
1286 | 1311 |
open my $fh, '-|', @cmd |
1287 | 1312 |
or croak 'Open git-rev-list failed'; |