... | ... |
@@ -23,16 +23,7 @@ our $VERSION = '1.0301'; |
23 | 23 |
has 'dbi'; |
24 | 24 |
has 'manager'; |
25 | 25 |
has 'validator'; |
26 |
- |
|
27 |
-sub git { |
|
28 |
- my $self = shift; |
|
29 |
- |
|
30 |
- my $git = Gitprep::Git->new; |
|
31 |
- $git->bin($self->config->{internal}{git_bin}); |
|
32 |
- $git->rep_home($self->config->{internal}{git_rep_home}); |
|
33 |
- |
|
34 |
- return $git; |
|
35 |
-} |
|
26 |
+has 'git'; |
|
36 | 27 |
|
37 | 28 |
sub startup { |
38 | 29 |
my $self = shift; |
... | ... |
@@ -63,7 +54,7 @@ sub startup { |
63 | 54 |
$self->log->error($error); |
64 | 55 |
croak $error; |
65 | 56 |
} |
66 |
- $conf->{internal}{git_bin} = $git_bin; |
|
57 |
+ $git->bin($git_bin); |
|
67 | 58 |
|
68 | 59 |
# Repository home |
69 | 60 |
my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep'); |
... | ... |
@@ -71,7 +62,8 @@ sub startup { |
71 | 62 |
mkdir $rep_home |
72 | 63 |
or croak "Can't create directory $rep_home: $!"; |
73 | 64 |
} |
74 |
- $conf->{internal}{git_rep_home} = $rep_home; |
|
65 |
+ $git->rep_home($rep_home); |
|
66 |
+ $self->git($git); |
|
75 | 67 |
|
76 | 68 |
# Repository Manager |
77 | 69 |
my $manager = Gitprep::Manager->new(app => $self); |
... | ... |
@@ -245,10 +237,10 @@ sub startup { |
245 | 237 |
|
246 | 238 |
# API |
247 | 239 |
my $api = $self->gitprep_api; |
248 |
- |
|
249 |
- # Private |
|
250 | 240 |
my $user = $self->param('user'); |
251 | 241 |
my $project = $self->param('project'); |
242 |
+ |
|
243 |
+ # Private |
|
252 | 244 |
my $private = $self->app->manager->is_private_project($user, $project); |
253 | 245 |
if ($private) { |
254 | 246 |
if ($api->can_access_private_project($user, $project)) { |
... | ... |
@@ -42,6 +42,26 @@ sub check_user_and_password { |
42 | 42 |
return $is_valid; |
43 | 43 |
} |
44 | 44 |
|
45 |
+sub git { |
|
46 |
+ my $self = shift; |
|
47 |
+ |
|
48 |
+ my $git = $self->app->git->clone; |
|
49 |
+ |
|
50 |
+ my $user = $self->cntl->param('user'); |
|
51 |
+ my $project = $self->cntl->param('project'); |
|
52 |
+ |
|
53 |
+ if (defined $user && defined $project){ |
|
54 |
+ # Project encoding |
|
55 |
+ my $encoding = $self->app->dbi->model('project')->select( |
|
56 |
+ 'encoding', |
|
57 |
+ id => [$user, $project] |
|
58 |
+ )->value; |
|
59 |
+ $git->encoding($encoding) if length $encoding; |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ return $git; |
|
63 |
+} |
|
64 |
+ |
|
45 | 65 |
sub is_collaborator { |
46 | 66 |
my ($self, $user, $project, $session_user) = @_; |
47 | 67 |
|
... | ... |
@@ -53,6 +53,18 @@ sub branch_status { |
53 | 53 |
return $status; |
54 | 54 |
} |
55 | 55 |
|
56 |
+sub clone { |
|
57 |
+ my $self = shift; |
|
58 |
+ |
|
59 |
+ my $clone = __PACKAGE__->new; |
|
60 |
+ $clone->bin($self->bin); |
|
61 |
+ $clone->encoding($self->encoding); |
|
62 |
+ $clone->rep_home($self->rep_home); |
|
63 |
+ $clone->text_exts([@{$self->text_exts}]); |
|
64 |
+ |
|
65 |
+ return $clone; |
|
66 |
+} |
|
67 |
+ |
|
56 | 68 |
sub no_merged_branch_h { |
57 | 69 |
my ($self, $user, $project) = @_; |
58 | 70 |
|
... | ... |
@@ -2,7 +2,7 @@ |
2 | 2 |
my $api = gitprep_api; |
3 | 3 |
|
4 | 4 |
# Git |
5 |
- my $git = app->git; |
|
5 |
+ my $git = $api->git; |
|
6 | 6 |
|
7 | 7 |
# Branches |
8 | 8 |
my $branches = $git->branches($user, $project) || []; |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
<% |
2 | 2 |
# API |
3 |
- my $api = $self->gitprep_api; |
|
3 |
+ my $api = gitprep_api; |
|
4 | 4 |
|
5 | 5 |
# Parameter |
6 | 6 |
my $user = param('user'); |
... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
} |
24 | 24 |
|
25 | 25 |
# Git |
26 |
- my $git = app->git; |
|
26 |
+ my $git = $api->git; |
|
27 | 27 |
|
28 | 28 |
# Object type |
29 | 29 |
my $type = $git->object_type($user, $project, "$rev^{}"); |
... | ... |
@@ -33,7 +33,7 @@ |
33 | 33 |
my $vresult = $validator->validate($params, $rule); |
34 | 34 |
|
35 | 35 |
# Git |
36 |
- my $git = app->git; |
|
36 |
+ my $git = $api->git; |
|
37 | 37 |
if ($vresult->is_ok) { |
38 | 38 |
# Not logined |
39 | 39 |
unless ($api->logined) { |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
my $api = gitprep_api; |
4 | 4 |
|
5 | 5 |
# Git |
6 |
- my $git = $self->app->git; |
|
6 |
+ my $git = $api->git; |
|
7 | 7 |
|
8 | 8 |
# Parameters |
9 | 9 |
my $user = param('user'); |
... | ... |
@@ -5,7 +5,7 @@ |
5 | 5 |
my $api = gitprep_api; |
6 | 6 |
|
7 | 7 |
# Git |
8 |
- my $git = $self->app->git; |
|
8 |
+ my $git = $api->git; |
|
9 | 9 |
|
10 | 10 |
# Parameters |
11 | 11 |
my $user = param('user'); |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
my $op = param('op') || ''; |
10 | 10 |
|
11 | 11 |
# Git |
12 |
- my $git = $self->app->git; |
|
12 |
+ my $git = $api->git; |
|
13 | 13 |
|
14 | 14 |
# Delete |
15 | 15 |
my $errors; |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
$rev = $diff unless defined $rev; |
10 | 10 |
|
11 | 11 |
# Git |
12 |
- my $git = app->git; |
|
12 |
+ my $git = $api->git; |
|
13 | 13 |
|
14 | 14 |
# Commit |
15 | 15 |
my $commit = $git->get_commit($user, $project, $rev); |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
my $api = gitprep_api; |
4 | 4 |
|
5 | 5 |
# Git |
6 |
- my $git = $self->app->git; |
|
6 |
+ my $git = $api->git; |
|
7 | 7 |
|
8 | 8 |
# Parameters |
9 | 9 |
my $user = param('user'); |
... | ... |
@@ -10,7 +10,7 @@ |
10 | 10 |
my $page = param('page') || 0; |
11 | 11 |
|
12 | 12 |
# Git |
13 |
- my $git = $self->app->git; |
|
13 |
+ my $git = $api->git; |
|
14 | 14 |
|
15 | 15 |
# Commits |
16 | 16 |
my $commits = $git->forward_commits($user, $project, $from_rev, $rev); |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
} |
16 | 16 |
|
17 | 17 |
# Branches |
18 |
- my $git = app->git; |
|
18 |
+ my $git = $api->git; |
|
19 | 19 |
my $remote_branches = $git->branches($remote_user, $remote_project); |
20 | 20 |
my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
21 | 21 |
|
... | ... |
@@ -1,8 +1,10 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
my $rev = stash('rev'); |
3 | 5 |
my $from_rev = stash('from_rev'); |
4 | 6 |
|
5 |
- my $git = app->git; |
|
7 |
+ my $git = $api->git; |
|
6 | 8 |
|
7 | 9 |
my $diff_tree = stash('diff_tree'); |
8 | 10 |
my $blob_diff = stash('blob_diff'); |
... | ... |
@@ -1,11 +1,13 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
my $display = stash('display') || ''; |
3 | 5 |
my $rev = stash('rev'); |
4 | 6 |
$rev = '' unless defined $rev; |
5 | 7 |
my $branches = stash('branches'); |
6 |
- my $branches_count = app->git->branches_count($user, $project); |
|
8 |
+ my $branches_count = $api->git->branches_count($user, $project); |
|
7 | 9 |
my $default_branch_name = app->manager->default_branch($user, $project); |
8 |
- my $tags_count = app->git->tags_count($user, $project); |
|
10 |
+ my $tags_count = $api->git->tags_count($user, $project); |
|
9 | 11 |
%> |
10 | 12 |
|
11 | 13 |
%= javascript begin |
... | ... |
@@ -1,10 +1,12 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
# Parameters |
3 | 5 |
my $rev = stash('rev'); |
4 | 6 |
my $from_rev = stash('from_rev'); |
5 | 7 |
|
6 | 8 |
# Git |
7 |
- my $git = app->git; |
|
9 |
+ my $git = $api->git; |
|
8 | 10 |
|
9 | 11 |
# Diff tree |
10 | 12 |
my $diff_trees = $git->diff_tree( |
... | ... |
@@ -2,10 +2,12 @@ |
2 | 2 |
use Mojo::ByteStream (); |
3 | 3 |
use Text::Markdown::Discount (); |
4 | 4 |
|
5 |
+ my $api = gitprep_api; |
|
6 |
+ |
|
5 | 7 |
# README |
6 | 8 |
my $type; |
7 | 9 |
my $lines; |
8 |
- eval { $lines = app->git->blob($user, $project, $rev, 'README') }; |
|
10 |
+ eval { $lines = $api->git->blob($user, $project, $rev, 'README') }; |
|
9 | 11 |
my $readme_e; |
10 | 12 |
if ($lines) { |
11 | 13 |
$type = 'plain'; |
... | ... |
@@ -14,7 +16,7 @@ |
14 | 16 |
$readme_e =~ s#(^|\s|[^\x00-\x7F])(http(?:s)?://.+?)($|\s|[^\x00-\x7F])#$1<a href="$2">$2</a>$3#msg; |
15 | 17 |
} |
16 | 18 |
else { |
17 |
- eval { $lines = app->git->blob($user, $project, $rev, 'README.md') }; |
|
19 |
+ eval { $lines = $api->git->blob($user, $project, $rev, 'README.md') }; |
|
18 | 20 |
if ($lines) { |
19 | 21 |
$type = 'markdown'; |
20 | 22 |
my $readme = join "\n", @$lines; |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
my $api = gitprep_api; |
4 | 4 |
|
5 | 5 |
# Branches |
6 |
- my $branches = [map { $_->{name} } @{app->git->branches($user, $project)}]; |
|
6 |
+ my $branches = [map { $_->{name} } @{$api->git->branches($user, $project)}]; |
|
7 | 7 |
|
8 | 8 |
# Members |
9 | 9 |
my $members = app->manager->members($user, $project); |
... | ... |
@@ -11,7 +11,7 @@ |
11 | 11 |
# Members branches |
12 | 12 |
for my $member (@$members) { |
13 | 13 |
my $branches = [ |
14 |
- map { $_->{name} } @{app->git->branches($member->{id}, $member->{project})} |
|
14 |
+ map { $_->{name} } @{$api->git->branches($member->{id}, $member->{project})} |
|
15 | 15 |
]; |
16 | 16 |
$member->{branches} = $branches; |
17 | 17 |
} |
... | ... |
@@ -1,12 +1,14 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
my $user = param('user'); |
3 | 5 |
my $project = param('project'); |
4 | 6 |
my $branch = param('rev1'); |
5 | 7 |
my $rev2_abs = param('rev2_abs'); |
6 | 8 |
my ($remote_user, $remote_project, $remote_branch) = split /\//, $rev2_abs, 3; |
7 | 9 |
|
8 |
- my $commits = app->git->get_commits($user, $project, $branch, 100); |
|
9 |
- my $remote_commits = app->git->get_commits( |
|
10 |
+ my $commits = $api->git->get_commits($user, $project, $branch, 100); |
|
11 |
+ my $remote_commits = $api->git->get_commits( |
|
10 | 12 |
$remote_user, |
11 | 13 |
$remote_project, |
12 | 14 |
$remote_branch, |
... | ... |
@@ -7,7 +7,7 @@ |
7 | 7 |
my $api = gitprep_api; |
8 | 8 |
|
9 | 9 |
# Git |
10 |
- my $git = app->git; |
|
10 |
+ my $git = $api->git; |
|
11 | 11 |
|
12 | 12 |
# Parameters |
13 | 13 |
my $user = param('user'); |
... | ... |
@@ -49,7 +49,7 @@ |
49 | 49 |
my $url = url_for->to_abs; |
50 | 50 |
$url->base(undef); |
51 | 51 |
my $ssh_port = config->{basic}{ssh_port}; |
52 |
- my $rep_home = app->git->rep_home; |
|
52 |
+ my $rep_home = $api->git->rep_home; |
|
53 | 53 |
my $execute_user = getpwuid($>); |
54 | 54 |
my $ssh_rep_url = "ssh://$execute_user\@" . $url->host |
55 | 55 |
. ($ssh_port ? ":$ssh_port" : '') . "$rep_home/$user/$project.git"; |
... | ... |
@@ -1,6 +1,9 @@ |
1 | 1 |
<% |
2 |
+ # API |
|
3 |
+ my $api = gitprep_api; |
|
4 |
+ |
|
2 | 5 |
# Git |
3 |
- my $git = app->git; |
|
6 |
+ my $git = $api->git; |
|
4 | 7 |
|
5 | 8 |
# Parameters |
6 | 9 |
my $user = param('user'); |
... | ... |
@@ -16,7 +16,7 @@ |
16 | 16 |
} |
17 | 17 |
|
18 | 18 |
# Rename project |
19 |
- my $git = app->git; |
|
19 |
+ my $git = $api->git; |
|
20 | 20 |
my $errors; |
21 | 21 |
my $post = lc $self->req->method eq 'post'; |
22 | 22 |
if ($op eq 'rename-project' && $post) { |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
} |
16 | 16 |
|
17 | 17 |
# Rename project |
18 |
- my $git = app->git; |
|
18 |
+ my $git = $api->git; |
|
19 | 19 |
my $errors; |
20 | 20 |
if (lc $self->req->method eq 'post') { |
21 | 21 |
if ($op eq 'add') { |
... | ... |
@@ -3,10 +3,12 @@ |
3 | 3 |
use Symbol (); |
4 | 4 |
use IO::Select (); |
5 | 5 |
|
6 |
+ my $api = gitprep_api; |
|
7 |
+ |
|
6 | 8 |
my $service = param('service') || ''; |
7 | 9 |
my $user = param('user'); |
8 | 10 |
my $project = param('project'); |
9 |
- my $git = app->git; |
|
11 |
+ my $git = $api->git; |
|
10 | 12 |
|
11 | 13 |
# Smart HTTP |
12 | 14 |
if ($service eq 'git-upload-pack' || $service eq 'git-receive-pack') { |
... | ... |
@@ -65,7 +67,7 @@ |
65 | 67 |
or die "Can't close pipe for @cmd:$!"; |
66 | 68 |
|
67 | 69 |
my $content_type = 'text/plain; charset=UTF-8'; |
68 |
- my $rep_home = app->git->rep_home; |
|
70 |
+ my $rep_home = $api->git->rep_home; |
|
69 | 71 |
my $file = "$rep_home/$user/$project.git/info/refs"; |
70 | 72 |
if (-f $file) { |
71 | 73 |
my $asset = Mojo::Asset::File->new(path => $file); |
... | ... |
@@ -3,11 +3,13 @@ |
3 | 3 |
use Symbol (); |
4 | 4 |
use IO::Select (); |
5 | 5 |
|
6 |
+ my $api = gitprep_api; |
|
7 |
+ |
|
6 | 8 |
my $service = param('service'); |
7 | 9 |
my $user = param('user'); |
8 | 10 |
my $project = param('project'); |
9 | 11 |
|
10 |
- my $git = app->git; |
|
12 |
+ my $git = $api->git; |
|
11 | 13 |
|
12 | 14 |
my $rep_dir = $git->rep($user, $project); |
13 | 15 |
my @cmd = $git->cmd($user, $project, $service, '--stateless-rpc', $rep_dir); |
... | ... |
@@ -1,4 +1,6 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
my $path = param('Path'); |
3 | 5 |
my $user = param('user'); |
4 | 6 |
my $project = param('project'); |
... | ... |
@@ -31,7 +33,7 @@ |
31 | 33 |
$content_type = 'application/x-git-packed-objects-toc'; |
32 | 34 |
} |
33 | 35 |
|
34 |
- my $rep_home = app->git->rep_home; |
|
36 |
+ my $rep_home = $api->git->rep_home; |
|
35 | 37 |
my $file = "$rep_home/$user/$project.git/$path"; |
36 | 38 |
if (-f $file) { |
37 | 39 |
my $asset = Mojo::Asset::File->new(path => $file); |
... | ... |
@@ -5,7 +5,7 @@ |
5 | 5 |
my $api = gitprep_api; |
6 | 6 |
|
7 | 7 |
# Git |
8 |
- my $git = $self->app->git; |
|
8 |
+ my $git = $api->git; |
|
9 | 9 |
|
10 | 10 |
# Parameters |
11 | 11 |
my $user = param('user'); |
... | ... |
@@ -8,7 +8,7 @@ |
8 | 8 |
my $page = param('page') || 1; |
9 | 9 |
|
10 | 10 |
# Git |
11 |
- my $git = $self->app->git; |
|
11 |
+ my $git = $api->git; |
|
12 | 12 |
|
13 | 13 |
# Ref names |
14 | 14 |
my $limit = app->config->{basic}{tags_limit}; |
... | ... |
@@ -3,7 +3,7 @@ |
3 | 3 |
my $api = gitprep_api; |
4 | 4 |
|
5 | 5 |
# Git |
6 |
- my $git = app->git; |
|
6 |
+ my $git = $api->git; |
|
7 | 7 |
|
8 | 8 |
# Parameters |
9 | 9 |
my $user = param('user'); |
... | ... |
@@ -1,4 +1,6 @@ |
1 | 1 |
<% |
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
2 | 4 |
# Redirect for project delete |
3 | 5 |
if (my $deleted_project = param('deleted_project')) { |
4 | 6 |
flash('deleted_project', $deleted_project); |
... | ... |
@@ -16,7 +18,7 @@ |
16 | 18 |
my $projects = app->manager->projects($user); |
17 | 19 |
my $reps = []; |
18 | 20 |
for my $project (@$projects) { |
19 |
- my $rep = app->git->repository($user, $project->{name}) || {none => 1}; |
|
21 |
+ my $rep = $api->git->repository($user, $project->{name}) || {none => 1}; |
|
20 | 22 |
$rep->{name} = $project->{name}; |
21 | 23 |
push @$reps, $rep; |
22 | 24 |
} |