#!perl -w
# Copyright (C) 1997 Capella Computers Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# :FILE:
# Start working on a new job.
use strict;
use English;
use P4;
# Takes (optional) job id.
sub usage {
P4::crash("Usage: p4wb [<job>]");
}
# Parse command line.
my $job;
if ($#ARGV < 0) {
$job = P4::current_job();
} elsif ($ARGV[0] eq '-h') {
usage();
} elsif ($ARGV[0] =~ /^\d+$/) {
$job = shift(@ARGV);
}
if ($#ARGV >= 0) {
usage();
}
# Verify quick pre-conditions.
P4::verify_current_user(0, 'integ');
# Lock depot to avoid race conditions.
P4::lock($job, 'p4wb');
# Obtain the job record.
my %record = P4::job_record($job);
# Verify pre-conditions.
my $status = $record{status};
P4::verify_job_status($job, \%record, 'new');
# This helps in case something goes wrong.
my $user = P4::current_user();
$record{user} = $user;
$record{status} = '_work';
P4::update_job($job, \%record);
# Create a branch for working on this job.
my $retry = $record{retry};
my $branch = "$user-$job-$retry";
P4::create_branch($branch, "for $user to work on $job",
'//depot/baseline/...', "//depot/$user/$job-$retry/...");
# Create a new change for populating the branch.
my $change = P4::create_change($user, "Begin $job-$retry by $user.");
# Integrate the branch (thus populating it). In this case, bug #350 does
# not bother us, since we'll submit the change in a moment anyway.
$::OUTPUT_AUTOFLUSH = 1;
print "### Create development branch ...\n";
P4::integrate_branch($branch, $change, 'quick');
# Submit the change.
$::OUTPUT_AUTOFLUSH = 1;
print "### Submit creation of development branch ...\n";
$change = P4::submit_change($change);
# This enables tracking job history.
P4::create_fix($change, $job);
# Finally, we need to get the branch files.
$::OUTPUT_AUTOFLUSH = 1;
print "### Get development files ...\n";
P4::get_files("//depot/$user/$job-$retry/...");
# Create the change for working on this branch.
$change = P4::create_change($user, "Work on $job-$retry by $user.");
# Again, this enables tracking job history.
P4::create_fix($change, $job);
# Update the job record with the change number, and set its status to 'work'
# to indicate it is now safe to work with.
$record{dev_chg} = $change;
$record{dev_client} = P4::current_client();
$record{status} = 'work';
P4::update_job($job, \%record);
# Release obtained locks.
P4::unlock();
# Notify caller.
print "Work on job $job (attempt #$retry) by $user has began.\n";
# Be nice.
1;