Changeset 2312 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/VCS.pm
- Timestamp:
- Sep 6, 2017, 9:08:46 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/VCS.pm
r2308 r2312 36 36 37 37 our @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 pb_vcs_compliant pb_vcs_conf_update_v0);38 our @EXPORT = qw(pb_vcs_init 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 pb_vcs_conf_update_v0); 39 39 ($VERSION,$REVISION) = pb_version_init(); 40 40 … … 52 52 53 53 =over 4 54 55 56 =item B<pb_vcs_init> 57 58 This function setup the environment for the VCS system related to the URL given by the pbprojurl configuration parameter. 59 The potential parameter indicates whether we should inititate the context or not. 60 It sets up environement variables (PBPROJDIR, PBDIR, PBREVISION, PBCMSLOGFILE) 61 62 =cut 63 64 sub pb_vcs_init { 65 66 my $pbinit = shift; 67 my $param = shift; 68 69 my ($pbprojurl) = pb_conf_get("pbprojurl"); 70 confess "Undefined pbprojurl for $ENV{'PBPROJ'}\n" if ((not defined $pbprojurl) or (not defined $pbprojurl->{$ENV{'PBPROJ'}})); 71 pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pbprojurl->{$ENV{'PBPROJ'}}\n"); 72 my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbprojurl->{$ENV{'PBPROJ'}}); 73 my $vcscmd = pb_vcs_cmd($scheme); 74 75 my ($pbprojdir) = pb_conf_get_if("pbprojdir"); 76 77 if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) { 78 $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}}; 79 } else { 80 $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}"; 81 } 82 # Expand potential env variable in it to allow string replacement 83 eval { $ENV{'PBPROJDIR'} =~ s/(\$ENV.+\})/$1/eeg }; 84 85 86 # Computing the default dir for PBDIR. 87 # what we have is PBPROJDIR so work from that. 88 # Tree identical between PBCONFDIR and PBROOTDIR on one side and 89 # PBPROJDIR and PBDIR on the other side. 90 91 my $tmp = $ENV{'PBROOTDIR'}; 92 $tmp =~ s|^$ENV{'PBCONFDIR'}/||; 93 # If no subdir, then replace again 94 $tmp =~ s|^$ENV{'PBCONFDIR'}||; 95 96 # 97 # Check project cms compliance 98 # 99 my $turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp"; 100 $turl = $pbprojurl->{$ENV{'PBPROJ'}} if ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(git)\b/o); 101 # git svn is like svn 102 $turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp" if ($scheme =~ /^git\+svn/o); 103 pb_vcs_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$turl,$pbinit); 104 105 106 if ($scheme =~ /^hg/) { 107 $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd identify )`; 108 chomp($tmp); 109 $tmp =~ s/^.* //; 110 $ENV{'PBREVISION'}=$tmp; 111 $ENV{'PBCMSLOGFILE'}="hg.log"; 112 } elsif ($scheme =~ /^git/) { 113 if ($scheme =~ /svn/) { 114 $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info | grep -E '^Revision:' | cut -d: -f2)`; 115 $tmp =~ s/\s+//; 116 } else { 117 $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd log | head -1 | cut -f2)`; 118 $tmp =~ s/^.* //; 119 # Reduce length of commit id to 8 digit 120 $tmp = substr($tmp,1,8); 121 } 122 chomp($tmp); 123 $ENV{'PBREVISION'}=$tmp; 124 $ENV{'PBCMSLOGFILE'}="git.log"; 125 } elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)\b/o) { 126 $ENV{'PBREVISION'}="flat"; 127 $ENV{'PBCMSLOGFILE'}="flat.log"; 128 } elsif ($scheme =~ /^svn/) { 129 # svnversion more precise than svn info if sbx 130 if ((defined $param) && ($param eq "CMS")) { 131 $tmp = `(LANGUAGE=C $vcscmd info $pbprojurl->{$ENV{'PBPROJ'}} | grep -E '^Revision:' | cut -d: -f2)`; 132 $tmp =~ s/\s+//; 133 } else { 134 $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd"version" .)`; 135 } 136 chomp($tmp); 137 $ENV{'PBREVISION'}=$tmp; 138 $ENV{'PBCMSLOGFILE'}="svn.log"; 139 } elsif ($scheme =~ /^svk/) { 140 $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info . | grep -E '^Revision:' | cut -d: -f2)`; 141 $tmp =~ s/\s+//; 142 chomp($tmp); 143 $ENV{'PBREVISION'}=$tmp; 144 $ENV{'PBCMSLOGFILE'}="svk.log"; 145 } elsif ($scheme =~ /^cvs/) { 146 # Way too slow 147 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`; 148 #chomp($ENV{'PBREVISION'}); 149 $ENV{'PBREVISION'}="cvs"; 150 $ENV{'PBCMSLOGFILE'}="cvs.log"; 151 $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/); 152 } else { 153 die "cms $scheme unknown"; 154 } 155 156 pb_log(1,"pb_vcs_init returns $scheme,$pbprojurl->{$ENV{'PBPROJ'}}\n"); 157 return($scheme,$pbprojurl->{$ENV{'PBPROJ'}}); 158 } 159 54 160 55 161 =item B<pb_vcs_export> … … 660 766 The second parameter is the environment variable this key will populate. 661 767 The third parameter is the location of the pbconf dir. 662 The fourth parameter is the URI of the CMS content related to the pbconf dir.768 The fourth parameter is the URI of the VCS content related to the pbconf dir. 663 769 The fifth parameter indicates whether we should inititate the context or not. 664 770
Note:
See TracChangeset
for help on using the changeset viewer.