cvsserver: Make the database backend configurable

Make all the different parts of the database backend connection
configurable. This adds the following string configuration variables:
- gitcvs.dbdriver
- gitcvs.dbname
- gitcvs.dbuser
- gitcvs.dbpass
The default values emulate the current behavior exactly for
backwards compatibility.
All configuration variables can also be specified for a specific
access method (i.e. in the form gitcvs.<method>.<var>)

The dbdriver/dbuser/dbpass variables are added for completness.
No other backend than SQLite is tested yet.
The dbname variable on the other hand is useful with this backend
already (to not discriminate against other possible backends
it was not splitted in dbdir and dbfile).

Both dbname and dbuser support dynamic variable substitution where
the available variables are:
%m -- the CVS 'module' (i.e. GIT 'head') worked on
%a -- CVS access method used (i.e. 'ext' or 'pserver')
%u -- User name of the user invoking git-cvsserver
%G -- .git directory name
%g -- .git directory name, mangled to be used in a filename,
      currently this substitutes all chars except for [\w.-]
      with '_'

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Frank Lichtenheld 2007-03-19 16:56:00 +01:00 committed by Junio C Hamano
parent d55820ced6
commit eb1780d480

View File

@ -2141,19 +2141,33 @@ sub new
bless $self, $class; bless $self, $class;
$self->{dbdir} = $config . "/";
die "Database dir '$self->{dbdir}' isn't a directory" unless ( defined($self->{dbdir}) and -d $self->{dbdir} );
$self->{module} = $module; $self->{module} = $module;
$self->{file} = $self->{dbdir} . "/gitcvs.$module.sqlite";
$self->{git_path} = $config . "/"; $self->{git_path} = $config . "/";
$self->{log} = $log; $self->{log} = $log;
die "Git repo '$self->{git_path}' doesn't exist" unless ( -d $self->{git_path} ); die "Git repo '$self->{git_path}' doesn't exist" unless ( -d $self->{git_path} );
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=" . $self->{file},"",""); $self->{dbdriver} = $cfg->{gitcvs}{$state->{method}}{dbdriver} ||
$cfg->{gitcvs}{dbdriver} || "dbi:SQLite";
$self->{dbname} = $cfg->{gitcvs}{$state->{method}}{dbname} ||
$cfg->{gitcvs}{dbname} || "%Ggitcvs.%m.sqlite";
$self->{dbuser} = $cfg->{gitcvs}{$state->{method}}{dbuser} ||
$cfg->{gitcvs}{dbuser} || "";
$self->{dbpass} = $cfg->{gitcvs}{$state->{method}}{dbpass} ||
$cfg->{gitcvs}{dbpass} || "";
my %mapping = ( m => $module,
a => $state->{method},
u => getlogin || getpwuid($<) || $<,
G => $self->{git_path},
g => mangle_dirname($self->{git_path}),
);
$self->{dbname} =~ s/%([mauGg])/$mapping{$1}/eg;
$self->{dbuser} =~ s/%([mauGg])/$mapping{$1}/eg;
$self->{dbh} = DBI->connect("$self->{dbdriver}:dbname=$self->{dbname}",
$self->{dbuser},
$self->{dbpass});
$self->{tables} = {}; $self->{tables} = {};
foreach my $table ( $self->{dbh}->tables ) foreach my $table ( $self->{dbh}->tables )
@ -2857,5 +2871,19 @@ sub safe_pipe_capture {
return wantarray ? @output : join('',@output); return wantarray ? @output : join('',@output);
} }
=head2 mangle_dirname
create a string from a directory name that is suitable to use as
part of a filename, mainly by converting all chars except \w.- to _
=cut
sub mangle_dirname {
my $dirname = shift;
return unless defined $dirname;
$dirname =~ s/[^\w.-]/_/g;
return $dirname;
}
1; 1;