2012-03-16 05:29:45 +01:00
|
|
|
package Gitolite::Rc;
|
|
|
|
|
|
|
|
# everything to do with 'rc'. Also defines some 'constants'
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
@EXPORT = qw(
|
|
|
|
%rc
|
|
|
|
glrc
|
|
|
|
query_rc
|
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
$ADC_CMD_ARGS_PATT
|
2012-03-16 05:29:45 +01:00
|
|
|
$REF_OR_FILENAME_PATT
|
|
|
|
$REPONAME_PATT
|
|
|
|
$REPOPATT_PATT
|
|
|
|
$USERNAME_PATT
|
|
|
|
);
|
|
|
|
|
|
|
|
use Exporter 'import';
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
use Gitolite::Common;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
our %rc;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
# variables that are/could be/should be in the rc file
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
$rc{GL_BINDIR} = $ENV{GL_BINDIR};
|
|
|
|
$rc{GL_ADMIN_BASE} = "$ENV{HOME}/.gitolite";
|
|
|
|
$rc{GL_REPO_BASE} = "$ENV{HOME}/repositories";
|
|
|
|
|
|
|
|
# variables that should probably never be changed
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
$ADC_CMD_ARGS_PATT = qr(^[0-9a-zA-Z._\@/+:-]*$);
|
2012-03-16 05:29:45 +01:00
|
|
|
$REF_OR_FILENAME_PATT = qr(^[0-9a-zA-Z][0-9a-zA-Z._\@/+ :,-]*$);
|
|
|
|
$REPONAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@/+-]*$);
|
|
|
|
$REPOPATT_PATT = qr(^\@?[0-9a-zA-Z[][\\^.$|()[\]*+?{}0-9a-zA-Z._\@/,-]*$);
|
|
|
|
$USERNAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$);
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
my $current_data_version = "3.0";
|
|
|
|
|
|
|
|
my $rc = glrc('filename');
|
|
|
|
do $rc if -r $rc;
|
2012-03-10 16:00:14 +01:00
|
|
|
_die "$rc seems to be for older gitolite" if defined($GL_ADMINDIR);
|
2012-03-16 05:29:45 +01:00
|
|
|
# let values specified in rc file override our internal ones
|
|
|
|
@rc{ keys %RC } = values %RC;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
my $glrc_default_text = '';
|
|
|
|
{
|
|
|
|
local $/ = undef;
|
|
|
|
$glrc_default_text = <DATA>;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub glrc {
|
|
|
|
my $cmd = shift;
|
|
|
|
if ( $cmd eq 'default-filename' ) {
|
2012-03-10 14:26:29 +01:00
|
|
|
trace( 1, "..should happen only on first run" );
|
2012-03-16 05:29:45 +01:00
|
|
|
return "$ENV{HOME}/.gitolite.rc";
|
|
|
|
} elsif ( $cmd eq 'default-text' ) {
|
2012-03-10 14:26:29 +01:00
|
|
|
trace( 1, "..should happen only on first run" );
|
2012-03-16 05:29:45 +01:00
|
|
|
return $glrc_default_text if $glrc_default_text;
|
|
|
|
_die "rc file default text not set; this should not happen!";
|
|
|
|
} elsif ( $cmd eq 'filename' ) {
|
|
|
|
# where is the rc file?
|
2012-03-10 14:26:29 +01:00
|
|
|
trace(4);
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
# search $HOME first
|
|
|
|
return "$ENV{HOME}/.gitolite.rc" if -f "$ENV{HOME}/.gitolite.rc";
|
2012-03-10 14:26:29 +01:00
|
|
|
trace( 2, "$ENV{HOME}/.gitolite.rc not found" );
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
# XXX for fedora, we can add the following line, but I would really prefer
|
|
|
|
# if ~/.gitolite.rc on each $HOME was just a symlink to /etc/gitolite.rc
|
|
|
|
# XXX return "/etc/gitolite.rc" if -f "/etc/gitolite.rc";
|
|
|
|
|
|
|
|
return '';
|
|
|
|
} elsif ( $cmd eq 'current-data-version' ) {
|
|
|
|
return $current_data_version;
|
|
|
|
} else {
|
|
|
|
_die "unknown argument to glrc: $cmd";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
2012-03-10 14:26:29 +01:00
|
|
|
# implements 'gitolite query-rc'
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
=for usage
|
|
|
|
|
|
|
|
Usage: gitolite query-rc -a
|
2012-03-11 17:15:07 +01:00
|
|
|
gitolite query-rc [-n] <list of rc variables>
|
|
|
|
|
|
|
|
-a print all variables and values
|
|
|
|
-n do not append a newline
|
2012-03-10 14:26:29 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
gitolite query-rc GL_ADMIN_BASE GL_UMASK
|
|
|
|
# prints "/home/git/.gitolite<tab>0077" or similar
|
|
|
|
|
|
|
|
gitolite query-rc -a
|
|
|
|
# prints all known variables and values, one per line
|
|
|
|
=cut
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
my $all = 0;
|
2012-03-11 17:15:07 +01:00
|
|
|
my $nonl = 0;
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
sub query_rc {
|
2012-03-10 14:26:29 +01:00
|
|
|
trace( 1, "rc file not found; default should be " . glrc('default-filename') ) if not glrc('filename');
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
my @vars = args();
|
|
|
|
|
|
|
|
no strict 'refs';
|
|
|
|
|
2012-03-11 17:15:07 +01:00
|
|
|
if ( $all ) {
|
2012-03-10 14:26:29 +01:00
|
|
|
for my $e (sort keys %rc) {
|
|
|
|
print "$e=" . ( defined($rc{$e}) ? $rc{$e} : 'undef' ) . "\n";
|
2012-03-16 05:29:45 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-11 17:15:07 +01:00
|
|
|
print join( "\t", map { $rc{$_} || '' } @vars ) . ($nonl ? '' : "\n") if @vars;
|
2012-03-16 05:29:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub args {
|
|
|
|
my $help = 0;
|
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
'all|a' => \$all,
|
2012-03-11 17:15:07 +01:00
|
|
|
'nonl|n' => \$nonl,
|
2012-03-16 05:29:45 +01:00
|
|
|
'help|h' => \$help,
|
|
|
|
) or usage();
|
|
|
|
|
|
|
|
usage("'-a' cannot be combined with other arguments") if $all and @ARGV;
|
|
|
|
usage() if not $all and not @ARGV or $help;
|
|
|
|
return @ARGV;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
# configuration variables for gitolite
|
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS
|
2012-03-16 05:29:45 +01:00
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
# this file is in perl syntax. However, you do NOT need to know perl to edit
|
2012-03-10 15:13:42 +01:00
|
|
|
# it; it should be fairly self-explanatory and easy to maintain. Just mind
|
|
|
|
# the commas, make sure the brackets and braces stay matched up!
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
%RC = (
|
|
|
|
UMASK => 0077,
|
|
|
|
GL_GITCONFIG_KEYS => "",
|
2012-03-10 15:13:42 +01:00
|
|
|
|
|
|
|
# uncomment as needed
|
|
|
|
SYNTACTIC_SUGAR =>
|
|
|
|
[
|
|
|
|
# 'continuation-lines',
|
|
|
|
]
|
2012-03-16 05:29:45 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# per perl rules, this should be the last line in such a file:
|
|
|
|
1;
|
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: perl
|
|
|
|
# End:
|
|
|
|
# vim: set syn=perl:
|