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