svn commit: r266153 - user/des/tinderbox

Dag-Erling Smørgrav des at FreeBSD.org
Thu May 15 16:17:22 UTC 2014


Author: des
Date: Thu May 15 16:17:21 2014
New Revision: 266153
URL: http://svnweb.freebsd.org/changeset/base/266153

Log:
  Add a revert command which runs svn revert and removes any leftovers.
  Clean up and simplify the svn checkout / update code.

Modified:
  user/des/tinderbox/tbmaster.pl
  user/des/tinderbox/tinderbox.1
  user/des/tinderbox/tinderbox.pl

Modified: user/des/tinderbox/tbmaster.pl
==============================================================================
--- user/des/tinderbox/tbmaster.pl	Thu May 15 16:11:06 2014	(r266152)
+++ user/des/tinderbox/tbmaster.pl	Thu May 15 16:17:21 2014	(r266153)
@@ -34,7 +34,7 @@ use POSIX;
 use Getopt::Long;
 use Storable qw(dclone);
 
-my $VERSION	= "2.21";
+my $VERSION	= "2.22";
 my $COPYRIGHT	= "Copyright (c) 2003-2014 Dag-Erling Smørgrav. " .
 		  "All rights reserved.";
 

Modified: user/des/tinderbox/tinderbox.1
==============================================================================
--- user/des/tinderbox/tinderbox.1	Thu May 15 16:11:06 2014	(r266152)
+++ user/des/tinderbox/tinderbox.1	Thu May 15 16:17:21 2014	(r266153)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd March 24, 2014
+.Dd May 15, 2014
 .Dt TINDERBOX 1
 .Os
 .Sh NAME
@@ -194,12 +194,11 @@ Delete the object tree at the start of e
 Delete the installation tree at the start of each job.
 .It Cm precleanroot
 Delete the release chroot tree at the start of each job.
+.It Cm revert
+Revert the source tree to a clean state.
 .It Cm update
-Update the sources using
+Update the source tree using
 .Xr svn 1 .
-This is highly recommended, for obvious reasons, if the
-.Cm clean
-command is specified.
 .It Cm patch
 Apply the patch specified with the
 .Fl -patch
@@ -207,6 +206,9 @@ option to the source tree.
 If the specified patch file does not exist, the
 .Cm patch
 command will fail gracefully.
+.It Cm version
+After updating and patching the source tree but before doing anything
+else, log information about the current state of the source tree.
 .It Cm world
 Build the world.
 .It Cm lint
@@ -270,9 +272,6 @@ but at the end of each job.
 As
 .Cm precleanroot ,
 but at the end of each job.
-.It Cm version
-After updating and patching the source tree but before doing anything
-else, log information about the current state of the source tree.
 .El
 .Pp
 The commands are executed in the order in which they are listed above,

Modified: user/des/tinderbox/tinderbox.pl
==============================================================================
--- user/des/tinderbox/tinderbox.pl	Thu May 15 16:11:06 2014	(r266152)
+++ user/des/tinderbox/tinderbox.pl	Thu May 15 16:17:21 2014	(r266153)
@@ -34,7 +34,7 @@ use POSIX;
 use Getopt::Long;
 use Scalar::Util qw(tainted);
 
-my $VERSION	= "2.21";
+my $VERSION	= "2.22";
 my $COPYRIGHT	= "Copyright (c) 2003-2014 Dag-Erling Smørgrav. " .
 		  "All rights reserved.";
 
@@ -65,6 +65,7 @@ my %cmds = (
     'cleanobj'	=> 0, 'precleanobj'	=> 0, 'postcleanobj'	=> 0,
     'cleaninst'	=> 0, 'precleaninst'	=> 0, 'postcleaninst'	=> 0,
     'cleanobj'	=> 0, 'precleanobj'	=> 0, 'postcleanobj'	=> 0,
+    'revert'	=> 0,
     'update'	=> 0,
     'patch'	=> 0,
     'world'	=> 0,
@@ -615,45 +616,75 @@ MAIN:{
     do_clean(); # no prefix for backward compatibility
     do_clean('pre');
 
-    # Check out new source tree
-    if ($cmds{'update'}) {
-	if (defined($svnbase)) {
-	    my @svnargs;
-	    push(@svnargs, "--quiet")
-		unless ($verbose);
-	    # ugly-bugly magic required because CVS to SVN conversion
-	    # smashed branch names
-	    $svnbase =~ s/\/$//;
-	    if ($branch eq 'HEAD') {
-		$svnbase .= '/head';
-	    } elsif ($branch =~ m/^RELENG_(\d+)_(\d+)$/) {
-		$svnbase .= "/releng/$1.$2";
-	    } elsif ($branch =~ m/^RELENG_(\d+)$/) {
-		$svnbase .= "/stable/$1";
+    # Locate svn
+    my $svncmd = '/usr/bin/false';
+    if ($cmds{'revert'} || $cmds{'version'} || $cmds{'update'}) {
+	$svncmd = [grep({ -x } @svncmds)]->[0]
+	    or error("unable to locate svn binary");
+    }
+
+    # Revert sources
+    if ($cmds{'revert'} && -d "$srcdir/.svn") {
+	my @svnargs;
+	push(@svnargs, "--quiet")
+	    unless ($verbose);
+	logstage("reverting $srcdir");
+	spawn($svncmd, @svnargs, "upgrade", $srcdir);
+	spawn($svncmd, @svnargs, "cleanup", $srcdir);
+	spawn($svncmd, @svnargs, "revert", "-R", $srcdir)
+	    or error("unable to revert the source tree");
+	# remove leftovers...  ugly!
+	open(my $pipe, '-|', $svncmd, "stat", "--no-ignore", $srcdir)
+	    or error("unable to stat source tree");
+	while (<$pipe>) {
+	    m/^[I?]\s+(\S.*)$/ or next;
+	    if (-d $1) {
+		remove_dir($1)
+		    or error("unable to remove $1");
+	    } elsif (-f $1 || -l $1) {
+		unlink($1)
+		    or error("unable to remove $1");
 	    } else {
-		error("unrecognized branch: $branch");
+		warning("ignoring $1");
 	    }
-	    logstage("checking out $srcdir from $svnbase");
-	    my $svncmd = [grep({ -x } @svncmds)]->[0]
-		or error("unable to locate svn binary");
-	    cd("$sandbox");
+	}
+	close($pipe);
+    }
+
+    # Check out new source tree
+    if ($cmds{'update'}) {
+	error("no svn base URL defined")
+	    unless defined($svnbase);
+	my @svnargs;
+	push(@svnargs, "--quiet")
+	    unless ($verbose);
+	# ugly-bugly magic required because CVS to SVN conversion
+	# smashed branch names
+	$svnbase =~ s/\/$//;
+	if ($branch eq 'HEAD') {
+	    $svnbase .= '/head';
+	} elsif ($branch =~ m/^RELENG_(\d+)_(\d+)$/) {
+	    $svnbase .= "/releng/$1.$2";
+	} elsif ($branch =~ m/^RELENG_(\d+)$/) {
+	    $svnbase .= "/stable/$1";
+	} else {
+	    error("unrecognized branch: $branch");
+	}
+	logstage("checking out $srcdir from $svnbase");
+	cd("$sandbox");
+	for (0..$svnattempts) {
 	    if (-d "$srcdir/.svn") {
 		spawn($svncmd, "upgrade", $srcdir);
 		spawn($svncmd, "cleanup", $srcdir);
-		push(@svnargs, "update", $srcdir);
+		last if spawn($svncmd, @svnargs, "update", $srcdir);
 	    } else {
-		push(@svnargs, "checkout", $svnbase, $srcdir);
-	    }
-	    for (0..$svnattempts) {
-		last if spawn($svncmd, @svnargs);
-		error("unable to check out the source tree")
-		    if ($_ == $svnattempts);
-		my $delay = 30 * ($_ + 1);
-		warning("sleeping $delay s and retrying...");
-		sleep($delay);
+		last if spawn($svncmd, @svnargs, "checkout", $svnbase, $srcdir);
 	    }
-	} else {
-	    error("no svn base URL defined");
+	    error("unable to check out the source tree")
+		if ($_ == $svnattempts);
+	    my $delay = 30 * ($_ + 1);
+	    warning("sleeping $delay s and retrying...");
+	    sleep($delay);
 	}
     }
 
@@ -682,8 +713,6 @@ MAIN:{
     # Print source tree version information
     if ($cmds{'version'}) {
 	if (defined($svnbase)) {
-	    my $svncmd = [grep({ -x } @svncmds)]->[0]
-		or error("unable to locate svn binary");
 	    my $svnversioncmd = [grep({ -x } @svnversioncmds)]->[0]
 		or error("unable to locate svnversion binary");
 	    if ($verbose) {


More information about the svn-src-user mailing list