/*
 *	aegis - project change supervisor
 *	Copyright (C) 2001, 2006-2008 Peter Miller
 *
 *	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 3 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, see
 *	<http://www.gnu.org/licenses/>.
 */
auto src, dst;
src = arg[0];
dst = arg[1];

auto ps;
ps = project[project_name()].state;

auto cs;
cs = ps.branch.change[change_number()];

/* one column 1000 chars wide */
columns(1000);

if (cs.state == completed)
{
	/*
	 * The the change has been completed, extact the historical
	 * version from history.
	 */
	print("$bindir/aegis -cp -ind -p " ## project_name() ## " -delta " ##
		cs.delta_number ## " " ## src ## " -o " ## dst);
}
else if (cs.state == awaiting_development)
{
	/*
	 * If the change hasn't happened yet, extract the baseline version.
	 */
	print("$bindir/aegis -cp -ind -p " ## project_name() ## " " ##
		src ## " -o " ## dst);
}
else
{
	/*
	 * If the change is being actively developed, copy directly from
	 * the development directory.
	 */
	auto f, found;
	found = false;
	for (f in cs.src)
	{
		if (f.file_name == src)
			found = true;
	}
	if (found)
	{
		print("cp " ## cs.development_directory ## "/" ## src ##
			" " ## dst);
	}
	else
	{
		print("$bindir/aegis -cp -ind -p " ## project_name() ## " " ##
			src ## " -o " ## dst);
	}
}
