ENH: Factor out VCS work tree revision checks
This moves checks of the work tree revision before and after update from cmCTestUpdateHandler::ProcessHandler into the cmCTestVC hierarchy.
This commit is contained in:
parent
d76bc78a12
commit
de3dedb4ea
|
@ -16,6 +16,10 @@
|
|||
=========================================================================*/
|
||||
#include "cmCTestSVN.h"
|
||||
|
||||
#include "cmCTest.h"
|
||||
|
||||
#include <cmsys/RegularExpression.hxx>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmCTestSVN::cmCTestSVN(cmCTest* ct, std::ostream& log): cmCTestVC(ct, log)
|
||||
{
|
||||
|
@ -35,3 +39,58 @@ void cmCTestSVN::CleanupImpl()
|
|||
OutputLogger err(this->Log, "cleanup-err> ");
|
||||
this->RunChild(svn_cleanup, &out, &err);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class cmCTestSVN::InfoParser: public cmCTestVC::LineParser
|
||||
{
|
||||
public:
|
||||
InfoParser(cmCTestSVN* svn, const char* prefix, std::string& rev):
|
||||
SVN(svn), Rev(rev)
|
||||
{
|
||||
this->SetLog(&svn->Log, prefix);
|
||||
this->RegexRev.compile("^Revision: ([0-9]+)");
|
||||
}
|
||||
private:
|
||||
cmCTestSVN* SVN;
|
||||
std::string& Rev;
|
||||
cmsys::RegularExpression RegexRev;
|
||||
virtual bool ProcessLine()
|
||||
{
|
||||
if(this->RegexRev.find(this->Line))
|
||||
{
|
||||
this->Rev = this->RegexRev.match(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cmCTestSVN::LoadInfo()
|
||||
{
|
||||
// Run "svn info" to get the repository info from the work tree.
|
||||
const char* svn = this->CommandLineTool.c_str();
|
||||
const char* svn_info[] = {svn, "info", 0};
|
||||
std::string rev;
|
||||
InfoParser out(this, "info-out> ", rev);
|
||||
OutputLogger err(this->Log, "info-err> ");
|
||||
this->RunChild(svn_info, &out, &err);
|
||||
return rev;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCTestSVN::NoteOldRevision()
|
||||
{
|
||||
this->OldRevision = this->LoadInfo();
|
||||
this->Log << "Revision before update: " << this->OldRevision << "\n";
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
|
||||
<< this->OldRevision << "\n");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCTestSVN::NoteNewRevision()
|
||||
{
|
||||
this->NewRevision = this->LoadInfo();
|
||||
this->Log << "Revision after update: " << this->NewRevision << "\n";
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
|
||||
<< this->NewRevision << "\n");
|
||||
}
|
||||
|
|
|
@ -31,9 +31,23 @@ public:
|
|||
|
||||
virtual ~cmCTestSVN();
|
||||
|
||||
int GetOldRevision() { return atoi(this->OldRevision.c_str()); }
|
||||
int GetNewRevision() { return atoi(this->NewRevision.c_str()); }
|
||||
private:
|
||||
// Implement cmCTestVC internal API.
|
||||
virtual void CleanupImpl();
|
||||
virtual void NoteOldRevision();
|
||||
virtual void NoteNewRevision();
|
||||
|
||||
// Old and new repository revisions.
|
||||
std::string OldRevision;
|
||||
std::string NewRevision;
|
||||
|
||||
std::string LoadInfo();
|
||||
|
||||
// Parsing helper classes.
|
||||
class InfoParser;
|
||||
friend class InfoParser;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -383,73 +383,18 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
|
||||
bool res = true;
|
||||
|
||||
// First, check what the current state of repository is
|
||||
std::string command = "";
|
||||
switch( this->UpdateType )
|
||||
{
|
||||
case cmCTestUpdateHandler::e_CVS:
|
||||
// TODO: CVS - for now just leave empty
|
||||
break;
|
||||
case cmCTestUpdateHandler::e_SVN:
|
||||
command = "\"" + this->UpdateCommand + "\" info";
|
||||
break;
|
||||
}
|
||||
|
||||
// CVS variables
|
||||
// SVN variables
|
||||
int svn_current_revision = 0;
|
||||
int svn_latest_revision = 0;
|
||||
int svn_use_status = 0;
|
||||
|
||||
//
|
||||
// Get initial repository information if that is possible. With subversion,
|
||||
// this will check the current revision.
|
||||
//
|
||||
if ( !command.empty() )
|
||||
// Get initial repository information if that is possible.
|
||||
vc->MarkOldRevision();
|
||||
if(this->UpdateType == e_SVN)
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"* Get repository information: " << command.c_str() << std::endl);
|
||||
if ( !this->CTest->GetShowOnly() )
|
||||
{
|
||||
ofs << "* Get repository information" << std::endl;
|
||||
ofs << " Command: " << command.c_str() << std::endl;
|
||||
res = this->CTest->RunCommand(command.c_str(), &goutput, &errors,
|
||||
&retVal, sourceDirectory, 0 /*this->TimeOut*/);
|
||||
|
||||
ofs << " Output: " << goutput.c_str() << std::endl;
|
||||
ofs << " Errors: " << errors.c_str() << std::endl;
|
||||
if ( ofs )
|
||||
{
|
||||
ofs << "--- Update information ---" << std::endl;
|
||||
ofs << goutput << std::endl;
|
||||
}
|
||||
switch ( this->UpdateType )
|
||||
{
|
||||
case cmCTestUpdateHandler::e_CVS:
|
||||
// TODO: CVS - for now just leave empty
|
||||
break;
|
||||
case cmCTestUpdateHandler::e_SVN:
|
||||
{
|
||||
cmsys::RegularExpression current_revision_regex(
|
||||
"Revision: ([0-9]+)");
|
||||
if ( current_revision_regex.find(goutput.c_str()) )
|
||||
{
|
||||
std::string currentRevisionString
|
||||
= current_revision_regex.match(1);
|
||||
svn_current_revision = atoi(currentRevisionString.c_str());
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Old revision of repository is: " << svn_current_revision
|
||||
<< std::endl);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"Get information with command: " << command << std::endl);
|
||||
}
|
||||
svn_current_revision =
|
||||
static_cast<cmCTestSVN*>(vc.get())->GetOldRevision();
|
||||
}
|
||||
|
||||
|
||||
|
@ -468,6 +413,7 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
static_cast<unsigned int>(cmSystemTools::GetTime());
|
||||
double elapsed_time_start = cmSystemTools::GetTime();
|
||||
|
||||
std::string command;
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "* Update repository: "
|
||||
<< command.c_str() << std::endl);
|
||||
if ( !this->CTest->GetShowOnly() )
|
||||
|
@ -570,31 +516,13 @@ int cmCTestUpdateHandler::ProcessHandler()
|
|||
int numUpdated = 0;
|
||||
int numModified = 0;
|
||||
int numConflicting = 0;
|
||||
// In subversion, get the latest revision
|
||||
|
||||
// Get final repository information if that is possible.
|
||||
vc->MarkNewRevision();
|
||||
if ( this->UpdateType == cmCTestUpdateHandler::e_SVN )
|
||||
{
|
||||
for ( cc= 0; cc < lines.size(); cc ++ )
|
||||
{
|
||||
const char* line = lines[cc].c_str();
|
||||
if ( svn_latest_revision_regex.find(line) )
|
||||
{
|
||||
svn_latest_revision = atoi(
|
||||
svn_latest_revision_regex.match(2).c_str());
|
||||
}
|
||||
}
|
||||
if ( svn_latest_revision <= 0 )
|
||||
{
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Problem determining the current "
|
||||
"revision of the repository from output:" << std::endl
|
||||
<< goutput.c_str() << std::endl);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
" Current revision of repository is: " << svn_latest_revision
|
||||
<< std::endl);
|
||||
}
|
||||
svn_latest_revision =
|
||||
static_cast<cmCTestSVN*>(vc.get())->GetNewRevision();
|
||||
}
|
||||
|
||||
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
||||
|
|
|
@ -102,3 +102,15 @@ void cmCTestVC::CleanupImpl()
|
|||
{
|
||||
// We do no cleanup by default.
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCTestVC::NoteOldRevision()
|
||||
{
|
||||
// We do nothing by default.
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmCTestVC::NoteNewRevision()
|
||||
{
|
||||
// We do nothing by default.
|
||||
}
|
||||
|
|
|
@ -45,9 +45,13 @@ public:
|
|||
/** Perform cleanup operations on the work tree. */
|
||||
void Cleanup();
|
||||
|
||||
void MarkOldRevision() { this->NoteOldRevision(); }
|
||||
void MarkNewRevision() { this->NoteNewRevision(); }
|
||||
protected:
|
||||
// Internal API to be implemented by subclasses.
|
||||
virtual void CleanupImpl();
|
||||
virtual void NoteOldRevision();
|
||||
virtual void NoteNewRevision();
|
||||
|
||||
/** Convert a list of arguments to a human-readable command line. */
|
||||
static std::string ComputeCommandLine(char const* const* cmd);
|
||||
|
|
Loading…
Reference in New Issue