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


Ignore:
Timestamp:
Jan 28, 2014, 9:10:25 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Move pb_cms_compliant fundtion into VCS.pm and rename it pb_vcs_compliant, as it was used incorrectly in Env.pm which was lower in the tree. Detected by MondoRescue 3.2 update by Corey Wirun and reported on the ML.
File:
1 edited

Legend:

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

    r1801 r1850  
    3636 
    3737our @ISA = qw(Exporter);
    38 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_add_if_not_in pb_vcs_cmd);
     38our @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 pb_vcs_compliant);
    3939($VERSION,$REVISION) = pb_version_init();
    4040
     
    623623}
    624624
    625    
     625=item B<pb_vcs_compliant>
     626
     627This function checks the compliance of the project and the pbconf directory.
     628The first parameter is the key name of the value that needs to be read in the configuration file.
     629The second parameter is the environment variable this key will populate.
     630The third parameter is the location of the pbconf dir.
     631The fourth parameter is the URI of the CMS content related to the pbconf dir.
     632The fifth parameter indicates whether we should inititate the context or not.
     633
     634=cut
     635
     636sub pb_vcs_compliant {
     637
     638my $param = shift;
     639my $envar = shift;
     640my $defdir = shift;
     641my $uri = shift;
     642my $pbinit = shift;
     643my %pdir;
     644
     645pb_log(1,"pb_vcs_compliant: envar: $envar - defdir: $defdir - uri: $uri\n");
     646my ($pdir) = pb_conf_get_if($param) if (defined $param);
     647if (defined $pdir) {
     648    %pdir = %$pdir;
     649}
     650
     651
     652if ((defined $pdir) && (%pdir) && (defined $pdir{$ENV{'PBPROJ'}})) {
     653    # That's always the environment variable that will be used
     654    $ENV{$envar} = $pdir{$ENV{'PBPROJ'}};
     655} else {
     656    if (defined $param) {
     657        pb_log(1,"WARNING: no $param defined, using $defdir\n");
     658        pb_log(1,"         Please create a $param reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
     659        pb_log(1,"         if you want to use another directory\n");
     660    }
     661    $ENV{$envar} = "$defdir";
     662}
     663
     664# Expand potential env variable in it
     665eval { $ENV{$envar} =~ s/(\$ENV.+\})/$1/eeg };
     666pb_log(2,"$envar: $ENV{$envar}\n");
     667
     668my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
     669
     670if (($scheme !~ /^cvs/) && ($scheme !~ /^svn/) && ($scheme !~ /^svk/) && ($scheme !~ /^hg/) && ($scheme !~ /^git/)) {
     671    # Do not compare if it's not a real cms
     672    pb_log(1,"pb_vcs_compliant useless\n");
     673    return;
     674} elsif (defined $pbinit) {
     675    pb_mkdir_p("$ENV{$envar}");
     676} elsif (! -d "$ENV{$envar}") {
     677    # Either we have a version in the uri, and it should be the same
     678    # as the one in the envar. Or we should add the version to the uri
     679    if (basename($uri) ne basename($ENV{$envar})) {
     680        $uri .= "/".basename($ENV{$envar})
     681    }
     682    pb_log(1,"Checking out $uri\n");
     683    # Create structure and remove end dir before exporting
     684    pb_mkdir_p("$ENV{$envar}");
     685    pb_rm_rf($ENV{$envar});
     686    pb_vcs_checkout($scheme,$uri,$ENV{$envar});
     687} else {
     688    pb_log(1,"$uri found locally, checking content\n");
     689    my $cmsurl = pb_vcs_get_uri($scheme,$ENV{$envar});
     690    my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
     691    # For svk, scheme doesn't appear in svk info so remove it here in uri coming from conf file
     692    # which needs it to trigger correct behaviour
     693    $uri =~ s/^svk://;
     694    if (($scheme2 =~ /^git/) || ($scheme2 =~ /^hg/)) {
     695        # These VCS manage branches internally not with different tree structures
     696        # Assuming it's correct for now.
     697    } elsif ($cmsurl ne $uri) {
     698        # The local content doesn't correpond to the repository
     699        pb_log(0,"ERROR: Inconsistency detected:\n");
     700        pb_log(0,"       * $ENV{$envar} ($envar) refers to $cmsurl but\n");
     701        pb_log(0,"       * $ENV{'PBETC'} refers to $uri\n");
     702        die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
     703    } else {
     704        pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
     705        # they match - do nothing - there may be local changes
     706    }
     707}
     708pb_log(1,"pb_vcs_compliant end\n");
     709}
     710
    626711
    627712=back
Note: See TracChangeset for help on using the changeset viewer.