#!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 integration of a job.
use strict;
use English;
use P4;
# Takes (optional) job id.
sub usage {
P4::crash("Usage: p4ib [<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(1, 'integ');
# Lock the job, then the whole depot (if the second one fails, the first will
# be released automatically). Note that these locks are _not_ released until
# either 'p4ie' or 'p4ibu' is called.
P4::lock($job, 'p4ib');
P4::lock('depot', 'p4ib');
# Obtain the job record.
my %record = P4::job_record($job);
# Verify pre-conditions.
my $status = $record{status};
P4::verify_job_status($job, \%record, 'pass');
# This helps in case something goes wrong.
$record{status} = '_integ';
P4::update_job($job, \%record);
# From this point on, the lock will NOT be released on error.
P4::unlock_on_error('depot', 0);
# Create a new change for integrating the job.
my $user = $record{user};
my $retry = $record{retry};
my $change = P4::create_change('integ', "Integrate $job-$retry by $user.");
# This enables tracking job history.
P4::create_fix($change, $job);
# Integrate the branch (thus populating it). In this case, bug #350 makes
# it a hellish job, since we _must_ get an exact image of the results in
# the local 'baseline' directory, or verification becomes a joke.
my $branch = "$user-$job-$retry";
$::OUTPUT_AUTOFLUSH = 1;
print "### Integrate development branch ...\n";
P4::integrate_branch($branch, $change, 'sure', '-r');
# Resolve the integration - in this case, it is safe just to 'accept theirs'.
$::OUTPUT_AUTOFLUSH = 1;
print "### Resolve development branch ...\n";
P4::resolve_files(0, '-at', "//depot/$user/$job-$retry/...");
# Update the job record with the change number, and set its status
# to 'integ' to indicate it is now safe for integration work.
$record{int_chg} = $change;
$record{int_client} = P4::current_client();
$record{status} = 'integ';
P4::update_job($job, \%record);
# Notify caller.
print "Integration of job $job (attempt #$retry) by $user has began.\n";
# Be nice.
1;