Skip to content

Commit

Permalink
cvsserver: Make the database backend configurable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Frank Lichtenheld authored and Junio C Hamano committed Mar 22, 2007
1 parent d55820c commit eb1780d
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions git-cvsserver.perl
Original file line number Diff line number Diff line change
Expand Up @@ -2141,19 +2141,33 @@ sub new

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->{file} = $self->{dbdir} . "/gitcvs.$module.sqlite";

$self->{git_path} = $config . "/";

$self->{log} = $log;

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} = {};
foreach my $table ( $self->{dbh}->tables )
Expand Down Expand Up @@ -2857,5 +2871,19 @@ sub safe_pipe_capture {
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;

0 comments on commit eb1780d

Please sign in to comment.