Changeset 1678 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/VCS.pm


Ignore:
Timestamp:
Nov 16, 2012, 9:06:13 PM (11 years ago)
Author:
Bruno Cornec
Message:
  • Exports function pb_vcs_add_if_not_in
  • replace most die by confess
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/VCS.pm

    r1586 r1678  
    3535 
    3636our @ISA = qw(Exporter);
    37 our @EXPORT = qw(pb_vcs_export pb_vcs_get_uri pb_vcs_copy pb_vcs_checkout pb_vcs_up pb_vcs_checkin pb_vcs_isdiff pb_vcs_add pb_vcs_cmd);
     37our @EXPORT = qw(pb_vcs_export pb_vcs_get_uri pb_vcs_copy pb_vcs_checkout pb_vcs_up pb_vcs_checkin pb_vcs_isdiff pb_vcs_add pb_vcs_add_if_not_in pb_vcs_cmd);
    3838($VERSION,$REVISION) = pb_version_init();
    3939
     
    112112    } else {
    113113        # Look at svk admin hotcopy
    114         die "Unable to export from svk without a source defined";
     114        confess "Unable to export from svk without a source defined";
    115115    }
    116116} elsif ($scheme eq "dir") {
     
    131131    if ($@) {
    132132        # File::MimeInfo not found
    133         die("ERROR: Install File::MimeInfo to handle scheme $scheme\n");
     133        confess("ERROR: Install File::MimeInfo to handle scheme $scheme\n");
    134134    }
    135135
     
    220220    pb_system("cd $dir ; $vcscmd -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
    221221} else {
    222     die "cms $scheme unknown";
     222    confess "cms $scheme unknown";
    223223}
    224224return(undef);
     
    243243
    244244if ($scheme =~ /^svn/) {
    245     open(PIPE,"LANGUAGE=C $vcscmd info $dir |") || return("");
     245    open(PIPE,"LANGUAGE=C $vcscmd info $dir 2> /dev/null |") || return("");
    246246    while (<PIPE>) {
    247247        ($void,$res) = split(/^URL:/) if (/^URL:/);
     
    251251    chomp($res);
    252252} elsif ($scheme =~ /^svk/) {
    253     open(PIPE,"LANGUAGE=C $vcscmd info $dir |") || return("");
     253    open(PIPE,"LANGUAGE=C $vcscmd info $dir 2> /dev/null |") || return("");
    254254    my $void2 = "";
    255255    while (<PIPE>) {
     
    267267    chomp($res);
    268268} elsif ($scheme =~ /^git/) {
    269     open(GIT,"git --git-dir=$dir/.git remote -v |") || return("");
     269    open(GIT,"git --git-dir=$dir/.git remote -v 2> /dev/null |") || return("");
    270270    while (<GIT>) {
    271271        next unless (/^origin\s+(\S+) \(push\)$/);
     
    277277} elsif ($scheme =~ /^cvs/) {
    278278    # This path is always the root path of CVS, but we may be below
    279     open(FILE,"$dir/CVS/Root") || die "$dir isn't CVS controlled";
     279    open(FILE,"$dir/CVS/Root") || confess "$dir isn't CVS controlled";
    280280    $res = <FILE>;
    281281    chomp($res);
     
    286286        $rdir = dirname($rdir);
    287287    }
    288     die "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
     288    confess "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
    289289    #compute our place under that root dir - should be a relative path
    290290    $dir =~ s|^$rdir||;
     
    300300    $res = $prefix.$res.$suffix;
    301301} else {
    302     die "cms $scheme unknown";
     302    confess "cms $scheme unknown";
    303303}
    304304pb_log(1,"pb_vcs_get_uri returns $res\n");
     
    332332    # Nothing to do.
    333333} else {
    334     die "cms $scheme unknown for project management";
     334    confess "cms $scheme unknown for project management";
    335335}
    336336}
     
    385385    pb_vcs_export($url,undef,$destination);
    386386} else {
    387     die "cms $scheme unknown";
     387    confess "cms $scheme unknown";
    388388}
    389389}
     
    411411    # Nothing to do.
    412412} else {
    413     die "cms $scheme unknown";
     413    confess "cms $scheme unknown";
    414414}
    415415}
     
    437437    # Nothing to do.
    438438} else {
    439     die "cms $scheme unknown";
     439    confess "cms $scheme unknown";
    440440}
    441441pb_vcs_up($scheme,$dir);
     442}
     443
     444=item B<pb_vcs_add_if_not_in>
     445
     446This function adds to a VCS content from a local directory if the content wasn't already managed under th VCS.
     447The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
     448The second parameter is a list of directory/file to add.
     449
     450=cut
     451
     452sub pb_vcs_add_if_not_in {
     453my $scheme = shift;
     454my @f = @_;
     455my $vcscmd = pb_vcs_cmd($scheme);
     456
     457if ($scheme =~ /^((hg)|(git)|(svn)|(svk)|(cvs))/o) {
     458    for my $f (@f) {
     459        my $uri = pb_vcs_get_uri($scheme,$f);
     460        pb_vcs_add($scheme,$f) if ($uri !~ /^$scheme/);
     461    }
     462} elsif ($scheme =~ /^(flat)|(ftp)|(http)|(file)\b/o) {
     463    # Nothing to do.
     464} else {
     465    confess "cms $scheme unknown";
     466}
    442467}
    443468
     
    460485    # Nothing to do.
    461486} else {
    462     die "cms $scheme unknown";
     487    confess "cms $scheme unknown";
    463488}
    464489pb_vcs_up($scheme,@f);
     
    480505
    481506if ($scheme =~ /^((svn)|(cvs)|(svk))/o) {
    482     open(PIPE,"$vcscmd diff $dir |") || die "Unable to get $vcscmd diff from $dir";
     507    open(PIPE,"$vcscmd diff $dir |") || confess "Unable to get $vcscmd diff from $dir";
    483508    $l = 0;
    484509    while (<PIPE>) {
     
    490515    $l = 0;
    491516} else {
    492     die "cms $scheme unknown";
     517    confess "cms $scheme unknown";
    493518}
    494519pb_log(1,"pb_vcs_isdiff returns $l\n");
     
    552577            return($cmd."$command -o ");
    553578        } else {
    554             die "Unable to handle $scheme.\nNo wget/curl available, please install one of those";
     579            confess "Unable to handle $scheme.\nNo wget/curl available, please install one of those";
    555580        }
    556581    }
Note: See TracChangeset for help on using the changeset viewer.