[1469] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Project Builder VCS module
|
---|
| 4 | # VCS subroutines brought by the the Project-Builder project
|
---|
| 5 | # which can be easily used across projects needing to perform
|
---|
| 6 | # VCS related operations
|
---|
| 7 | #
|
---|
| 8 | # $Id$
|
---|
| 9 | #
|
---|
| 10 | # Copyright B. Cornec 2007-2012
|
---|
| 11 | # Provided under the GPL v2
|
---|
| 12 |
|
---|
| 13 | package ProjectBuilder::VCS;
|
---|
| 14 |
|
---|
| 15 | use strict 'vars';
|
---|
[1535] | 16 | use Carp 'confess';
|
---|
[1469] | 17 | use Data::Dumper;
|
---|
| 18 | use English;
|
---|
| 19 | use File::Basename;
|
---|
| 20 | use File::Copy;
|
---|
| 21 | use POSIX qw(strftime);
|
---|
| 22 | use lib qw (lib);
|
---|
| 23 | use ProjectBuilder::Version;
|
---|
| 24 | use ProjectBuilder::Base;
|
---|
| 25 | use ProjectBuilder::Conf;
|
---|
| 26 |
|
---|
| 27 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 28 |
|
---|
| 29 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
| 30 | use Exporter;
|
---|
| 31 |
|
---|
| 32 | # Export, by default, all the functions into the namespace of
|
---|
| 33 | # any code which uses this module.
|
---|
| 34 |
|
---|
| 35 | our @ISA = qw(Exporter);
|
---|
| 36 | 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);
|
---|
| 37 | ($VERSION,$REVISION) = pb_version_init();
|
---|
| 38 |
|
---|
| 39 | =pod
|
---|
| 40 |
|
---|
| 41 | =head1 NAME
|
---|
| 42 |
|
---|
| 43 | ProjectBuilder::VCS, part of the project-builder.org
|
---|
| 44 |
|
---|
| 45 | =head1 DESCRIPTION
|
---|
| 46 |
|
---|
| 47 | This modules provides version control system functions.
|
---|
| 48 |
|
---|
| 49 | =head1 USAGE
|
---|
| 50 |
|
---|
| 51 | =over 4
|
---|
| 52 |
|
---|
| 53 | =item B<pb_vcs_export>
|
---|
| 54 |
|
---|
| 55 | This function exports a VCS content to a directory.
|
---|
| 56 | The first parameter is the URL of the VCS content.
|
---|
| 57 | The second parameter is the directory in which it is locally exposed (result of a checkout). If undef, then use the original VCS content.
|
---|
| 58 | The third parameter is the directory where we want to deliver it (result of export).
|
---|
| 59 | It returns the original tar file if we need to preserve it and undef if we use the produced one.
|
---|
| 60 |
|
---|
| 61 | =cut
|
---|
| 62 |
|
---|
| 63 | sub pb_vcs_export {
|
---|
| 64 |
|
---|
| 65 | my $uri = shift;
|
---|
| 66 | my $source = shift;
|
---|
| 67 | my $destdir = shift;
|
---|
| 68 | my $tmp;
|
---|
| 69 | my $tmp1;
|
---|
| 70 |
|
---|
| 71 | pb_log(1,"pb_vcs_export uri: $uri - destdir: $destdir\n");
|
---|
| 72 | pb_log(1,"pb_vcs_export source: $source\n") if (defined $source);
|
---|
| 73 | my @date = pb_get_date();
|
---|
| 74 | # If it's not flat, then we have a real uri as source
|
---|
| 75 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 76 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 77 | $uri = pb_vcs_mod_socks($uri);
|
---|
| 78 |
|
---|
| 79 | if ($scheme =~ /^svn/) {
|
---|
| 80 | if (defined $source) {
|
---|
| 81 | if (-d $source) {
|
---|
| 82 | $tmp = $destdir;
|
---|
| 83 | } else {
|
---|
| 84 | $tmp = "$destdir/".basename($source);
|
---|
| 85 | }
|
---|
| 86 | $source = pb_vcs_mod_htftp($source,"svn");
|
---|
| 87 | pb_system("$vcscmd export $source $tmp","Exporting $source from $scheme to $tmp ");
|
---|
| 88 | } else {
|
---|
| 89 | $uri = pb_vcs_mod_htftp($uri,"svn");
|
---|
| 90 | pb_system("$vcscmd export $uri $destdir","Exporting $uri from $scheme to $destdir ");
|
---|
| 91 | }
|
---|
| 92 | } elsif ($scheme eq "svk") {
|
---|
| 93 | my $src = $source;
|
---|
| 94 | if (defined $source) {
|
---|
| 95 | if (-d $source) {
|
---|
| 96 | $tmp = $destdir;
|
---|
| 97 | } else {
|
---|
| 98 | $tmp = "$destdir/".basename($source);
|
---|
| 99 | $src = dirname($source);
|
---|
| 100 | }
|
---|
| 101 | $source = pb_vcs_mod_htftp($source,"svk");
|
---|
| 102 | # This doesn't exist !
|
---|
| 103 | # pb_system("$vcscmd export $path $tmp","Exporting $path from $scheme to $tmp ");
|
---|
| 104 | pb_log(4,"$uri,$source,$destdir,$scheme, $account, $host, $port, $path,$tmp");
|
---|
| 105 | if (-d $source) {
|
---|
| 106 | pb_system("mkdir -p $tmp ; cd $tmp; tar -cf - -C $source . | tar xf -","Exporting $source from $scheme to $tmp ");
|
---|
| 107 | } else {
|
---|
| 108 | # If source is file do not use -C with source
|
---|
| 109 | pb_system("mkdir -p ".dirname($tmp)." ; cd ".dirname($tmp)."; tar -cf - -C $src ".basename($source)." | tar xf -","Exporting $src/".basename($source)." from $scheme to $tmp ");
|
---|
| 110 | }
|
---|
| 111 | } else {
|
---|
| 112 | # Look at svk admin hotcopy
|
---|
| 113 | die "Unable to export from svk without a source defined";
|
---|
| 114 | }
|
---|
| 115 | } elsif ($scheme eq "dir") {
|
---|
| 116 | pb_system("cp -r $path $destdir","Copying $uri from DIR to $destdir ");
|
---|
| 117 | } elsif (($scheme eq "http") || ($scheme eq "ftp")) {
|
---|
| 118 | my $f = basename($path);
|
---|
| 119 | unlink "$ENV{'PBTMP'}/$f";
|
---|
| 120 | pb_system("$vcscmd $ENV{'PBTMP'}/$f $uri","Downloading $uri with $vcscmd to $ENV{'PBTMP'}/$f\n");
|
---|
| 121 | # We want to preserve the original tar file
|
---|
| 122 | pb_vcs_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
|
---|
| 123 | return("$ENV{'PBTMP'}/$f");
|
---|
| 124 | } elsif ($scheme =~ /^file/) {
|
---|
| 125 | eval
|
---|
| 126 | {
|
---|
| 127 | require File::MimeInfo;
|
---|
| 128 | File::MimeInfo->import();
|
---|
| 129 | };
|
---|
| 130 | if ($@) {
|
---|
| 131 | # File::MimeInfo not found
|
---|
| 132 | die("ERROR: Install File::MimeInfo to handle scheme $scheme\n");
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | my $mm = mimetype($path);
|
---|
| 136 | pb_log(2,"mimetype: $mm\n");
|
---|
| 137 |
|
---|
| 138 | # Check whether the file is well formed
|
---|
| 139 | # (containing already a directory with the project-version name)
|
---|
| 140 | #
|
---|
| 141 | # If it's not the case, we try to adapt, but distro needing
|
---|
| 142 | # to verify the checksum will have issues (Fedora)
|
---|
| 143 | # Then upstream should be notified that they need to change their rules
|
---|
| 144 | # This doesn't apply to patches or additional sources of course.
|
---|
| 145 | my ($pbwf) = pb_conf_get_if("pbwf");
|
---|
| 146 | if ((defined $pbwf) && (defined $pbwf->{$ENV{'PBPROJ'}}) && ($path !~ /\/pbpatch\//) && ($path !~ /\/pbsrc\//)) {
|
---|
| 147 | $destdir = dirname($destdir);
|
---|
| 148 | pb_log(2,"This is a well-formed file so destdir is now $destdir\n");
|
---|
| 149 | }
|
---|
| 150 | pb_mkdir_p($destdir);
|
---|
| 151 |
|
---|
| 152 | if ($mm =~ /\/x-bzip-compressed-tar$/) {
|
---|
| 153 | # tar+bzip2
|
---|
| 154 | pb_system("cd $destdir ; tar xfj $path","Extracting $path in $destdir ");
|
---|
| 155 | } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
|
---|
| 156 | # tar+lzma
|
---|
| 157 | pb_system("cd $destdir ; tar xfY $path","Extracting $path in $destdir ");
|
---|
| 158 | } elsif ($mm =~ /\/x-compressed-tar$/) {
|
---|
| 159 | # tar+gzip
|
---|
| 160 | pb_system("cd $destdir ; tar xfz $path","Extracting $path in $destdir ");
|
---|
| 161 | } elsif ($mm =~ /\/x-tar$/) {
|
---|
| 162 | # tar
|
---|
| 163 | pb_system("cd $destdir ; tar xf $path","Extracting $path in $destdir ");
|
---|
| 164 | } elsif ($mm =~ /\/zip$/) {
|
---|
| 165 | # zip
|
---|
| 166 | pb_system("cd $destdir ; unzip $path","Extracting $path in $destdir ");
|
---|
| 167 | } else {
|
---|
| 168 | # simple file: copy it (patch e.g.)
|
---|
| 169 | copy($path,$destdir);
|
---|
| 170 | }
|
---|
| 171 | } elsif ($scheme =~ /^hg/) {
|
---|
| 172 | if (defined $source) {
|
---|
| 173 | if (-d $source) {
|
---|
| 174 | $tmp = $destdir;
|
---|
| 175 | } else {
|
---|
| 176 | $tmp = "$destdir/".basename($source);
|
---|
| 177 | }
|
---|
| 178 | $source = pb_vcs_mod_htftp($source,"hg");
|
---|
| 179 | pb_system("cd $source ; $vcscmd archive $tmp","Exporting $source from Mercurial to $tmp ");
|
---|
| 180 | } else {
|
---|
| 181 | $uri = pb_vcs_mod_htftp($uri,"hg");
|
---|
| 182 | pb_system("$vcscmd clone $uri $destdir","Exporting $uri from Mercurial to $destdir ");
|
---|
| 183 | }
|
---|
| 184 | } elsif ($scheme =~ /^git/) {
|
---|
| 185 | if (defined $source) {
|
---|
| 186 | if (-d $source) {
|
---|
| 187 | $tmp = $destdir;
|
---|
| 188 | } else {
|
---|
| 189 | $tmp = "$destdir/".basename($source);
|
---|
| 190 | }
|
---|
| 191 | $source = pb_vcs_mod_htftp($source,"git");
|
---|
| 192 | pb_system("cd $source ; $vcscmd archive --format=tar HEAD | (mkdir $tmp && cd $tmp && tar xf -)","Exporting $source/HEAD from GIT to $tmp ");
|
---|
| 193 | } else {
|
---|
| 194 | $uri = pb_vcs_mod_htftp($uri,"git");
|
---|
| 195 | pb_system("$vcscmd clone $uri $destdir","Exporting $uri from GIT to $destdir ");
|
---|
| 196 | }
|
---|
| 197 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 198 | # CVS needs a relative path !
|
---|
| 199 | my $dir=dirname($destdir);
|
---|
| 200 | my $base=basename($destdir);
|
---|
| 201 | if (defined $source) {
|
---|
| 202 | # CVS also needs a modules name not a dir
|
---|
| 203 | $tmp1 = basename($source);
|
---|
| 204 | } else {
|
---|
| 205 | # Probably not right, should be checked, but that way I'll notice it :-)
|
---|
| 206 | pb_log(0,"You're in an untested part of project-builder.org, please report any result upstream\n");
|
---|
| 207 | $tmp1 = $uri;
|
---|
| 208 | }
|
---|
| 209 | # If we're working on the CVS itself
|
---|
| 210 | my $cvstag = basename($ENV{'PBROOTDIR'});
|
---|
| 211 | my $cvsopt = "";
|
---|
| 212 | if ($cvstag eq "cvs") {
|
---|
| 213 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 214 | $cvsopt = "-D \"$pbdate\"";
|
---|
| 215 | } else {
|
---|
| 216 | # we're working on a tag which should be the last part of PBROOTDIR
|
---|
| 217 | $cvsopt = "-r $cvstag";
|
---|
| 218 | }
|
---|
| 219 | pb_system("cd $dir ; $vcscmd -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
|
---|
| 220 | } else {
|
---|
| 221 | die "cms $scheme unknown";
|
---|
| 222 | }
|
---|
| 223 | return(undef);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | =item B<pb_vcs_get_uri>
|
---|
| 227 |
|
---|
| 228 | This function is only called with a real VCS system and gives the URL stored in the checked out directory.
|
---|
| 229 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
| 230 | The second parameter is the directory in which it is locally exposed (result of a checkout).
|
---|
| 231 |
|
---|
| 232 | =cut
|
---|
| 233 |
|
---|
| 234 | sub pb_vcs_get_uri {
|
---|
| 235 |
|
---|
| 236 | my $scheme = shift;
|
---|
| 237 | my $dir = shift;
|
---|
| 238 |
|
---|
| 239 | my $res = "";
|
---|
| 240 | my $void = "";
|
---|
| 241 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 242 |
|
---|
| 243 | if ($scheme =~ /^svn/) {
|
---|
| 244 | open(PIPE,"LANGUAGE=C $vcscmd info $dir |") || return("");
|
---|
| 245 | while (<PIPE>) {
|
---|
| 246 | ($void,$res) = split(/^URL:/) if (/^URL:/);
|
---|
| 247 | }
|
---|
| 248 | $res =~ s/^\s*//;
|
---|
| 249 | close(PIPE);
|
---|
| 250 | chomp($res);
|
---|
| 251 | } elsif ($scheme =~ /^svk/) {
|
---|
| 252 | open(PIPE,"LANGUAGE=C $vcscmd info $dir |") || return("");
|
---|
| 253 | my $void2 = "";
|
---|
| 254 | while (<PIPE>) {
|
---|
| 255 | ($void,$void2,$res) = split(/ /) if (/^Depot/);
|
---|
| 256 | }
|
---|
| 257 | $res =~ s/^\s*//;
|
---|
| 258 | close(PIPE);
|
---|
| 259 | chomp($res);
|
---|
| 260 | } elsif ($scheme =~ /^hg/) {
|
---|
| 261 | open(HGRC,".hg/hgrc/") || return("");
|
---|
| 262 | while (<HGRC>) {
|
---|
| 263 | ($void,$res) = split(/^default.*=/) if (/^default.*=/);
|
---|
| 264 | }
|
---|
| 265 | close(HGRC);
|
---|
| 266 | chomp($res);
|
---|
| 267 | } elsif ($scheme =~ /^git/) {
|
---|
[1536] | 268 | open(GIT,"git --git-dir=$dir/.git remote -v |") || return("");
|
---|
[1540] | 269 | while (<GIT>) {
|
---|
[1536] | 270 | next unless (/^origin\s+(\S+) \(push\)$/);
|
---|
| 271 | return $1;
|
---|
[1469] | 272 | }
|
---|
[1540] | 273 | close(GIT);
|
---|
[1536] | 274 | warn "Unable to find origin remote for $dir";
|
---|
| 275 | return "";
|
---|
[1469] | 276 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 277 | # This path is always the root path of CVS, but we may be below
|
---|
| 278 | open(FILE,"$dir/CVS/Root") || die "$dir isn't CVS controlled";
|
---|
| 279 | $res = <FILE>;
|
---|
| 280 | chomp($res);
|
---|
| 281 | close(FILE);
|
---|
| 282 | # Find where we are in the tree
|
---|
| 283 | my $rdir = $dir;
|
---|
| 284 | while ((! -d "$rdir/CVSROOT") && ($rdir ne "/")) {
|
---|
| 285 | $rdir = dirname($rdir);
|
---|
| 286 | }
|
---|
| 287 | die "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
|
---|
| 288 | #compute our place under that root dir - should be a relative path
|
---|
| 289 | $dir =~ s|^$rdir||;
|
---|
| 290 | my $suffix = "";
|
---|
| 291 | $suffix = "$dir" if ($dir ne "");
|
---|
| 292 |
|
---|
| 293 | my $prefix = "";
|
---|
| 294 | if ($scheme =~ /ssh/) {
|
---|
| 295 | $prefix = "cvs+ssh://";
|
---|
| 296 | } else {
|
---|
| 297 | $prefix = "cvs://";
|
---|
| 298 | }
|
---|
| 299 | $res = $prefix.$res.$suffix;
|
---|
| 300 | } else {
|
---|
| 301 | die "cms $scheme unknown";
|
---|
| 302 | }
|
---|
| 303 | pb_log(1,"pb_vcs_get_uri returns $res\n");
|
---|
| 304 | return($res);
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | =item B<pb_vcs_copy>
|
---|
| 308 |
|
---|
| 309 | This function copies a VCS content to another.
|
---|
| 310 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
| 311 | The second parameter is the URL of the original VCS content.
|
---|
| 312 | The third parameter is the URL of the destination VCS content.
|
---|
| 313 |
|
---|
| 314 | Only coded for SVN now as used for pbconf itself not the project
|
---|
| 315 |
|
---|
| 316 | =cut
|
---|
| 317 |
|
---|
| 318 | sub pb_vcs_copy {
|
---|
| 319 | my $scheme = shift;
|
---|
| 320 | my $oldurl = shift;
|
---|
| 321 | my $newurl = shift;
|
---|
| 322 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 323 | $oldurl = pb_vcs_mod_socks($oldurl);
|
---|
| 324 | $newurl = pb_vcs_mod_socks($newurl);
|
---|
| 325 |
|
---|
| 326 | if ($scheme =~ /^svn/) {
|
---|
| 327 | $oldurl = pb_vcs_mod_htftp($oldurl,"svn");
|
---|
| 328 | $newurl = pb_vcs_mod_htftp($newurl,"svn");
|
---|
| 329 | pb_system("$vcscmd copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
| 330 | } elsif (($scheme eq "flat") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 331 | } else {
|
---|
| 332 | die "cms $scheme unknown for project management";
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | =item B<pb_vcs_checkout>
|
---|
| 337 |
|
---|
| 338 | This function checks a VCS content out to a directory.
|
---|
| 339 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
| 340 | The second parameter is the URL of the VCS content.
|
---|
| 341 | The third parameter is the directory where we want to deliver it (result of export).
|
---|
| 342 |
|
---|
| 343 | =cut
|
---|
| 344 |
|
---|
| 345 | sub pb_vcs_checkout {
|
---|
| 346 | my $scheme = shift;
|
---|
| 347 | my $url = shift;
|
---|
| 348 | my $destination = shift;
|
---|
| 349 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 350 | $url = pb_vcs_mod_socks($url);
|
---|
| 351 |
|
---|
| 352 | if ($scheme =~ /^svn/) {
|
---|
| 353 | $url = pb_vcs_mod_htftp($url,"svn");
|
---|
| 354 | pb_system("$vcscmd co $url $destination","Checking out $url to $destination ");
|
---|
| 355 | } elsif ($scheme =~ /^svk/) {
|
---|
| 356 | $url = pb_vcs_mod_htftp($url,"svk");
|
---|
| 357 | pb_system("$vcscmd co $url $destination","Checking out $url to $destination ");
|
---|
| 358 | } elsif ($scheme =~ /^hg/) {
|
---|
| 359 | $url = pb_vcs_mod_htftp($url,"hg");
|
---|
| 360 | pb_system("$vcscmd clone $url $destination","Checking out $url to $destination ");
|
---|
| 361 | } elsif ($scheme =~ /^git/) {
|
---|
| 362 | $url = pb_vcs_mod_htftp($url,"git");
|
---|
| 363 | pb_system("$vcscmd clone $url $destination","Checking out $url to $destination ");
|
---|
| 364 | } elsif (($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 365 | return;
|
---|
| 366 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 367 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($url);
|
---|
| 368 |
|
---|
| 369 | # If we're working on the CVS itself
|
---|
| 370 | my $cvstag = basename($ENV{'PBROOTDIR'});
|
---|
| 371 | my $cvsopt = "";
|
---|
| 372 | if ($cvstag eq "cvs") {
|
---|
| 373 | my @date = pb_get_date();
|
---|
| 374 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 375 | $cvsopt = "-D \"$pbdate\"";
|
---|
| 376 | } else {
|
---|
| 377 | # we're working on a tag which should be the last part of PBROOTDIR
|
---|
| 378 | $cvsopt = "-r $cvstag";
|
---|
| 379 | }
|
---|
| 380 | pb_mkdir_p("$destination");
|
---|
| 381 | pb_system("cd $destination ; $vcscmd -d $account\@$host:$path co $cvsopt .","Checking out $url to $destination ");
|
---|
| 382 | } elsif ($scheme =~ /^file/) {
|
---|
| 383 | pb_vcs_export($url,undef,$destination);
|
---|
| 384 | } else {
|
---|
| 385 | die "cms $scheme unknown";
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | =item B<pb_vcs_up>
|
---|
| 390 |
|
---|
| 391 | This function updates a local directory with the VCS content.
|
---|
| 392 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
[1492] | 393 | The second parameter is the list of directory to update.
|
---|
[1469] | 394 |
|
---|
| 395 | =cut
|
---|
| 396 |
|
---|
| 397 | sub pb_vcs_up {
|
---|
| 398 | my $scheme = shift;
|
---|
[1493] | 399 | my @dir = @_;
|
---|
[1469] | 400 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 401 |
|
---|
[1539] | 402 | if ($scheme =~ /^((svn)|(cvs)|(svk))/o) {
|
---|
[1492] | 403 | pb_system("$vcscmd up ".join(' ',@dir),"Updating ".join(' ',@dir));
|
---|
[1535] | 404 | } elsif ($scheme =~ /^((hg)|(git))/o) {
|
---|
[1539] | 405 | foreach my $d (@dir) {
|
---|
| 406 | pb_system("(cd $d && $vcscmd pull)", "Updating $d ");
|
---|
| 407 | }
|
---|
[1469] | 408 | } elsif (($scheme eq "flat") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 409 | } else {
|
---|
| 410 | die "cms $scheme unknown";
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | =item B<pb_vcs_checkin>
|
---|
| 415 |
|
---|
| 416 | This function updates a VCS content from a local directory.
|
---|
| 417 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
| 418 | The second parameter is the directory to update from.
|
---|
| 419 | The third parameter is the comment to pass during the commit
|
---|
| 420 |
|
---|
| 421 | =cut
|
---|
| 422 |
|
---|
| 423 | sub pb_vcs_checkin {
|
---|
| 424 | my $scheme = shift;
|
---|
| 425 | my $dir = shift;
|
---|
| 426 | my $msg = shift;
|
---|
| 427 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 428 |
|
---|
[1539] | 429 | if ($scheme =~ /^((svn)|(cvs)|(svk))/o) {
|
---|
[1535] | 430 | pb_system("cd $dir && $vcscmd ci -m \"$msg\" .","Checking in $dir ");
|
---|
| 431 | } elsif ($scheme =~ /^git/) {
|
---|
| 432 | pb_system("cd $dir && $vcscmd commit -a -m \"$msg\"", "Checking in $dir ");
|
---|
[1469] | 433 | } elsif (($scheme eq "flat") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 434 | } else {
|
---|
| 435 | die "cms $scheme unknown";
|
---|
| 436 | }
|
---|
| 437 | pb_vcs_up($scheme,$dir);
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | =item B<pb_vcs_add>
|
---|
| 441 |
|
---|
| 442 | This function adds to a VCS content from a local directory.
|
---|
| 443 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
[1492] | 444 | The second parameter is a list of directory/file to add.
|
---|
[1469] | 445 |
|
---|
| 446 | =cut
|
---|
| 447 |
|
---|
| 448 | sub pb_vcs_add {
|
---|
| 449 | my $scheme = shift;
|
---|
[1493] | 450 | my @f = @_;
|
---|
[1469] | 451 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 452 |
|
---|
[1535] | 453 | if ($scheme =~ /^((hg)|(git)|(svn)|(svk)|(cvs))/o) {
|
---|
[1492] | 454 | pb_system("$vcscmd add ".join(' ',@f),"Adding ".join(' ',@f)." to VCS ");
|
---|
[1469] | 455 | } elsif (($scheme eq "flat") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 456 | } else {
|
---|
| 457 | die "cms $scheme unknown";
|
---|
| 458 | }
|
---|
[1492] | 459 | pb_vcs_up($scheme,@f);
|
---|
[1469] | 460 | }
|
---|
| 461 |
|
---|
| 462 | =item B<pb_vcs_isdiff>
|
---|
| 463 |
|
---|
| 464 | This function returns a integer indicating the number f differences between the VCS content and the local directory where it's checked out.
|
---|
| 465 | The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
|
---|
| 466 | The second parameter is the directory to consider.
|
---|
| 467 |
|
---|
| 468 | =cut
|
---|
| 469 |
|
---|
| 470 | sub pb_vcs_isdiff {
|
---|
| 471 | my $scheme = shift;
|
---|
| 472 | my $dir =shift;
|
---|
| 473 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
| 474 | my $l = undef;
|
---|
| 475 |
|
---|
[1539] | 476 | if ($scheme =~ /^((svn)|(cvs)|(svk))/o) {
|
---|
[1469] | 477 | open(PIPE,"$vcscmd diff $dir |") || die "Unable to get $vcscmd diff from $dir";
|
---|
| 478 | $l = 0;
|
---|
| 479 | while (<PIPE>) {
|
---|
| 480 | # Skipping normal messages in case of CVS
|
---|
| 481 | next if (/^cvs diff:/);
|
---|
| 482 | $l++;
|
---|
| 483 | }
|
---|
| 484 | } elsif (($scheme eq "flat") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 485 | $l = 0;
|
---|
| 486 | } else {
|
---|
| 487 | die "cms $scheme unknown";
|
---|
| 488 | }
|
---|
| 489 | pb_log(1,"pb_vcs_isdiff returns $l\n");
|
---|
| 490 | return($l);
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | sub pb_vcs_mod_htftp {
|
---|
| 494 |
|
---|
| 495 | my $url = shift;
|
---|
| 496 | my $proto = shift;
|
---|
| 497 |
|
---|
| 498 | $url =~ s/^$proto\+((ht|f)tp[s]*):/$1:/;
|
---|
| 499 | pb_log(1,"pb_vcs_mod_htftp returns $url\n");
|
---|
| 500 | return($url);
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | sub pb_vcs_mod_socks {
|
---|
| 504 |
|
---|
| 505 | my $url = shift;
|
---|
| 506 |
|
---|
| 507 | $url =~ s/^([A-z0-9]+)\+(socks):/$1:/;
|
---|
| 508 | pb_log(1,"pb_vcs_mod_socks returns $url\n");
|
---|
| 509 | return($url);
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 |
|
---|
| 513 | sub pb_vcs_cmd {
|
---|
| 514 |
|
---|
| 515 | my $scheme = shift;
|
---|
| 516 | my $cmd = "";
|
---|
| 517 |
|
---|
| 518 | # If there is a socks proxy to use
|
---|
| 519 | if ($scheme =~ /socks/) {
|
---|
| 520 | # Get the socks proxy command from the conf file
|
---|
| 521 | my ($pbsockscmd) = pb_conf_get("pbsockscmd");
|
---|
| 522 | $cmd = "$pbsockscmd->{$ENV{'PBPROJ'}} ";
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | if ($scheme =~ /hg/) {
|
---|
| 526 | return($cmd."hg")
|
---|
| 527 | } elsif ($scheme =~ /git/) {
|
---|
| 528 | return($cmd."git")
|
---|
| 529 | } elsif ($scheme =~ /svn/) {
|
---|
| 530 | return($cmd."svn")
|
---|
| 531 | } elsif ($scheme =~ /svk/) {
|
---|
| 532 | return($cmd."svk")
|
---|
| 533 | } elsif ($scheme =~ /cvs/) {
|
---|
| 534 | return($cmd."cvs")
|
---|
| 535 | } elsif (($scheme =~ /http/) || ($scheme =~ /ftp/)) {
|
---|
| 536 | my $command = pb_check_req("wget",1);
|
---|
| 537 | if (-x $command) {
|
---|
| 538 | return($cmd."$command -nv -O ");
|
---|
| 539 | } else {
|
---|
| 540 | $command = pb_check_req("curl",1);
|
---|
| 541 | if (-x $command) {
|
---|
| 542 | return($cmd."$command -o ");
|
---|
| 543 | } else {
|
---|
| 544 | die "Unable to handle $scheme.\nNo wget/curl available, please install one of those";
|
---|
| 545 | }
|
---|
| 546 | }
|
---|
| 547 | } else {
|
---|
| 548 | return($cmd);
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 |
|
---|
| 553 |
|
---|
| 554 | =back
|
---|
| 555 |
|
---|
| 556 | =head1 WEB SITES
|
---|
| 557 |
|
---|
| 558 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 559 |
|
---|
| 560 | =head1 USER MAILING LIST
|
---|
| 561 |
|
---|
| 562 | None exists for the moment.
|
---|
| 563 |
|
---|
| 564 | =head1 AUTHORS
|
---|
| 565 |
|
---|
| 566 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 567 |
|
---|
| 568 | =head1 COPYRIGHT
|
---|
| 569 |
|
---|
| 570 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 571 | described in the file C<COPYING> included with the distribution.
|
---|
| 572 |
|
---|
| 573 | =cut
|
---|
| 574 |
|
---|
| 575 | 1;
|
---|