~ubuntu-branches/ubuntu/gutsy/git-core/gutsy-updates

« back to all changes in this revision

Viewing changes to git-cvsserver.perl

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-05-30 12:38:45 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20070530123845-mhso4051d7vx1189
Tags: 1:1.5.2-1
* merge branch debian-experimental.
* new upstream release.
  * gitweb: choose appropriate view for file type if a= parameter missing
    (closes: #410465).
  * git fetch -q is supported (closes: #423165).
* /usr/bin/git transition (thx Ian Beckwith!).
  * debian/git-core.preinst: new; remove /usr/bin/git alternative if
    upgrading from versions older than 1:1.5.2~rc3-2.
  * debian/git-core.prerm, debian/git-core.postinst: remove; no longer
    handle /usr/bin/git alternative through update-alternatives.
  * debian/rules: no longer install git program as git-scm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
# if we are called with a pserver argument,
92
92
# deal with the authentication cat before entering the
93
93
# main loop
 
94
$state->{method} = 'ext';
94
95
if (@ARGV && $ARGV[0] eq 'pserver') {
 
96
    $state->{method} = 'pserver';
95
97
    my $line = <STDIN>; chomp $line;
96
98
    unless( $line eq 'BEGIN AUTH REQUEST') {
97
99
       die "E Do not understand $line - expecting BEGIN AUTH REQUEST\n";
103
105
    unless ($line eq 'anonymous') {
104
106
       print "E Only anonymous user allowed via pserver\n";
105
107
       print "I HATE YOU\n";
 
108
       exit 1;
106
109
    }
107
110
    $line = <STDIN>; chomp $line;    # validate the password?
108
111
    $line = <STDIN>; chomp $line;
181
184
    }
182
185
    foreach my $line ( @gitvars )
183
186
    {
184
 
        next unless ( $line =~ /^(.*?)\.(.*?)=(.*)$/ );
185
 
        $cfg->{$1}{$2} = $3;
 
187
        next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
 
188
        unless ($2) {
 
189
            $cfg->{$1}{$3} = $4;
 
190
        } else {
 
191
            $cfg->{$1}{$2}{$3} = $4;
 
192
        }
186
193
    }
187
194
 
188
 
    unless ( defined ( $cfg->{gitcvs}{enabled} ) and $cfg->{gitcvs}{enabled} =~ /^\s*(1|true|yes)\s*$/i )
 
195
    unless ( ($cfg->{gitcvs}{$state->{method}}{enabled}
 
196
              and $cfg->{gitcvs}{$state->{method}}{enabled} =~ /^\s*(1|true|yes)\s*$/i)
 
197
             or ($cfg->{gitcvs}{enabled}
 
198
              and $cfg->{gitcvs}{enabled} =~ /^\s*(1|true|yes)\s*$/i) )
189
199
    {
190
200
        print "E GITCVS emulation needs to be enabled on this repo\n";
191
201
        print "E the repo config file needs a [gitcvs] section added, and the parameter 'enabled' set to 1\n";
194
204
        return 0;
195
205
    }
196
206
 
197
 
    if ( defined ( $cfg->{gitcvs}{logfile} ) )
 
207
    my $logfile = $cfg->{gitcvs}{$state->{method}}{logfile} || $cfg->{gitcvs}{logfile};
 
208
    if ( $logfile )
198
209
    {
199
 
        $log->setfile($cfg->{gitcvs}{logfile});
 
210
        $log->setfile($logfile);
200
211
    } else {
201
212
        $log->nofile();
202
213
    }
350
361
 
351
362
    argsplit("add");
352
363
 
 
364
    my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
 
365
    $updater->update();
 
366
 
 
367
    argsfromdir($updater);
 
368
 
353
369
    my $addcount = 0;
354
370
 
355
371
    foreach my $filename ( @{$state->{args}} )
356
372
    {
357
373
        $filename = filecleanup($filename);
358
374
 
 
375
        my $meta = $updater->getmeta($filename);
 
376
        my $wrev = revparse($filename);
 
377
 
 
378
        if ($wrev && $meta && ($wrev < 0))
 
379
        {
 
380
            # previously removed file, add back
 
381
            $log->info("added file $filename was previously removed, send 1.$meta->{revision}");
 
382
 
 
383
            print "MT +updated\n";
 
384
            print "MT text U \n";
 
385
            print "MT fname $filename\n";
 
386
            print "MT newline\n";
 
387
            print "MT -updated\n";
 
388
 
 
389
            unless ( $state->{globaloptions}{-n} )
 
390
            {
 
391
                my ( $filepart, $dirpart ) = filenamesplit($filename,1);
 
392
 
 
393
                print "Created $dirpart\n";
 
394
                print $state->{CVSROOT} . "/$state->{module}/$filename\n";
 
395
 
 
396
                # this is an "entries" line
 
397
                my $kopts = kopts_from_path($filepart);
 
398
                $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
 
399
                print "/$filepart/1.$meta->{revision}//$kopts/\n";
 
400
                # permissions
 
401
                $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
 
402
                print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
 
403
                # transmit file
 
404
                transmitfile($meta->{filehash});
 
405
            }
 
406
 
 
407
            next;
 
408
        }
 
409
 
359
410
        unless ( defined ( $state->{entries}{$filename}{modified_filename} ) )
360
411
        {
361
412
            print "E cvs add: nothing known about `$filename'\n";
1027
1078
 
1028
1079
    $log->info("req_ci : " . ( defined($data) ? $data : "[NULL]" ));
1029
1080
 
1030
 
    if ( @ARGV && $ARGV[0] eq 'pserver')
 
1081
    if ( $state->{method} eq 'pserver')
1031
1082
    {
1032
1083
        print "error 1 pserver access cannot commit\n";
1033
1084
        exit;
2132
2183
 
2133
2184
    bless $self, $class;
2134
2185
 
2135
 
    $self->{dbdir} = $config . "/";
2136
 
    die "Database dir '$self->{dbdir}' isn't a directory" unless ( defined($self->{dbdir}) and -d $self->{dbdir} );
2137
 
 
2138
2186
    $self->{module} = $module;
2139
 
    $self->{file} = $self->{dbdir} . "/gitcvs.$module.sqlite";
2140
 
 
2141
2187
    $self->{git_path} = $config . "/";
2142
2188
 
2143
2189
    $self->{log} = $log;
2144
2190
 
2145
2191
    die "Git repo '$self->{git_path}' doesn't exist" unless ( -d $self->{git_path} );
2146
2192
 
2147
 
    $self->{dbh} = DBI->connect("dbi:SQLite:dbname=" . $self->{file},"","");
 
2193
    $self->{dbdriver} = $cfg->{gitcvs}{$state->{method}}{dbdriver} ||
 
2194
        $cfg->{gitcvs}{dbdriver} || "SQLite";
 
2195
    $self->{dbname} = $cfg->{gitcvs}{$state->{method}}{dbname} ||
 
2196
        $cfg->{gitcvs}{dbname} || "%Ggitcvs.%m.sqlite";
 
2197
    $self->{dbuser} = $cfg->{gitcvs}{$state->{method}}{dbuser} ||
 
2198
        $cfg->{gitcvs}{dbuser} || "";
 
2199
    $self->{dbpass} = $cfg->{gitcvs}{$state->{method}}{dbpass} ||
 
2200
        $cfg->{gitcvs}{dbpass} || "";
 
2201
    my %mapping = ( m => $module,
 
2202
                    a => $state->{method},
 
2203
                    u => getlogin || getpwuid($<) || $<,
 
2204
                    G => $self->{git_path},
 
2205
                    g => mangle_dirname($self->{git_path}),
 
2206
                    );
 
2207
    $self->{dbname} =~ s/%([mauGg])/$mapping{$1}/eg;
 
2208
    $self->{dbuser} =~ s/%([mauGg])/$mapping{$1}/eg;
 
2209
 
 
2210
    die "Invalid char ':' in dbdriver" if $self->{dbdriver} =~ /:/;
 
2211
    die "Invalid char ';' in dbname" if $self->{dbname} =~ /;/;
 
2212
    $self->{dbh} = DBI->connect("dbi:$self->{dbdriver}:dbname=$self->{dbname}",
 
2213
                                $self->{dbuser},
 
2214
                                $self->{dbpass});
 
2215
    die "Error connecting to database\n" unless defined $self->{dbh};
2148
2216
 
2149
2217
    $self->{tables} = {};
2150
 
    foreach my $table ( $self->{dbh}->tables )
 
2218
    foreach my $table ( keys %{$self->{dbh}->table_info(undef,undef,undef,'TABLE')->fetchall_hashref('TABLE_NAME')} )
2151
2219
    {
2152
 
        $table =~ s/^"//;
2153
 
        $table =~ s/"$//;
2154
2220
        $self->{tables}{$table} = 1;
2155
2221
    }
2156
2222
 
2848
2914
    return wantarray ? @output : join('',@output);
2849
2915
}
2850
2916
 
 
2917
=head2 mangle_dirname
 
2918
 
 
2919
create a string from a directory name that is suitable to use as
 
2920
part of a filename, mainly by converting all chars except \w.- to _
 
2921
 
 
2922
=cut
 
2923
sub mangle_dirname {
 
2924
    my $dirname = shift;
 
2925
    return unless defined $dirname;
 
2926
 
 
2927
    $dirname =~ s/[^\w.-]/_/g;
 
2928
 
 
2929
    return $dirname;
 
2930
}
2851
2931
 
2852
2932
1;