... | ... |
@@ -33,6 +33,15 @@ sub data_dir { |
33 | 33 |
return $data_dir; |
34 | 34 |
} |
35 | 35 |
|
36 |
+sub rep_info { |
|
37 |
+ my ($self, $user, $project) = @_; |
|
38 |
+ |
|
39 |
+ my $info = {}; |
|
40 |
+ $info->{git_dir} = $self->rep_home . "/$user/$project.git"; |
|
41 |
+ |
|
42 |
+ return $info; |
|
43 |
+} |
|
44 |
+ |
|
36 | 45 |
sub rep_home { |
37 | 46 |
my $self = shift; |
38 | 47 |
|
... | ... |
@@ -34,6 +34,36 @@ sub branch { |
34 | 34 |
return $branch; |
35 | 35 |
} |
36 | 36 |
|
37 |
+sub branch_new { |
|
38 |
+ my ($self, %opt) = @_; |
|
39 |
+ my $git_dir = $opt{git_dir}; |
|
40 |
+ my $branch_name = $opt{name}; |
|
41 |
+ |
|
42 |
+ # Branch |
|
43 |
+ $branch_name =~ s/^\*//; |
|
44 |
+ $branch_name =~ s/^\s*//; |
|
45 |
+ $branch_name =~ s/\s*$//; |
|
46 |
+ my $branch = {}; |
|
47 |
+ $branch->{name} = $branch_name; |
|
48 |
+ my $commit = $self->get_commit_new(git_dir => $git_dir, id => $branch_name); |
|
49 |
+ $branch->{commit} = $commit; |
|
50 |
+ |
|
51 |
+ return $branch; |
|
52 |
+} |
|
53 |
+ |
|
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 |
+ |
|
37 | 67 |
sub branch_status { |
38 | 68 |
my ($self, $user, $project, $branch1, $branch2) = @_; |
39 | 69 |
|
... | ... |
@@ -100,7 +130,7 @@ sub branches { |
100 | 130 |
unless $start++; |
101 | 131 |
|
102 | 132 |
# Branch |
103 |
- my $branch = $self->branch($user, $project, $branch_name); |
|
133 |
+ my $branch = $self->branch_new(%{$self->app->rep_info($user, $project)}, name => $branch_name); |
|
104 | 134 |
$branch->{no_merged} = 1 if $no_merged_branches_h->{$branch_name}; |
105 | 135 |
push @$branches, $branch; |
106 | 136 |
} |
... | ... |
@@ -1249,6 +1279,36 @@ sub get_commit { |
1249 | 1279 |
return $commit; |
1250 | 1280 |
} |
1251 | 1281 |
|
1282 |
+sub get_commit_new { |
|
1283 |
+ my ($self, %opt) = @_; |
|
1284 |
+ |
|
1285 |
+ my $git_dir = $opt{git_dir}; |
|
1286 |
+ my $id = $opt{id}; |
|
1287 |
+ |
|
1288 |
+ # Git rev-list |
|
1289 |
+ my @cmd = $self->cmd_dir( |
|
1290 |
+ $git_dir, |
|
1291 |
+ 'rev-list', |
|
1292 |
+ '--parents', |
|
1293 |
+ '--header', |
|
1294 |
+ '--max-count=1', |
|
1295 |
+ $id, |
|
1296 |
+ '--' |
|
1297 |
+ ); |
|
1298 |
+ open my $fh, '-|', @cmd |
|
1299 |
+ or croak 'Open git-rev-list failed'; |
|
1300 |
+ |
|
1301 |
+ # Parse commit |
|
1302 |
+ local $/ = "\0"; |
|
1303 |
+ my $content = <$fh>; |
|
1304 |
+ $content = $self->_dec($content); |
|
1305 |
+ return unless defined $content; |
|
1306 |
+ my $commit = $self->parse_commit_text($content, 1); |
|
1307 |
+ close $fh; |
|
1308 |
+ |
|
1309 |
+ return $commit; |
|
1310 |
+} |
|
1311 |
+ |
|
1252 | 1312 |
sub parse_commit_text { |
1253 | 1313 |
my ($self, $commit_text, $withparents) = @_; |
1254 | 1314 |
|
... | ... |
@@ -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($user, $project, $default_branch_name); |
|
58 |
+ my $default_branch = $git->branch_new(%{$self->app->rep_info($user, $project)}, name => $default_branch_name); |
|
59 | 59 |
|
60 | 60 |
# Branches |
61 | 61 |
my $branch_types; |
... | ... |
@@ -66,9 +66,16 @@ |
66 | 66 |
|
67 | 67 |
# Fetch repository |
68 | 68 |
my $rep = $self->app->rep_path($user, $project); |
69 |
- my @git_fetch_cmd = $self->app->git->cmd_rep_work($user, $project, 'fetch', $rep); |
|
69 |
+ my @git_fetch_cmd = $self->app->git->cmd_rep_work($user, $project, 'fetch'); |
|
70 | 70 |
Gitprep::Util::run_command(@git_fetch_cmd) |
71 | 71 |
or Carp::croak "Can't execute git fetch: @git_fetch_cmd"; |
72 |
+ |
|
73 |
+ # git checkout -b origin/$from_rev |
|
74 |
+ my $gitprep_tmp_branch_name = '__gitprep_tmp_branch_name__'; |
|
75 |
+ my @git_checkout_tmp_branch = $self->app->git->cmd_rep_work( |
|
76 |
+ $user, $project, 'checkout', '-b', $gitprep_tmp_branch_name, "origin/$from_rev"); |
|
77 |
+ Gitprep::Util::run_command(@git_checkout_tmp_branch) |
|
78 |
+ or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch"; |
|
72 | 79 |
} |
73 | 80 |
|
74 | 81 |
layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project"; |