@matheusbsbs / matheus-bagliano / commits / eb1780d480
Fork 0

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>

Frank Lichtenheld committed Mar 19, 2007 at 16:56 UTC eb1780d480c2c57c58024692055a6ee33074a95f
1 file changed +34 -6
git-cvsserver.perl
+34 -6
@@ -2141,19 +2141,33 @@ sub new
2141
2142 bless $self, $class;
2143
2144 - $self->{dbdir} = $config . "/";
2145 - die "Database dir '$self->{dbdir}' isn't a directory" unless ( defined($self->{dbdir}) and -d $self->{dbdir} );
2146 -
2144 $self->{module} = $module;
2148 - $self->{file} = $self->{dbdir} . "/gitcvs.$module.sqlite";
2149 -
2145 $self->{git_path} = $config . "/";
2146
2147 $self->{log} = $log;
2148
2149 die "Git repo '$self->{git_path}' doesn't exist" unless ( -d $self->{git_path} );
2150
2156 - $self->{dbh} = DBI->connect("dbi:SQLite:dbname=" . $self->{file},"","");
2151 + $self->{dbdriver} = $cfg->{gitcvs}{$state->{method}}{dbdriver} ||
2152 + $cfg->{gitcvs}{dbdriver} || "dbi:SQLite";
2153 + $self->{dbname} = $cfg->{gitcvs}{$state->{method}}{dbname} ||
2154 + $cfg->{gitcvs}{dbname} || "%Ggitcvs.%m.sqlite";
2155 + $self->{dbuser} = $cfg->{gitcvs}{$state->{method}}{dbuser} ||
2156 + $cfg->{gitcvs}{dbuser} || "";
2157 + $self->{dbpass} = $cfg->{gitcvs}{$state->{method}}{dbpass} ||
2158 + $cfg->{gitcvs}{dbpass} || "";
2159 + my %mapping = ( m => $module,
2160 + a => $state->{method},
2161 + u => getlogin || getpwuid($<) || $<,
2162 + G => $self->{git_path},
2163 + g => mangle_dirname($self->{git_path}),
2164 + );
2165 + $self->{dbname} =~ s/%([mauGg])/$mapping{$1}/eg;
2166 + $self->{dbuser} =~ s/%([mauGg])/$mapping{$1}/eg;
2167 +
2168 + $self->{dbh} = DBI->connect("$self->{dbdriver}:dbname=$self->{dbname}",
2169 + $self->{dbuser},
2170 + $self->{dbpass});
2171
2172 $self->{tables} = {};
2173 foreach my $table ( $self->{dbh}->tables )
@@ -2857,5 +2871,19 @@ sub safe_pipe_capture {
2871 return wantarray ? @output : join('',@output);
2872 }
2873
2874 +=head2 mangle_dirname
2875 +
2876 +create a string from a directory name that is suitable to use as
2877 +part of a filename, mainly by converting all chars except \w.- to _
2878 +
2879 +=cut
2880 +sub mangle_dirname {
2881 + my $dirname = shift;
2882 + return unless defined $dirname;
2883 +
2884 + $dirname =~ s/[^\w.-]/_/g;
2885 +
2886 + return $dirname;
2887 +}
2888
2889 1;