Commit 863602d5 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Checkpoint the switch to using subversion instead of CVS. Wow, this is

going to be a lot easier!
parent ea28187f
......@@ -38,10 +38,14 @@ my $CHMOD = "/bin/chmod";
my $TAR = "/usr/bin/tar";
my $RM = "/bin/rm";
my $CVSBIN = "/usr/bin/cvs";
my $SVN = "/usr/local/bin/svn";
my $SVNADMIN = "/usr/local/bin/svnadmin";
my $IMPORTER = "$TB/sbin/svn_load_dirs.pl";
my $inittag = 'root';
my $defaultview = 'head';
my $debug = 1;
my $cvsopt = ($debug ? "" : "-q");
my $svnopt = ($debug ? "" : "-q");
# Little helper and debug function.
sub mysystem($)
......@@ -103,16 +107,16 @@ sub ArchiveCreate(;$$)
# to hold currently checked out versions of the tree. Lastly, we
# need a place to copyin files before they are added to the repo.
#
my $cvsdir = "$dir/repo";
my $repodir = "$dir/repo";
my $checkouts = "$dir/checkouts";
my $checkins = "$dir/checkins";
if (! mkdir("$cvsdir", 0777)) {
print STDERR "ArchiveCreate: Could not mkdir $cvsdir: $!\n";
if (! mkdir("$repodir", 0777)) {
print STDERR "ArchiveCreate: Could not mkdir $repodir: $!\n";
goto bad;
}
if (! chmod(0777, "$cvsdir")) {
print STDERR "ArchiveCreate: Could not chmod $cvsdir: $!\n";
if (! chmod(0777, "$repodir")) {
print STDERR "ArchiveCreate: Could not chmod $repodir: $!\n";
goto bad;
}
if (! mkdir("$checkouts", 0777)) {
......@@ -139,18 +143,25 @@ sub ArchiveCreate(;$$)
print STDERR "ArchiveCreate: Could not chmod $checkins/$view: $!\n";
goto bad;
}
# Init the CVS control files.
mysystem("$CVSBIN $cvsopt -d $cvsdir init") == 0
# Initialize the repo.
mysystem("$SVNADMIN create $repodir") == 0
or goto bad;
# Create an stub directory and import it as "root"
mysystem("cd $dir; mkdir ignore; cd ignore; ".
"$CVSBIN $cvsopt -d $cvsdir import ".
"-m 'Initialize' root $tag ${tag}_init")
# Create an stub directory tree and import it as "root"
mysystem("cd $dir; mkdir ignore; cd ignore; mkdir $view; ".
" mkdir $view/trunk $view/savepoint $view/tags; ".
"$SVN import -m 'ArchiveCreate' $view file://$repodir/$view")
== 0 or goto bad;
# Create a branch tag in the tags directory to base differences against.
mysystem("$SVN copy -m 'ArchiveCreate Branch' ".
" file://$repodir/$view/trunk ".
" file://$repodir/$view/tags/${tag}-branch")
== 0 or goto bad;
# Now check it out. This creates the $checkouts/$view directory.
mysystem("cd $checkouts; ".
"$CVSBIN $cvsopt -d $cvsdir checkout root; ".
"/bin/mv root ${view}")
"$SVN checkout $svnopt file://$repodir/$view")
== 0 or goto bad;
# Now enter the default view (okay, branch) of this archive.
......@@ -160,7 +171,7 @@ sub ArchiveCreate(;$$)
# Now enter an initial tag for the tree. Nothing actually gets tagged.
DBQueryWarn("insert into archive_tags set idx=NULL, ".
" tag='$tag', archive_idx='$idx', revision='1.1', ".
" tag='$tag', archive_idx='$idx', ".
" date_created=UNIX_TIMESTAMP(now())") or goto bad;
return $idx;
......@@ -243,7 +254,7 @@ sub ArchiveAdd($$;$)
print STDERR "ArchiveFile: $directory cannot be written!\n";
return -1;
}
my $cvsdir = "$directory/repo";
my $repodir = "$directory/repo";
my $checkout = "$directory/checkouts/$view";
my $checkin = "$directory/checkins/$view";
......@@ -305,7 +316,7 @@ sub ArchiveSavePoint($;$$)
print STDERR "ArchiveSavePoint: $directory cannot be written!\n";
goto bad;
}
my $cvsdir = "$directory/repo";
my $repodir = "$directory/repo";
my $checkout = "$directory/checkouts/$view";
my $checkin = "$directory/checkins/$view";
......@@ -321,9 +332,8 @@ sub ArchiveSavePoint($;$$)
}
# Get the current tag for the archive.
my ($archive_tag, $archive_revision);
if (GetArchiveCurrentTags($archive_idx, $view,
\$archive_tag, \$archive_revision) < 0) {
my ($archive_tag);
if (GetArchiveCurrentTags($archive_idx, $view, \$archive_tag) < 0) {
print STDERR "ArchiveSavePoint: ".
"Archive '$archive_idx' does not have a current tag!\n";
goto bad;
......@@ -344,60 +354,35 @@ sub ArchiveSavePoint($;$$)
}
#
# Use cvs import command. This is nice cause it handles all the
# Use svn import command. This is nice cause it handles all the
# subdirs and stuff in one shot, instead of trying to deal with
# each file and directory individually.
#
# NOTE: Need to specify the current "vendor" branch to import on,
# or else cvs always uses 1.1.1. After each commit to the head, we
# bump this so that the savepoints are logically distinct and clearly
# associated with its head branch.
#
my $rev = "${archive_revision}.1";
my $bopt = "-b $rev";
if (! chdir("$checkout")) {
print STDERR "ArchiveSavePoint: Cannot chdir to $checkout!\n";
if (! chdir("$checkin")) {
print STDERR "ArchiveSavePoint: Cannot chdir to $checkin!\n";
goto bad;
}
mysystem("$IMPORTER -no_user_input file://$repodir ".
" $view/savepoint . > /dev/null")
== 0 or goto bad;
#
# Ack! We need to set the default branch to match the head revision.
# I think CVS is totally screwed up on this!
# Create the tag for this savepoint.
#
#mysystem("rcs -b${rev} ".
# "`$CVSBIN $cvsopt -d $cvsdir -q log -R`");
mysystem("$SVN copy -m 'ArchiveCreate Branch' ".
" file://$repodir/$view/savepoint ".
" file://$repodir/$view/tags/${savetag}")
== 0 or goto bad;
# Now do the import.
if (! chdir("$checkin")) {
print STDERR "ArchiveSavePoint: Cannot chdir to $checkin!\n";
goto bad;
}
mysystem("$CVSBIN $cvsopt -d $cvsdir import $bopt ".
"-m 'SavePoint' root $archive_tag $savetag");
if ($?) {
print STDERR "ArchiveCommit: Could not import from $checkin!\n";
goto bad;
}
#
# And record the new tag.
#
DBQueryWarn("insert into archive_tags set idx=NULL, ".
" tag='$savetag', revision='${archive_revision}', ".
" tag='$savetag', ".
" archive_idx='$archive_idx', ".
" date_created=UNIX_TIMESTAMP(now())") or goto bad;
# And now into the checkout dir to checkout a current copy.
if (! chdir("$checkout")) {
print STDERR "ArchiveSavePoint: Cannot chdir to $checkout!\n";
goto bad;
}
mysystem("$CVSBIN $cvsopt -d $cvsdir update -dP -r $rev");
if ($?) {
print STDERR "ArchiveSavePoint: Could not checkout revision!\n";
goto bad;
}
okay:
TBScriptUnlock();
chdir($cwd)
......@@ -418,6 +403,7 @@ sub ArchiveSavePoint($;$$)
sub ArchiveCommit($;$$$)
{
my ($archive_idx, $newtag, $view, $altdir) = @_;
my $noactivity = 0;
my $cwd;
$view = $defaultview
......@@ -440,7 +426,7 @@ sub ArchiveCommit($;$$$)
print STDERR "ArchiveCommit: $directory cannot be written!\n";
goto bad;
}
my $cvsdir = "$directory/repo";
my $repodir = "$directory/repo";
my $checkout = "$directory/checkouts/$view";
my $checkin = (defined($altdir) ? $altdir : "$directory/checkins/$view");
......@@ -461,30 +447,17 @@ sub ArchiveCommit($;$$$)
}
# Get the current tags for the archive.
my ($archive_tag, $archive_revision, $previous_tag);
my ($archive_tag, $previous_tag);
if (GetArchiveCurrentTags($archive_idx, $view, \$archive_tag,
\$archive_revision, \$previous_tag) < 0) {
\$previous_tag) < 0) {
print STDERR "ArchiveCommit: ".
"Archive '$archive_idx' does not have a current tag!\n";
goto bad;
}
#
# Lets see if there has been any action since the last commit.
# Check for new tags.
# Form new tag.
#
my $query_result =
DBQueryWarn("select tag from archive_tags ".
"where archive_idx='$archive_idx' ".
"order by idx desc limit 1");
goto bad
if (!$query_result || !$query_result->numrows);
my ($tmptag) = $query_result->fetchrow_array();
if ($tmptag eq $archive_tag) {
print "ArchiveCommit: Archive is clean; no need to commit.\n";
goto okay;
}
my ($seconds, $microseconds) = gettimeofday();
my $import_tag = POSIX::strftime("T20%y%m%d-%H%M%S-", localtime());
$import_tag .= $microseconds;
......@@ -498,6 +471,24 @@ sub ArchiveCommit($;$$$)
$newtag = "T" . $newtag;
}
#
# Lets see if there has been any action since the last commit.
# Check for new tags, and if nothing has happened, just drop a
# new set of tags in and return.
#
my $query_result =
DBQueryWarn("select tag from archive_tags ".
"where archive_idx='$archive_idx' ".
"order by idx desc limit 1");
goto bad
if (!$query_result || !$query_result->numrows);
my ($tmptag) = $query_result->fetchrow_array();
if ($tmptag eq $archive_tag) {
print "ArchiveCommit: Archive is clean; no need to commit.\n";
$noactivity = 1;
}
# Clean the temp dir for next phase.
mysystem("/bin/rm -rf $checkin/*");
if ($?) {
......@@ -506,95 +497,55 @@ sub ArchiveCommit($;$$$)
}
#
# Form a new head revision and branch tag.
# Okay, do the commit to the trunk for this view.
#
my $next_revision;
if ($archive_revision =~ /^(\d*)\.(\d*)$/) {
$next_revision = $1 . "." . ($2 + 1);
}
else {
print STDERR "ArchiveCommit: ".
"Could not parse revision $archive_revision!\n";
goto bad;
}
if (! $noactivity) {
#
# If this is the first commit of the archive, then just checkout
# and commit to a new head revision.
# Check out the current trunk.
#
if ($archive_revision eq "1.1") {
mysystem("$CVSBIN $cvsopt -d $cvsdir checkout root");
if ($?) {
print STDERR "ArchiveCommit: ".
"Could not checkout $archive_tag!\n";
goto bad;
}
}
else {
#
# Need to merge. Do a fresh checkout, merging the current import branch
# into the head revsion.
mysystem("$SVN checkout $svnopt file://$repodir/$view/trunk")
== 0 or goto bad;
#
# Yuck. Need to clear the -b (default branch) or else the merge
# commit fails for some reason that makes no sense to me, but
# must make sense to someone at CVS headquarters.
# Do a merge from the branch off the previous commit tag, with
# the savepoint. This is merged into the working directory we
# just checked out above. This will do the work of scheduling
# additions and deletions.
#
mysystem("$CVSBIN $cvsopt -d $cvsdir ".
"checkout -r $archive_revision root");
if ($?) {
print STDERR "ArchiveCommit: ".
"Could not checkout revision $archive_revision!\n";
goto bad;
}
mysystem("$CVSBIN $cvsopt -d $cvsdir admin -b root");
if ($?) {
print STDERR "ArchiveCommit: ".
"Could not clear the default branch!\n";
goto bad;
}
mysystem("$CVSBIN $cvsopt -d $cvsdir update -A ".
"-j $previous_tag -j $archive_tag root");
if ($?) {
print STDERR "ArchiveCommit: ".
"Could not checkout and merge $archive_tag into head.!\n";
goto bad;
}
}
mysystem("$SVN merge $svnopt ".
" file://$repodir/$view/tags/${archive_tag}-branch ".
" file://$repodir/$view/savepoint ".
" trunk")
== 0 or goto bad;
#
# And then commit it back to the head revision, using bumped rev number.
# Now commit to the trunk!
#
mysystem("$CVSBIN $cvsopt -d $cvsdir commit -f -R -r $next_revision ".
"-m 'Commit merge of ${archive_tag} with head'");
if ($?) {
print STDERR "ArchiveCommit: ".
"Could not commit merge back to the repository!\n";
goto bad;
mysystem("$SVN commit $svnopt ".
" -m 'Commit merge of ${archive_tag} to trunk' trunk")
== 0 or goto bad;
}
#
# Ack! We need to advance the default branch to match the head revision.
# I think CVS is totally screwed up on this!
#
mysystem("rcs -b${next_revision}.1 ".
"`$CVSBIN $cvsopt -d $cvsdir -q log -R`");
# Create a tag in the tags directory for the commit.
mysystem("$SVN copy -m 'ArchiveCommit' ".
" file://$repodir/$view/trunk ".
" file://$repodir/$view/tags/${newtag}")
== 0 or goto bad;
DBQueryWarn("insert into archive_tags set idx=NULL, ".
" tag='$import_tag', revision='${next_revision}', ".
" archive_idx='$archive_idx', ".
" date_created=UNIX_TIMESTAMP(now())")
or goto bad;
# Create a branch tag in the tags directory to base differences against.
mysystem("$SVN copy -m 'ArchiveCommit Branch' ".
" file://$repodir/$view/trunk ".
" file://$repodir/$view/tags/${newtag}-branch")
== 0 or goto bad;
DBQueryWarn("insert into archive_tags set idx=NULL, ".
" tag='$newtag', revision='${next_revision}', ".
" tag='$newtag', ".
" archive_idx='$archive_idx', ".
" date_created=UNIX_TIMESTAMP(now())")
or goto bad;
DBQueryWarn("update archive_views set ".
" current_tag='$import_tag', ".
" current_tag='$newtag', ".
" previous_tag='$archive_tag' ".
"where archive_idx='$archive_idx' and view='$view'")
or goto bad;
......@@ -606,21 +557,14 @@ sub ArchiveCommit($;$$$)
goto bad;
}
# And lets tag the tree for good measure with a commit tag.
mysystem("$CVSBIN $cvsopt -d $cvsdir rtag -r $next_revision $newtag root");
if ($?) {
print STDERR "ArchiveCommit: Could not rtag with $newtag!\n";
goto bad;
}
# And now into the checkout dir to checkout a current copy.
if (! chdir("$checkout")) {
print STDERR "ArchiveCommit: Cannot chdir to $checkout!\n";
goto bad;
}
mysystem("$CVSBIN $cvsopt -d $cvsdir update -dP -r $next_revision");
mysystem("$SVN $svnopt update trunk");
if ($?) {
print STDERR "ArchiveCommit: Could not checkout head revision!\n";
print STDERR "ArchiveCommit: Could not update head revision!\n";
goto bad;
}
okay:
......@@ -685,9 +629,9 @@ sub ArchiveFork($$;$)
}
# Get the current tags for the archive.
my ($archive_tag, $archive_revision, $previous_tag);
my ($archive_tag, $previous_tag);
if (GetArchiveCurrentTags($archive_idx, $view, \$archive_tag,
\$archive_revision, \$previous_tag) < 0) {
\$previous_tag) < 0) {
print STDERR "ArchiveCommit: ".
"Archive '$archive_idx' does not have a current tag!\n";
goto bad;
......@@ -704,7 +648,7 @@ sub ArchiveFork($$;$)
}
# Now checkout new view; this creates the $checkouts/$newview directory.
mysystem("cd $checkouts; ".
"$CVSBIN $cvsopt -d $cvsdir checkout -r $archive_revision root; ".
"$CVSBIN $cvsopt -d $cvsdir checkout root; ".
"/bin/mv root ${newview}")
== 0 or goto bad;
......@@ -834,12 +778,12 @@ sub GetArchiveDirectory($$)
# Get the current tag for an archive, given its index. Returns -1 on error,
# zero otherwise. Place tag in the return pointer.
#
sub GetArchiveCurrentTags($$$;$$)
sub GetArchiveCurrentTags($$$;$)
{
my ($archive_idx, $view, $tagp, $revnump, $prevp) = @_;
my ($archive_idx, $view, $tagp, $prevp) = @_;
my $query_result =
DBQueryWarn("select v.current_tag,t.revision,v.previous_tag ".
DBQueryWarn("select v.current_tag,v.previous_tag ".
" from archive_views as v ".
"left join archive_tags as t on ".
" t.archive_idx=v.archive_idx and ".
......@@ -849,12 +793,10 @@ sub GetArchiveCurrentTags($$$;$$)
return -1
if (!$query_result);
my ($tag,$revision,$previous) = $query_result->fetchrow_array();
my ($tag,$previous) = $query_result->fetchrow_array();
$$tagp = $tag
if (defined($tagp));
$$revnump = $revision
if (defined($revnump));
$$prevp = $previous
if (defined($prevp));
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment