/*
* px *
Copyright (c) 2008 Shawn Hladky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "pxheaders.h"
#include "jobfiles.h"
#include "jobfiles_fixesclientuser.h"
#include "jobfiles_filesclientuser.h"
ErrorId jobfiles_usage = { ErrorOf( ES_CLIENT, 0, E_INFO, EV_USAGE, 0 ),
"\n"
" jobfiles -- List files fixed by jobs\n"
"\n"
" px jobfiles [-s] job(s)...\n"
"\n"
" 'px jobfiles' lists all files in changelists fixed by the\n"
" jobs supplied. Multiple jobs can be specified. No files\n"
" are listed for non-existant jobs, and no error is displayed\n"
" (which is consitient with p4 fixes).\n"
"\n"
" The -s flag causes a summary view where each file is listed once\n"
" at the highest revision.\n"
"\n"};
void jobfilesCommand::Help(Error *e)
{
e->Set(jobfiles_usage);
}
void jobfilesCommand::Run(ClientUser* cu, ClientApi* api, char *const *argv, int argc)
{
Options opts;
Error e;
int iargc = argc;
char** iargv = (char**) argv;
ErrorId usage = {E_INFO , "Usage: jobfiles [-s] jobs..." };
opts.Parse( iargc, iargv, "s", OPT_SOME, usage, &e);
if (e.Test())
{
cu->Message(&e);
return;
}
ErrorId fileInfo = {ErrorOf( ES_CLIENT, 0, E_INFO, EV_CLIENT, 2) , "%depotFile%#%rev% - %action% change %change% (%type%)" };
//if(tagged)
//{
// printf("tagged mode\n");
//}
//else
//{
// printf("NO tagged mode\n");
//}
bool summary;
if(opts['s'])
{
//printf("sumary mode\n");
summary = true;
}
else
{
//printf("NO sumary mode\n");
summary = false;
}
if(iargc == 0)
{
// shouldn't opts error if this is the case?
}
else
{
// run fixes on each job
JobFiles_FixesClientUser fixesCU;
for (int i = 0; i < iargc; i++)
{
StrRef job(iargv[i]);
api->SetVar("tag", "");
api->SetVar("", "-j");
api->SetVar("", job);
api->Run("fixes", &fixesCU);
}
std::list<int> changes = fixesCU.GetChanges();
if (changes.size() == 0)
{
printf("no fixes for job\n");
return;
}
//else
//{
// printf("%d fixes for job\n", changes.size());
// return;
//}
// build the arg list for files (use @=change);
for(std::list<int>::const_iterator it = changes.begin(); it != changes.end(); it++)
{
StrBuf change;
change << "@=";
change << *it;
api->SetVar("", change);
}
JobFiles_FilesClientUser filesCU(tagged, summary, caseSensitive, cu);
// finally run files
api->SetVar("tag", "");
api->Run("files", &filesCU);
}
}