add FAQ large repository can...
|
1 |
# 環境変数 |
2 | ||
copy gitweblite soruce code
|
3 |
use 5.008007; |
renamed gitpub to gitprep
|
4 |
package Gitprep; |
copy gitweblite soruce code
|
5 |
use Mojo::Base 'Mojolicious'; |
cleanup
|
6 | |
7 |
use Carp 'croak'; |
|
added start page
|
8 |
use DBIx::Custom; |
little more secure login
|
9 |
use Gitprep::API; |
cleanup
|
10 |
use Gitprep::Git; |
fixed tags page paging bug a...
|
11 |
use Gitprep::Manager; |
added RepManager rename feat...
|
12 |
use Scalar::Util 'weaken'; |
cleanup
|
13 |
use Validator::Custom; |
copy gitweblite soruce code
|
14 | |
Digest::SHA loading to Mojo:...
|
15 |
# Digest::SHA loading to Mojo::Util if not loaded |
16 |
{ |
|
17 |
package Mojo::Util; |
|
18 |
eval {require Digest::SHA; import Digest::SHA qw(sha1 sha1_hex)}; |
|
19 |
} |
|
20 | ||
version up and add descripti...
|
21 |
our $VERSION = '1.04'; |
cleanup
|
22 | |
added start page
|
23 |
has 'dbi'; |
revert encoding support
|
24 |
has 'git'; |
added RepManager rename feat...
|
25 |
has 'manager'; |
rename validator to vc to up...
|
26 |
has 'vc'; |
revert encoding support
|
27 | |
28 |
use constant BUFFER_SIZE => 8192; |
|
add /info/refs request
|
29 | |
copy gitweblite soruce code
|
30 |
sub startup { |
31 |
my $self = shift; |
|
32 |
|
|
cleanup
|
33 |
# Config file |
update Mojolicious and added...
|
34 |
$self->plugin('INIConfig', {ext => 'conf'}); |
35 |
|
|
cleanup
|
36 |
# Config file for developper |
add need_login_always_option
|
37 |
unless ($ENV{GITPREP_NO_MYCONFIG}) { |
38 |
my $my_conf_file = $self->home->rel_file('gitprep.my.conf'); |
|
39 |
$self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file; |
|
40 |
} |
|
update Mojolicious and added...
|
41 |
|
cleanup
|
42 |
# Listen |
copy gitweblite soruce code
|
43 |
my $conf = $self->config; |
cleanup
|
44 |
my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020']; |
45 |
$listen = [split /,/, $listen] unless ref $listen eq 'ARRAY'; |
|
fixed listen bug
|
46 |
$conf->{hypnotoad}{listen} = $listen; |
copy gitweblite soruce code
|
47 |
|
revert encoding support
|
48 |
# Git |
renamed gitpub to gitprep
|
49 |
my $git = Gitprep::Git->new; |
cleanup
|
50 |
my $git_bin |
51 |
= $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin; |
|
fix mini bug
|
52 |
if (!$git_bin || ! -e $git_bin) { |
53 |
$git_bin ||= ''; |
|
cleanup
|
54 |
my $error = "Can't detect or found git command ($git_bin)." |
55 |
. " set git_bin in gitprep.conf"; |
|
fixed git_bin not found bug
|
56 |
$self->log->error($error); |
57 |
croak $error; |
|
58 |
} |
|
improve code structures
|
59 |
$git->bin($git_bin); |
revert encoding support
|
60 |
|
61 |
# Repository Manager |
|
62 |
my $manager = Gitprep::Manager->new(app => $self); |
|
63 |
weaken $manager->{app}; |
|
64 |
$self->manager($manager); |
|
65 |
|
|
fixed git_bin not found bug
|
66 |
# Repository home |
cleanup
|
67 |
my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep'); |
revert encoding support
|
68 |
$git->rep_home($rep_home); |
added create repository feat...
|
69 |
unless (-d $rep_home) { |
70 |
mkdir $rep_home |
|
71 |
or croak "Can't create directory $rep_home: $!"; |
|
72 |
} |
|
improve code structures
|
73 |
$self->git($git); |
cleanup
|
74 |
|
revert encoding support
|
75 |
# Added public path |
76 |
# push @{$self->static->paths}, $rep_home; |
|
cleanup
|
77 |
|
improved create repository f...
|
78 |
# DBI |
added test
|
79 |
my $db_file = $ENV{GITPREP_DB_FILE} |
80 |
|| $self->home->rel_file('data/gitprep.db'); |
|
improved create repository f...
|
81 |
my $dbi = DBIx::Custom->connect( |
82 |
dsn => "dbi:SQLite:database=$db_file", |
|
83 |
connector => 1, |
|
added original_pid column
|
84 |
option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1} |
improved create repository f...
|
85 |
); |
86 |
$self->dbi($dbi); |
|
87 |
|
|
cleanup
|
88 |
# Database file permision |
fixed database file permissi...
|
89 |
if (my $user = $self->config->{hypnotoad}{user}) { |
90 |
my $uid = (getpwnam $user)[2]; |
|
91 |
chown $uid, -1, $db_file; |
|
92 |
} |
|
93 |
if (my $group = $self->config->{hypnotoad}{group}) { |
|
94 |
my $gid = (getgrnam $group)[2]; |
|
95 |
chown -1, $gid, $db_file; |
|
96 |
} |
|
97 |
|
|
added tab_index columns
|
98 |
# Setup database |
99 |
$self->manager->setup_database; |
|
improved create repository f...
|
100 |
|
101 |
# Model |
|
102 |
my $models = [ |
|
103 |
{table => 'user', primary_key => 'id'}, |
|
added original_pid column
|
104 |
{table => 'project', primary_key => ['user_id', 'name']}, |
add collaborator register lo...
|
105 |
{table => 'number', primary_key => 'key'}, |
106 |
{table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']} |
|
improved create repository f...
|
107 |
]; |
108 |
$dbi->create_model($_) for @$models; |
|
109 | ||
110 |
# Validator |
|
rename validator to vc to up...
|
111 |
my $vc = Validator::Custom->new; |
112 |
$self->vc($vc); |
|
113 |
$vc->register_constraint( |
|
added project delete feature
|
114 |
user_name => sub { |
115 |
my $value = shift; |
|
116 |
|
|
117 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
118 |
}, |
|
119 |
project_name => sub { |
|
120 |
my $value = shift; |
|
121 |
|
|
122 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/ |
|
123 |
} |
|
124 |
); |
|
improved create repository f...
|
125 |
|
fixed receive pack bug and a...
|
126 |
# Basic auth plugin |
127 |
$self->plugin('BasicAuth'); |
|
added admin user tests
|
128 | |
cleanup
|
129 |
# Routes |
Auto Route system catch up w...
|
130 |
sub template { |
131 |
my $template = shift; |
|
132 |
|
|
cleanup
|
133 |
return sub { shift->render($template, , 'mojo.maybe' => 1) }; |
Auto Route system catch up w...
|
134 |
} |
135 |
|
|
added login page
|
136 |
{ |
cleanup
|
137 |
my $r = $self->routes; |
138 | ||
139 |
# DBViewer(only development) |
|
140 |
if ($self->mode eq 'development') { |
|
141 |
eval { |
|
142 |
$self->plugin( |
|
143 |
'DBViewer', |
|
144 |
dsn => "dbi:SQLite:database=$db_file" |
|
145 |
); |
|
146 |
}; |
|
added reset password feature
|
147 |
} |
added AutoRoute plugin
|
148 |
|
cleanup
|
149 |
# Auto route |
cleanup many pages
|
150 |
{ |
cleanup
|
151 |
my $r = $r->under(sub { |
152 |
my $self = shift; |
|
153 |
|
|
154 |
my $api = $self->gitprep_api; |
|
155 |
|
|
add need_login_always_option
|
156 |
# Authentication |
cleanup
|
157 |
{ |
158 |
my $path = $self->req->url->path->parts->[0] || ''; |
|
add need_login_always_option
|
159 |
|
160 |
# Admin |
|
cleanup
|
161 |
if ($path eq '_admin' && !$api->logined_admin) { |
162 |
$self->redirect_to('/'); |
|
163 |
return; |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
return 1; |
|
168 |
}); |
|
add need_login_always_option
|
169 |
|
170 |
# Auto routes |
|
cleanup
|
171 |
$self->plugin('AutoRoute', route => $r); |
improved repository page des...
|
172 | |
add need_login_always_option
|
173 |
# Custom routes |
cleanup
|
174 |
{ |
add need_login_always_option
|
175 |
my $id_re = qr/[a-zA-Z0-9_-]+/; |
cleanup
|
176 |
|
add need_login_always_option
|
177 |
# User |
178 |
my $r = $r->route('/:user', user => $id_re); |
|
179 |
{ |
|
180 |
# Home |
|
181 |
$r->get('/' => template '/user'); |
|
182 |
|
|
183 |
# Settings |
|
184 |
$r->get('/_settings' => template '/user-settings'); |
|
185 |
} |
|
add /info/refs request
|
186 | |
187 |
# Smart HTTP |
|
188 |
{ |
|
189 |
my $r = $r->route('/(:project).git', project => $id_re); |
|
190 |
|
|
fixed receive pack bug and a...
|
191 |
{ |
192 |
my $r = $r->under(sub { |
|
193 |
my $self = shift; |
|
194 |
|
|
cleanup
|
195 |
my $api = $self->gitprep_api; |
complete private repository ...
|
196 |
my $user = $self->param('user'); |
197 |
my $project = $self->param('project'); |
|
198 |
my $private = $self->app->manager->is_private_project($user, $project); |
|
cleanup
|
199 |
|
fixed receive pack bug and a...
|
200 |
# Basic auth when push request |
201 |
my $service = $self->param('service') || ''; |
|
complete private repository ...
|
202 |
if ($service eq 'git-receive-pack' || $private) { |
fixed receive pack bug and a...
|
203 |
|
204 |
$self->basic_auth("Git Area", sub { |
|
complete private repository ...
|
205 |
my ($auth_user, $auth_password) = @_; |
fix warnings
|
206 |
$auth_user = '' unless defined $auth_user; |
207 |
$auth_password = '' unless defined $auth_password; |
|
fixed receive pack bug and a...
|
208 |
|
complete collaborator featur...
|
209 |
my $is_valid = |
210 |
($user eq $auth_user || $api->is_collaborator($user, $project, $auth_user)) |
|
211 |
&& $api->check_user_and_password($auth_user, $auth_password); |
|
fixed receive pack bug and a...
|
212 |
|
213 |
return $is_valid; |
|
214 |
}); |
|
215 |
} |
|
216 |
else { |
|
217 |
return 1; |
|
218 |
} |
|
219 |
}); |
|
220 |
|
|
221 |
# /info/refs |
|
222 |
$r->get('/info/refs' => template 'smart-http/info-refs'); |
|
223 |
|
|
224 |
# /git-upload-pack or /git-receive-pack |
|
225 |
$r->any('/git-(:service)' |
|
226 |
=> [service => qr/(?:upload-pack|receive-pack)/] |
|
227 |
=> template 'smart-http/service' |
|
228 |
); |
|
229 |
|
|
230 |
# Static file |
|
231 |
$r->get('/(*Path)' => template 'smart-http/static'); |
|
232 |
} |
|
add /info/refs request
|
233 |
} |
234 |
|
|
add need_login_always_option
|
235 |
# Project |
236 |
{ |
|
237 |
my $r = $r->route('/:project', project => $id_re); |
|
238 |
|
|
add private reporitory featu...
|
239 |
{ |
240 |
my $r = $r->under(sub { |
|
241 |
my $self = shift; |
|
242 |
|
|
cleanup
|
243 |
# API |
244 |
my $api = $self->gitprep_api; |
|
improve code structures
|
245 |
|
246 |
# Private |
|
revert encoding support
|
247 |
my $user = $self->param('user'); |
248 |
my $project = $self->param('project'); |
|
add private reporitory featu...
|
249 |
my $private = $self->app->manager->is_private_project($user, $project); |
250 |
if ($private) { |
|
complete collaborator featur...
|
251 |
if ($api->can_access_private_project($user, $project)) { |
add private reporitory featu...
|
252 |
return 1; |
253 |
} |
|
254 |
else { |
|
255 |
$self->render('private'); |
|
256 |
return 0; |
|
257 |
} |
|
258 |
} |
|
259 |
else { |
|
260 |
return 1; |
|
261 |
} |
|
262 |
}); |
|
263 |
|
|
264 |
# Home |
|
265 |
$r->get('/' => template '/project'); |
|
266 |
|
|
267 |
# Commit |
|
268 |
$r->get('/commit/*diff' => template '/commit'); |
|
269 |
|
|
270 |
# Commits |
|
271 |
$r->get('/commits/*rev_file' => template '/commits'); |
|
272 |
|
|
273 |
# Branches |
|
274 |
$r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches'); |
|
added feature that you see p...
|
275 | |
add private reporitory featu...
|
276 |
# Tags |
277 |
$r->get('/tags' => template '/tags'); |
|
improved network page
|
278 | |
add private reporitory featu...
|
279 |
# Tree |
280 |
$r->get('/tree/*rev_dir' => template '/tree'); |
|
281 |
|
|
282 |
# Blob |
|
283 |
$r->get('/blob/*rev_file' => template '/blob'); |
|
284 |
|
|
285 |
# Sub module |
|
286 |
$r->get('/submodule/*rev_file' => template '/submodule'); |
|
add blame method
|
287 | |
add private reporitory featu...
|
288 |
# Raw |
289 |
$r->get('/raw/*rev_file' => template '/raw'); |
|
add blame method
|
290 | |
add private reporitory featu...
|
291 |
# Blame |
292 |
$r->get('/blame/*rev_file' => template '/blame'); |
|
293 |
|
|
294 |
# Archive |
|
295 |
$r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar'); |
|
296 |
$r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' ); |
|
297 |
|
|
298 |
# Compare |
|
299 |
$r->get('/compare/(*rev1)...(*rev2)' => template '/compare'); |
|
300 |
|
|
301 |
# Settings |
|
302 |
$r->any('/settings' => template '/settings'); |
|
303 |
|
|
add collaboration page
|
304 |
# Collaboration |
305 |
$r->any('/settings/collaboration' => template '/settings/collaboration'); |
|
306 |
|
|
add private reporitory featu...
|
307 |
# Fork |
308 |
$r->any('/fork' => template '/fork'); |
|
cleanup
|
309 | |
add private reporitory featu...
|
310 |
# Network |
311 |
$r->get('/network' => template '/network'); |
|
cleanup
|
312 | |
add private reporitory featu...
|
313 |
# Network Graph |
314 |
$r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph'); |
|
add pull page design
|
315 | |
add private reporitory featu...
|
316 |
# Import branch |
317 |
$r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch'); |
|
318 |
|
|
319 |
# Get branches and tags |
|
320 |
$r->get('/api/revs' => template '/api/revs'); |
|
321 |
} |
|
add need_login_always_option
|
322 |
} |
cleanup
|
323 |
} |
added AutoRoute plugin
|
324 |
} |
325 |
} |
|
added admin user tests
|
326 | |
327 |
# Helper |
|
328 |
{ |
|
329 |
# API |
|
330 |
$self->helper(gitprep_api => sub { Gitprep::API->new(shift) }); |
|
331 |
} |
|
added reverse proxy path_dep...
|
332 |
|
added AutoRoute plugin
|
333 |
# Reverse proxy support |
added reverse proxy path_dep...
|
334 |
my $reverse_proxy_on = $self->config->{reverse_proxy}{on}; |
335 |
my $path_depth = $self->config->{reverse_proxy}{path_depth}; |
|
336 |
if ($reverse_proxy_on) { |
|
337 |
$ENV{MOJO_REVERSE_PROXY} = 1; |
|
338 |
if ($path_depth) { |
|
339 |
$self->hook('before_dispatch' => sub { |
|
340 |
my $self = shift; |
|
341 |
for (1 .. $path_depth) { |
|
342 |
my $prefix = shift @{$self->req->url->path->parts}; |
|
343 |
push @{$self->req->url->base->path->parts}, $prefix; |
|
344 |
} |
|
345 |
}); |
|
added AutoRoute plugin
|
346 |
} |
added reverse proxy path_dep...
|
347 |
} |
cleanup
|
348 |
|
349 |
# Smart HTTP Buffer size |
|
350 |
$ENV{GITPREP_SMART_HTTP_BUFFER_SIZE} ||= 8192; |
|
copy gitweblite soruce code
|
351 |
} |
352 | ||
353 |
1; |