Changeset 382 in openpam for trunk/misc


Ignore:
Timestamp:
Mar 14, 2006, 3:46:53 PM (13 years ago)
Author:
Dag-Erling Smørgrav
Message:

Use a single client connection, instead of reconnecting for every file in
every changeset. This is a bit of a kludge, because I tried to change as
little as possible. Also, this version will not work for depots which
contain binary files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/misc/p42svn.pl

    r381 r382  
    578578#########################################################################
    579579
     580my $global_p4;
     581
    580582sub p4_init {
     583    return $global_p4
     584        if defined $global_p4;
    581585    my $p4 = P4->new();
    582586    $p4->SetUser($options{user}) if $options{user};
     
    585589    $p4->SetPassword($options{password}) if $options{password};
    586590    $p4->ParseForms();
    587     $p4->Init() or die "failed to connect to Perforce server";
    588     return $p4;
     591    while (!$p4->Init()) {
     592        warn "failed to connect to Perforce server";
     593        sleep 3;
     594        warn "retrying...\n";
     595    };
     596    return $global_p4 = $p4;
    589597}
    590598
     
    597605        die "@{$p4->Errors()}" if $p4->ErrorCount();
    598606    }
    599     $p4->Final();
     607    #$p4->Final();
    600608    my %seen = map {$_->{change} => 1} @changes;
    601609    return sort {$a <=> $b} keys %seen;
     
    608616    my $change = $p4->Describe($change_num);
    609617    die "@{$p4->Errors()}" if $p4->ErrorCount();
    610     $p4->Final();
     618    #$p4->Final();
    611619    my %result;
    612620    $result{author} = $change->{user};
     
    637645    my $filespec = shift;
    638646    debug("p4_get_file_content: $filespec\n");
    639     local *P4_OUTPUT;
    640     local $/ = undef;
    641     my $pid = open(P4_OUTPUT, "-|");
    642     die "fork failed: $!" unless defined $pid;
    643     if ($pid == 0) { # child
    644         my $p4 = p4_init();
    645         my $result = $p4->Print($filespec);
    646         die "@{$p4->Errors()}" if $p4->ErrorCount();
    647         if (ref $result eq "ARRAY") {
    648             for (my $i = 1; $i < @$result; $i++) {
    649                 print $result->[$i];
    650             }
    651         }
    652         $p4->Final();
    653         exit 0;
    654     }
    655     my $content = <P4_OUTPUT>;
    656     close(P4_OUTPUT) or die "close failed: ($?) $!";
     647    my $p4 = p4_init();
     648    my $result = $p4->Print($filespec);
     649    die "@{$p4->Errors()}" if $p4->ErrorCount();
     650    my $content = "";
     651    if (ref $result eq "ARRAY") {
     652        for (my $i = 1; $i < @$result; $i++) {
     653            $content .= $result->[$i];
     654        }
     655    }
     656    #$p4->Final();
    657657    return $content;
    658658}
Note: See TracChangeset for help on using the changeset viewer.