Allow the model to be user defined.
[catagits/Gitalist.git] / lib / Gitalist.pm
CommitLineData
89de6a33 1package Gitalist;
42fe5d11 2use Moose;
775e96e0 3BEGIN { require 5.008006; }
e33993c9 4use Catalyst::Runtime 5.90006;
775e96e0 5use namespace::autoclean;
89de6a33 6
42fe5d11 7extends 'Catalyst';
89de6a33 8
43d4a724 9use Catalyst qw/
89de6a33 10 ConfigLoader
fac828e0 11 Unicode::Encoding
d5cc37a4 12 Static::Simple
fac828e0 13 StackTrace
16bdb8df 14 SubRequest
fac828e0 15/;
61b56ed6 16
1ff94f74 17our $VERSION = '0.003006';
775e96e0 18$VERSION = eval $VERSION;
89de6a33 19
d3feefcf 20__PACKAGE__->config(
61b56ed6 21 name => 'Gitalist',
22 default_view => 'Default',
7bf1a6f5 23 default_model => 'CollectionOfRepos',
e77519b1 24 use_request_uri_for_path => 1,
25 disable_component_resolution_regex_fallback => 1,
d3feefcf 26);
89de6a33 27
89de6a33 28__PACKAGE__->setup();
29
319537bf 30after prepare_path => sub {
31 my ($ctx) = @_;
f41fc741 32 my $path = $ctx->req->uri->path;
319537bf 33 if ($ctx->req->param('a')) {
f41fc741 34 $ctx->req->uri->path("/legacy$path");
35 }
36
37 if($path =~ s/[.]json$// && $ctx->req->content_type eq 'application/json') {
38 $ctx->req->uri->path($path);
319537bf 39 }
40};
41
4df2f62f 42around uri_for => sub {
43 my ($orig, $c) = (shift, shift);
df49ca46 44 my $uri = $c->$orig(@_);
74d26472 45 $$uri =~ tr[&][;] if defined $uri;
4df2f62f 46 return $uri;
47};
61b56ed6 48
906a2dd2 49sub uri_with {
50 my ($self, @args) = @_;
51 my $uri = $self->request->uri_with(@args);
52 # Wow this awful.
53 $uri =~ s[/fragment\b][];
54 return $uri;
55}
56
775e96e0 571;
58
59__END__
60
8004a936 61=encoding UTF-8
62
89de6a33 63=head1 NAME
64
775e96e0 65Gitalist - A modern git web viewer
89de6a33 66
67=head1 SYNOPSIS
68
3a7cd273 69 perl script/gitalist_server.pl --repo_dir /home/me/code/git
89de6a33 70
b6d010e1 71=head1 INSTALL
72
73As Gitalist follows the usual Perl module format the usual approach
8004a936 74for installation should work, e.g.:
b6d010e1 75
3a7cd273 76 perl Makefile.PL
77 make
78 make test
79 make install
b6d010e1 80
63f34424 81or
82
3a7cd273 83 cpan -i Gitalist
63f34424 84
8004a936 85You can also L<check Gitalist out from its git repository|/"GETTING GITALIST">
86and run it, in this case you'll additionally need the author modules,
87but no configuration will be needed as it will default to looking
63f34424 88for repositories the directory above the checkout.
b6d010e1 89
89de6a33 90=head1 DESCRIPTION
91
8004a936 92Gitalist is a web frontend for git repositories based on
93L<gitweb.cgi|https://git.wiki.kernel.org/index.php/Gitweb> and backed by
94L<Catalyst>.
b6d010e1 95
96=head2 History
97
8004a936 98This project started off as an attempt to port I<gitweb.cgi> to a
b6d010e1 99Catalyst app in a piecemeal fashion. As it turns out, thanks largely
8004a936 100to Florian Ragwitz's earlier effort, it was easier to use I<gitweb.cgi>
b6d010e1 101as a template for building a new Catalyst application.
89de6a33 102
69175e49 103=head1 GETTING GITALIST
104
105You can install Gitalist from CPAN in the usual way:
106
107 cpan -i Gitalist
108
109Alternatively, you can get Gitalist using git.
110
111The canonical repository for the master branch is:
112
1d46f550 113 git://git.shadowcat.co.uk/catagits/Gitalist.git
69175e49 114
8004a936 115Gitalist is also mirrored to GitHub at L<https://github.com/broquaint/Gitalist>,
116and a number of people have active forks
69175e49 117with branches and/or new features in the master branch.
118
ccb79ac8 119=head1 BOOTSTRAPPING
120
121As of C<0.002001> Gitalist can now be bootstrapped to run out of its
122own directory by installing its prerequisites locally with the help of
123L<local::lib>. So instead of installing the prerequisites to the
124system path with CPAN they are installed under the Gitalist directory.
125
8004a936 126To do this clone Gitalist from the L<Shadowcat repository mentioned
127above|/"GETTING GITALIST"> or grab a snapshot from broquaint's GitHub repository:
ccb79ac8 128
8004a936 129 https://github.com/broquaint/Gitalist/downloads
ccb79ac8 130
131With the source acquired and unpacked run the following from within the
132Gitalist directory:
133
e2c6e7c1 134 perl script/bootstrap.pl
ccb79ac8 135
136This will install the necessary modules for the build process which in
137turn installs the prerequisites locally.
138
8004a936 139B<NB:> The relevant bootstrap scripts aren't available in the CPAN dist
e2c6e7c1 140as the bootstrap scripts should not be installed.
141
69175e49 142=head1 INITIAL CONFIGURATION
143
144Gitalist is configured using L<Catalyst::Plugin::Configloader>. The supplied sample
145configuration is in L<Config::General> format, however it is possible to configure
146Gitalist using other config file formats (such as YAML) if you prefer.
147
148=head2 WHEN CHECKING GITALIST OUT OF GIT
149
150Gitalist from git includes a minimal C<gitalist_local.conf>, which sets the repository
151directory to one directory higher than the Gitalist repository.
152
153This means that if you check Gitalist out next to your other git checkouts, then starting
154the demo server needs no parameters at all:
155
3a7cd273 156 Gitalist [master]$ perl script/gitalist_server.pl
69175e49 157 You can connect to your server at http://localhost:3000
158
159=head2 FOR CPAN INSTALLS
63f34424 160
161Gitalist can be supplied with a config file by setting the C<< GITALIST_CONFIG >>
162environment variable to point to a configuration file.
163
69175e49 164If you install Gitalist from CPAN, a default configuration is installed along with gitalist,
165which is complete except for a repository directory. You can get a copy of this configuration
166by running:
63f34424 167
168 cp `perl -Ilib -MGitalist -e'print Gitalist->path_to("gitalist.conf")'` gitalist.conf
169
8004a936 170You can then edit this configuration, adding a C<repo_dir> path and customising
171other settings as desired.
69175e49 172
173You can then start the Gitalist demo server by setting C<< GITALIST_CONFIG >>. For example:
174
175 GITALIST_CONFIG=/usr/local/etc/gitalist.conf gitalist_server.pl
63f34424 176
177Alternatively, if you only want to set a repository directory and are otherwise happy with
1d46f550 178the default configuration, then you can set the C<< GITALIST_REPO_DIR >> environment
3d0e045e 179variable, or pass the C<< --repo_dir >> flag to any of the scripts.
63f34424 180
1d46f550 181 GITALIST_REPO_DIR=/home/myuser/code/git gitalist_server.pl
3d0e045e 182 gitalist_server.pl --repo_dir home/myuser/code/git
69175e49 183
1d46f550 184The C<< GITALIST_REPO_DIR >> environment variable will override the repository directory set
3d0e045e 185in configuration, and will itself be overridden by he C<< --repo_dir >> flag.
63f34424 186
69175e49 187=head1 RUNNING
188
189Once you have followed the instructions above to install and configure Gitalist, you may want
190to run it in a more production facing environment than using the single threaded developement
191server.
192
193The recommended deployment method for Gitalist is FastCGI, although Gitalist can also be run
8004a936 194under L<mod_perl|https://perl.apache.org/> or as pure Perl with L<Catalyst::Engine::PreFork>.
69175e49 195
196Assuming that you have installed Gitalist's dependencies into a L<local::lib>, and you
197are running from a git checkout, adding a trivial FCGI script as C<script/gitalist.fcgi>
198(this file is specifically in C<.gitignore> so you can have your own copy):
199
200 #!/bin/sh
69175e49 201 exec /home/t0m/public_html/Gitalist/script/gitalist_fastcgi.pl
202
203This example can be seen live here:
204
f9d6e4f1 205 http://example.gitalist.com
8004a936 206
cc02cf5a 207=head2 Plack
208
209If you would like to run Gitalist under L<Plack> then one need only
210make use of L<plackup|search.cpan.org/perldoc?plackup> and the
211C<.psgi> found under C<scripts/>:
212
213 plackup script/gitalist_app.psgi
214
5111a8ab 215=head1 CONFIGURATION
216
217The Gitalist config is loaded with L<Catalyst::Plugin::ConfigLoader>
218and the available config options are:
219
225bd36d 220=over
221
222=item no_gravatars
223
224If true don't display gravatars. May be desirable if you are worried about
225leaking repo names via the browser referer headers.
226
227=back
228
5111a8ab 229=head2 Model::CollectionOfRepos
230
231=over
232
5111a8ab 233=item repo_dir
234
235A directory containing the directories to show.
236
07ee9dc1 237=item repos
238
239A list of directories containing repositories to show.
5111a8ab 240
241=item search_recursively
242
243A boolean indicating whether to always search recursively for
244repositories within C<repo_dir>.
245
246=item whitelist
247
248Path a file containing a list of repositories that can be shown. Each
249line in the file will represent the name of a repo to show e.g
250
251 Gitalist
252 some-bare-repo.git
253
254This is compatible with C<gitweb>'s C<projects.list>.
255
256=item export_ok
257
258If provided every must contain a file of the same name to be
259visible. This is similar to C<gitweb>'s functionality.
260
e33993c9 261=item class
262
263If you want a different way of surfacing repositories you can use your
264own model (i.e something that composes
265L<Gitalist::Git::CollectionOfRepositories>) and specify the class name with
266this config option.
267
268=item args
269
270Any additional arguments to be passed into the Model constructor, only
271of use when used in conjunction with C<class> (see above).
272
5111a8ab 273=back
274
275=head2 paging
276
277=over
278
279=item log
280
07ee9dc1 281The number of commits to show in the summary, shortlog and longlog views.
5111a8ab 282
283=back
284
321b3fbf 285=head2 FASTCGI
8004a936 286
287Running Gitalist in FastCGI mode requires a webserver with FastCGI
288support (such as apache with L<mod_fcgi|http://www.fastcgi.com/drupal/node/3>
289or L<mod_fcgid|https://httpd.apache.org/mod_fcgid/>). Below is a sample
290configuration using Apache2 with mod_fcgid in a dynamic configuration
291(as opposed to static or standalone mode). More information on these modes and
292their configuration can be found at L<Catalyst::Engine::FastCGI/"Standalone server mode">.
293
294In Apache's F<mime.conf>, add C<AddHandler fcgid-script .fcgi>
295(or C<AddHandler fastcgi-script .fcgi> for mod_fcgi).
296
297And a quick VirtualHost configuration:
298
299 <VirtualHost *:80>
300 ServerName gitalist.yourdomain.com
301 DocumentRoot /path/to/gitalist.fcgi
302 <Directory "/path/to/gitalist.fcgi">
57f9f654 303 AllowOverride all
304 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
305 Order allow,deny
306 Allow from all
8004a936 307 </Directory>
321b3fbf 308
309 # Tell Apache this is a FastCGI application
310 <Files gitalist.fcgi>
57f9f654 311 #change the below to fastcgi-script if using mod_fcgi
321b3fbf 312 SetHandler fcgid-script
313 </Files>
8004a936 314 </VirtualHost>
315
316Now to access your Gitalist instance, you'll go to
317C<gitalist.yourdomain.com/gitalist.fcgi/> (B<do not forget that trailing> C</>).
318If you'd like a different URL, of course, you'll likely want to use
319L<mod_rewrite|https://httpd.apache.org/docs/mod/mod_rewrite.html> or equivalent.
320
321If you find the need to do some troubleshooting, you can call
322C<http://url_to_gitalist.fcgi?dump_info=1> and/or add export C<GITALIST_DEBUG=1>
323to the top of your F<gitalist.fcgi> file (just below the shebang line).
324
b7b5f98e 325=head2 Apache config
326
327Apache will refuse C<%2F> in Gitalist URLs unless configured otherwise. Make
328sure C<AllowEncodedSlashes On> is in your F<httpd.conf> file in order for
329this to run smoothly.
330
331To have the static content served statically by Apache, instead of
332Gitalist, then add something like following line to your F<httpd.conf>:
333
334 Alias /static /usr/local/share/perl/5.10.1/Gitalist/root/static
67388737 335
69175e49 336=head1 CONTRIBUTING
337
338Patches are welcome, please feel free to fork on github and send pull requests, send patches
339from git format-patch to the bug tracker, or host your own copy of gitalist somewhere and
340ask us to pull from it.
341
342=head1 SUPPORT
343
344Gitalist has an active irc community in C<#gitalist> on irc.perl.org, please feel free to stop
345by and ask questions, report bugs or installation issues or generally for a chat about where
346we plan to go with the project.
347
89de6a33 348=head1 SEE ALSO
349
b6d010e1 350L<Gitalist::Controller::Root>
351
44a9ed75 352L<Gitalist::Git::Repository>
b6d010e1 353
354L<Catalyst>
89de6a33 355
42fe5d11 356=head1 AUTHORS AND COPYRIGHT
89de6a33 357
42fe5d11 358 Catalyst application:
8004a936 359 © 2009 Venda Ltd and Dan Brook <broq@cpan.org>
360 © 2009, Tom Doran <bobtfish@bobtfish.net>
361 © 2009, Zac Stevens <zts@cryptocracy.com>
42fe5d11 362
363 Original gitweb.cgi from which this was derived:
8004a936 364 © 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
365 © 2005, Christian Gierke
89de6a33 366
b6d010e1 367 Model based on http://github.com/rafl/gitweb
8004a936 368 © 2008, Florian Ragwitz
89de6a33 369
b6d010e1 370=head1 LICENSE
42fe5d11 371
b6d010e1 372Licensed under GNU GPL v2