cmCTestUpdateHandler.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestUpdateHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmVersion.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmXMLParser.h"
  22. //#include <cmsys/RegularExpression.hxx>
  23. #include <cmsys/Process.h>
  24. // used for sleep
  25. #ifdef _WIN32
  26. #include "windows.h"
  27. #endif
  28. #include <stdlib.h>
  29. #include <math.h>
  30. #include <float.h>
  31. //----------------------------------------------------------------------
  32. //**********************************************************************
  33. class cmCTestUpdateHandlerSVNXMLParser : public cmXMLParser
  34. {
  35. public:
  36. struct t_CommitLog
  37. {
  38. int m_Revision;
  39. std::string m_Author;
  40. std::string m_Date;
  41. std::string m_Message;
  42. };
  43. cmCTestUpdateHandlerSVNXMLParser(cmCTestUpdateHandler* up)
  44. : cmXMLParser(), m_UpdateHandler(up), m_MinRevision(-1), m_MaxRevision(-1), m_Verbose(false)
  45. {
  46. }
  47. int Parse(const char* str)
  48. {
  49. m_MinRevision = -1;
  50. m_MaxRevision = -1;
  51. int res = this->cmXMLParser::Parse(str);
  52. if ( m_MinRevision == -1 || m_MaxRevision == -1 )
  53. {
  54. return 0;
  55. }
  56. return res;
  57. }
  58. typedef std::vector<t_CommitLog> t_VectorOfCommits;
  59. t_VectorOfCommits* GetCommits() { return &m_Commits; }
  60. int GetMinRevision() { return m_MinRevision; }
  61. int GetMaxRevision() { return m_MaxRevision; }
  62. void SetVerbose(bool v) { m_Verbose = v; }
  63. protected:
  64. void StartElement(const char* name, const char** atts)
  65. {
  66. if ( strcmp(name, "logentry") == 0 )
  67. {
  68. m_CommitLog = t_CommitLog();
  69. const char* rev = this->FindAttribute(atts, "revision");
  70. if ( rev)
  71. {
  72. m_CommitLog.m_Revision = atoi(rev);
  73. if ( m_MinRevision < 0 || m_MinRevision > m_CommitLog.m_Revision )
  74. {
  75. m_MinRevision = m_CommitLog.m_Revision;
  76. }
  77. if ( m_MaxRevision < 0 || m_MaxRevision < m_CommitLog.m_Revision )
  78. {
  79. m_MaxRevision = m_CommitLog.m_Revision;
  80. }
  81. }
  82. }
  83. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  84. }
  85. void EndElement(const char* name)
  86. {
  87. if ( strcmp(name, "logentry") == 0 )
  88. {
  89. if ( m_Verbose )
  90. {
  91. std::cout << "\tRevision: " << m_CommitLog.m_Revision<< std::endl;
  92. std::cout << "\tAuthor: " << m_CommitLog.m_Author.c_str() << std::endl;
  93. std::cout << "\tDate: " << m_CommitLog.m_Date.c_str() << std::endl;
  94. std::cout << "\tMessage: " << m_CommitLog.m_Message.c_str() << std::endl;
  95. }
  96. m_Commits.push_back(m_CommitLog);
  97. }
  98. else if ( strcmp(name, "author") == 0 )
  99. {
  100. m_CommitLog.m_Author.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  101. }
  102. else if ( strcmp(name, "date") == 0 )
  103. {
  104. m_CommitLog.m_Date.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  105. }
  106. else if ( strcmp(name, "msg") == 0 )
  107. {
  108. m_CommitLog.m_Message.assign(&(*(m_CharacterData.begin())), m_CharacterData.size());
  109. }
  110. m_CharacterData.erase(m_CharacterData.begin(), m_CharacterData.end());
  111. }
  112. void CharacterDataHandler(const char* data, int length)
  113. {
  114. m_CharacterData.insert(m_CharacterData.end(), data, data+length);
  115. }
  116. const char* FindAttribute( const char** atts, const char* attribute )
  117. {
  118. if ( !atts || !attribute )
  119. {
  120. return 0;
  121. }
  122. const char **atr = atts;
  123. while ( *atr && **atr && **(atr+1) )
  124. {
  125. if ( strcmp(*atr, attribute) == 0 )
  126. {
  127. return *(atr+1);
  128. }
  129. atr+=2;
  130. }
  131. return 0;
  132. }
  133. private:
  134. std::vector<char> m_CharacterData;
  135. cmCTestUpdateHandler* m_UpdateHandler;
  136. t_CommitLog m_CommitLog;
  137. t_VectorOfCommits m_Commits;
  138. int m_MinRevision;
  139. int m_MaxRevision;
  140. bool m_Verbose;
  141. };
  142. //**********************************************************************
  143. //----------------------------------------------------------------------
  144. //----------------------------------------------------------------------
  145. cmCTestUpdateHandler::cmCTestUpdateHandler()
  146. {
  147. m_Verbose = false;
  148. m_CTest = 0;
  149. }
  150. //----------------------------------------------------------------------
  151. int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
  152. {
  153. if ( type && *type )
  154. {
  155. std::string stype = cmSystemTools::LowerCase(type);
  156. if ( stype.find("cvs") != std::string::npos )
  157. {
  158. return cmCTestUpdateHandler::e_CVS;
  159. }
  160. if ( stype.find("svn") != std::string::npos )
  161. {
  162. return cmCTestUpdateHandler::e_SVN;
  163. }
  164. }
  165. else
  166. {
  167. std::string stype = cmSystemTools::LowerCase(cmd);
  168. if ( stype.find("cvs") != std::string::npos )
  169. {
  170. return cmCTestUpdateHandler::e_CVS;
  171. }
  172. if ( stype.find("svn") != std::string::npos )
  173. {
  174. return cmCTestUpdateHandler::e_SVN;
  175. }
  176. }
  177. return cmCTestUpdateHandler::e_CVS;
  178. }
  179. //----------------------------------------------------------------------
  180. //clearly it would be nice if this were broken up into a few smaller
  181. //functions and commented...
  182. int cmCTestUpdateHandler::ProcessHandler()
  183. {
  184. int count = 0;
  185. int updateType = e_CVS;
  186. std::string::size_type cc, kk;
  187. bool updateProducedError = false;
  188. // Get source dir
  189. const char* sourceDirectory = this->GetOption("SourceDirectory");
  190. if ( !sourceDirectory )
  191. {
  192. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  193. return -1;
  194. }
  195. std::cout << "Updating the repository: " << sourceDirectory << std::endl;
  196. // Get update command
  197. std::string updateCommand = m_CTest->GetCTestConfiguration("UpdateCommand");
  198. if ( updateCommand.empty() )
  199. {
  200. updateCommand = m_CTest->GetCTestConfiguration("CVSCommand");
  201. if ( updateCommand.empty() )
  202. {
  203. updateCommand = m_CTest->GetCTestConfiguration("SVNCommand");
  204. if ( updateCommand.empty() )
  205. {
  206. std::cerr << "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl;
  207. return -1;
  208. }
  209. else
  210. {
  211. updateType = e_SVN;
  212. }
  213. }
  214. else
  215. {
  216. updateType = e_CVS;
  217. }
  218. }
  219. else
  220. {
  221. updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetCTestConfiguration("UpdateType").c_str());
  222. }
  223. // And update options
  224. std::string updateOptions = m_CTest->GetCTestConfiguration("UpdateOptions");
  225. if ( updateOptions.empty() )
  226. {
  227. switch (updateType)
  228. {
  229. case cmCTestUpdateHandler::e_CVS:
  230. updateOptions = m_CTest->GetCTestConfiguration("CVSUpdateOptions");
  231. break;
  232. case cmCTestUpdateHandler::e_SVN:
  233. updateOptions = m_CTest->GetCTestConfiguration("SVNUpdateOptions");
  234. break;
  235. }
  236. }
  237. // Get update time
  238. std::string extra_update_opts;
  239. if ( m_CTest->GetTestModel() == cmCTest::NIGHTLY )
  240. {
  241. struct tm* t = cmCTest::GetNightlyTime(m_CTest->GetCTestConfiguration("NightlyStartTime"),
  242. m_Verbose, m_CTest->GetTomorrowTag());
  243. char current_time[1024];
  244. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  245. t->tm_year + 1900,
  246. t->tm_mon + 1,
  247. t->tm_mday,
  248. t->tm_hour,
  249. t->tm_min,
  250. t->tm_sec);
  251. std::string today_update_date = current_time;
  252. // TODO: SVN
  253. switch ( updateType )
  254. {
  255. case cmCTestUpdateHandler::e_CVS:
  256. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  257. break;
  258. case cmCTestUpdateHandler::e_SVN:
  259. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  260. break;
  261. }
  262. }
  263. updateCommand = "\"" + updateCommand + "\"";
  264. // First, check what the current state of repository is
  265. std::string command = "";
  266. switch( updateType )
  267. {
  268. case cmCTestUpdateHandler::e_CVS:
  269. // TODO: CVS - for now just leave empty
  270. break;
  271. case cmCTestUpdateHandler::e_SVN:
  272. command = updateCommand + " info";
  273. break;
  274. }
  275. cmGeneratedFileStream ofs;
  276. if ( !m_CTest->GetShowOnly() )
  277. {
  278. m_CTest->OpenOutputFile("Temporary", "LastUpdate.log", ofs);
  279. }
  280. // CVS variables
  281. // SVN variables
  282. int svn_current_revision = 0;
  283. int svn_latest_revision = 0;
  284. int svn_use_status = 0;
  285. std::string goutput;
  286. int retVal = 0;
  287. bool res = true;
  288. //
  289. // Get initial repository information if that is possible. With subversion, this will check the current revision.
  290. //
  291. if ( !command.empty() )
  292. {
  293. if ( m_Verbose )
  294. {
  295. std::cout << "* Get repository information: " << command.c_str() << std::endl;
  296. }
  297. if ( !m_CTest->GetShowOnly() )
  298. {
  299. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  300. &retVal, sourceDirectory,
  301. m_Verbose, 0 /*m_TimeOut*/);
  302. if ( ofs )
  303. {
  304. ofs << "--- Update information ---" << std::endl;
  305. ofs << goutput << std::endl;
  306. }
  307. switch ( updateType )
  308. {
  309. case cmCTestUpdateHandler::e_CVS:
  310. // TODO: CVS - for now just leave empty
  311. break;
  312. case cmCTestUpdateHandler::e_SVN:
  313. {
  314. cmsys::RegularExpression current_revision_regex("Revision: ([0-9]+)");
  315. if ( current_revision_regex.find(goutput.c_str()) )
  316. {
  317. std::string currentRevisionString = current_revision_regex.match(1);
  318. svn_current_revision = atoi(currentRevisionString.c_str());
  319. std::cout << " Old revision of repository is: " << svn_current_revision << std::endl;
  320. }
  321. }
  322. break;
  323. }
  324. }
  325. else
  326. {
  327. std::cout << "Update with command: " << command << std::endl;
  328. }
  329. }
  330. //
  331. // Now update repository and remember what files were updated
  332. //
  333. cmGeneratedFileStream os;
  334. if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Update.xml", os, true) )
  335. {
  336. std::cerr << "Cannot open log file" << std::endl;
  337. }
  338. std::string start_time = m_CTest->CurrentTime();
  339. double elapsed_time_start = cmSystemTools::GetTime();
  340. if ( m_Verbose )
  341. {
  342. std::cout << "* Update repository: " << command.c_str() << std::endl;
  343. }
  344. if ( !m_CTest->GetShowOnly() )
  345. {
  346. command = "";
  347. switch( updateType )
  348. {
  349. case cmCTestUpdateHandler::e_CVS:
  350. command = updateCommand + " -z3 update " + updateOptions +
  351. " " + extra_update_opts;
  352. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  353. &retVal, sourceDirectory,
  354. m_Verbose, 0 /*m_TimeOut*/);
  355. break;
  356. case cmCTestUpdateHandler::e_SVN:
  357. {
  358. std::string partialOutput;
  359. command = updateCommand + " update " + updateOptions +
  360. " " + extra_update_opts;
  361. bool res1 = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput,
  362. &retVal, sourceDirectory,
  363. m_Verbose, 0 /*m_TimeOut*/);
  364. command = updateCommand + " status";
  365. res = cmSystemTools::RunSingleCommand(command.c_str(), &partialOutput,
  366. &retVal, sourceDirectory,
  367. m_Verbose, 0 /*m_TimeOut*/);
  368. goutput += partialOutput;
  369. res = res && res1;
  370. }
  371. }
  372. if ( ofs )
  373. {
  374. ofs << "--- Update repository ---" << std::endl;
  375. ofs << goutput << std::endl;;
  376. }
  377. }
  378. if ( !res || retVal )
  379. {
  380. updateProducedError = true;
  381. }
  382. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  383. << "<Update mode=\"Client\" Generator=\"ctest-"
  384. << cmVersion::GetCMakeVersion() << "\">\n"
  385. << "\t<Site>" << m_CTest->GetCTestConfiguration("Site") << "</Site>\n"
  386. << "\t<BuildName>" << m_CTest->GetCTestConfiguration("BuildName")
  387. << "</BuildName>\n"
  388. << "\t<BuildStamp>" << m_CTest->GetCurrentTag() << "-"
  389. << m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  390. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  391. << "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command)
  392. << "</UpdateCommand>\n";
  393. // Even though it failed, we may have some useful information. Try to continue...
  394. std::vector<cmStdString> lines;
  395. cmSystemTools::Split(goutput.c_str(), lines);
  396. // CVS style regular expressions
  397. cmsys::RegularExpression cvs_date_author_regex("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  398. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  399. cmsys::RegularExpression cvs_end_of_file_regex("^=============================================================================$");
  400. cmsys::RegularExpression cvs_end_of_comment_regex("^----------------------------$");
  401. // Subversion style regular expressions
  402. cmsys::RegularExpression svn_status_line_regex("^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  403. cmsys::RegularExpression svn_latest_revision_regex("(Updated to|At) revision ([0-9]+)\\.");
  404. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  405. std::string current_path = "<no-path>";
  406. bool first_file = true;
  407. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  408. int num_updated = 0;
  409. int num_modified = 0;
  410. int num_conflicting = 0;
  411. // In subversion, get the latest revision
  412. if ( updateType == cmCTestUpdateHandler::e_SVN )
  413. {
  414. for ( cc= 0 ; cc < lines.size(); cc ++ )
  415. {
  416. const char* line = lines[cc].c_str();
  417. if ( svn_latest_revision_regex.find(line) )
  418. {
  419. svn_latest_revision = atoi(svn_latest_revision_regex.match(2).c_str());
  420. }
  421. }
  422. }
  423. if ( updateType == cmCTestUpdateHandler::e_SVN )
  424. {
  425. std::cout << " Current revision of repository is: " << svn_latest_revision << std::endl;
  426. }
  427. std::cout << " Gathering version information (each . represents one updated file):" << std::endl;
  428. int file_count = 0;
  429. for ( cc= 0 ; cc < lines.size(); cc ++ )
  430. {
  431. const char* line = lines[cc].c_str();
  432. if ( file_update_line.find(line) )
  433. {
  434. if ( !m_Verbose )
  435. {
  436. if ( file_count == 0 )
  437. {
  438. std::cout << " ";
  439. std::cout.flush();
  440. }
  441. std::cout << ".";
  442. }
  443. std::cout.flush();
  444. std::string upChar = file_update_line.match(1);
  445. std::string upFile = file_update_line.match(2);
  446. char mod = upChar[0];
  447. bool modifiedOrConflict = false;
  448. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  449. {
  450. count ++;
  451. modifiedOrConflict = true;
  452. }
  453. const char* file = upFile.c_str();
  454. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  455. std::string output;
  456. if ( modifiedOrConflict )
  457. {
  458. std::string logcommand;
  459. switch ( updateType )
  460. {
  461. case cmCTestUpdateHandler::e_CVS:
  462. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  463. break;
  464. case cmCTestUpdateHandler::e_SVN:
  465. if ( svn_latest_revision > 0 && svn_latest_revision > svn_current_revision )
  466. {
  467. cmOStringStream logCommandStream;
  468. logCommandStream << updateCommand << " log -r " << svn_current_revision << ":" << svn_latest_revision
  469. << " --xml \"" << file << "\"";
  470. logcommand = logCommandStream.str();
  471. }
  472. else
  473. {
  474. logcommand = updateCommand + " status --verbose \"" + file + "\"";
  475. svn_use_status = 1;
  476. }
  477. break;
  478. }
  479. //std::cout << "Do log: " << logcommand << std::endl;
  480. if ( m_Verbose )
  481. {
  482. std::cout << "* Get file update information: " << logcommand.c_str() << std::endl;
  483. }
  484. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  485. &retVal, sourceDirectory,
  486. m_Verbose, 0 /*m_TimeOut*/);
  487. if ( ofs )
  488. {
  489. ofs << output << std::endl;
  490. }
  491. }
  492. if ( res && retVal == 0)
  493. {
  494. //std::cout << output << std::endl;
  495. std::string::size_type sline = 0;
  496. std::string srevision1 = "Unknown";
  497. std::string sdate1 = "Unknown";
  498. std::string sauthor1 = "Unknown";
  499. std::string semail1 = "Unknown";
  500. std::string comment1 = "";
  501. std::string srevision2 = "Unknown";
  502. std::string sdate2 = "Unknown";
  503. std::string sauthor2 = "Unknown";
  504. std::string comment2 = "";
  505. std::string semail2 = "Unknown";
  506. if ( updateType == cmCTestUpdateHandler::e_CVS )
  507. {
  508. bool have_first = false;
  509. bool have_second = false;
  510. std::vector<cmStdString> ulines;
  511. cmSystemTools::Split(output.c_str(), ulines);
  512. for ( kk = 0; kk < ulines.size(); kk ++ )
  513. {
  514. const char* clp = ulines[kk].c_str();
  515. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  516. {
  517. if ( !have_first )
  518. {
  519. srevision1 = cvs_revision_regex.match(1);
  520. }
  521. else
  522. {
  523. srevision2 = cvs_revision_regex.match(1);
  524. }
  525. }
  526. else if ( !have_second && !sline && cvs_date_author_regex.find(clp) )
  527. {
  528. sline = kk + 1;
  529. if ( !have_first )
  530. {
  531. sdate1 = cvs_date_author_regex.match(1);
  532. sauthor1 = cvs_date_author_regex.match(2);
  533. }
  534. else
  535. {
  536. sdate2 = cvs_date_author_regex.match(1);
  537. sauthor2 = cvs_date_author_regex.match(2);
  538. }
  539. }
  540. else if ( sline && cvs_end_of_comment_regex.find(clp) || cvs_end_of_file_regex.find(clp))
  541. {
  542. if ( !have_first )
  543. {
  544. have_first = true;
  545. }
  546. else if ( !have_second )
  547. {
  548. have_second = true;
  549. }
  550. sline = 0;
  551. }
  552. else if ( sline )
  553. {
  554. if ( !have_first )
  555. {
  556. comment1 += clp;
  557. comment1 += "\n";
  558. }
  559. else
  560. {
  561. comment2 += clp;
  562. comment2 += "\n";
  563. }
  564. }
  565. }
  566. }
  567. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  568. {
  569. if ( svn_use_status )
  570. {
  571. cmOStringStream str;
  572. str << svn_current_revision;
  573. srevision1 = str.str();
  574. if (!svn_status_line_regex.find(output))
  575. {
  576. std::cerr << "Bad output from SVN status command: " << output << std::endl;
  577. }
  578. else if ( svn_status_line_regex.match(4) != file )
  579. {
  580. std::cerr << "Bad output from SVN status command. The file name returned: \"" << svn_status_line_regex.match(4) << "\" was different than the file specified: \"" << file << "\"" << std::endl;
  581. }
  582. else
  583. {
  584. srevision1 = svn_status_line_regex.match(2);
  585. int latest_revision = atoi(svn_status_line_regex.match(2).c_str());
  586. if ( svn_current_revision < latest_revision )
  587. {
  588. srevision2 = str.str();
  589. }
  590. sauthor1 = svn_status_line_regex.match(3);
  591. }
  592. }
  593. else
  594. {
  595. cmCTestUpdateHandlerSVNXMLParser parser(this);
  596. parser.SetVerbose(m_Verbose);
  597. if ( parser.Parse(output.c_str()) )
  598. {
  599. int minrev = parser.GetMinRevision();
  600. int maxrev = parser.GetMaxRevision();
  601. cmCTestUpdateHandlerSVNXMLParser::t_VectorOfCommits::iterator it;
  602. for ( it = parser.GetCommits()->begin();
  603. it != parser.GetCommits()->end();
  604. ++ it )
  605. {
  606. if ( it->m_Revision == maxrev )
  607. {
  608. cmOStringStream mRevStream;
  609. mRevStream << maxrev;
  610. srevision1 = mRevStream.str();
  611. sauthor1 = it->m_Author;
  612. comment1 = it->m_Message;
  613. sdate1 = it->m_Date;
  614. }
  615. else if ( it->m_Revision == minrev )
  616. {
  617. cmOStringStream mRevStream;
  618. mRevStream << minrev;
  619. srevision2 = mRevStream.str();
  620. sauthor2 = it->m_Author;
  621. comment2 = it->m_Message;
  622. sdate2 = it->m_Date;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. if ( mod == 'M' )
  629. {
  630. comment1 = "Locally modified file\n";
  631. sauthor1 = "Local User";
  632. }
  633. if ( mod == 'C' )
  634. {
  635. comment1 = "Conflict while updating\n";
  636. sauthor1 = "Local User";
  637. }
  638. std::string path = cmSystemTools::GetFilenamePath(file);
  639. std::string fname = cmSystemTools::GetFilenameName(file);
  640. if ( path != current_path )
  641. {
  642. if ( !first_file )
  643. {
  644. os << "\t</Directory>" << std::endl;
  645. }
  646. else
  647. {
  648. first_file = false;
  649. }
  650. os << "\t<Directory>\n"
  651. << "\t\t<Name>" << path << "</Name>" << std::endl;
  652. }
  653. if ( mod == 'C' )
  654. {
  655. num_conflicting ++;
  656. os << "\t<Conflicting>" << std::endl;
  657. }
  658. else if ( mod == 'G' )
  659. {
  660. num_conflicting ++;
  661. os << "\t<Conflicting>" << std::endl;
  662. }
  663. else if ( mod == 'M' )
  664. {
  665. num_modified ++;
  666. os << "\t<Modified>" << std::endl;
  667. }
  668. else
  669. {
  670. num_updated ++;
  671. os << "\t<Updated>" << std::endl;
  672. }
  673. if ( srevision2 == "Unknown" )
  674. {
  675. srevision2 = srevision1;
  676. }
  677. if ( m_Verbose )
  678. {
  679. std::cout << "File: " << path.c_str() << " / " << fname.c_str() << " was updated by "
  680. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  681. << " from revision: " << srevision2.c_str() << std::endl;
  682. }
  683. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">" << cmCTest::MakeXMLSafe(fname)
  684. << "</File>\n"
  685. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path) << "</Directory>\n"
  686. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  687. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1) << "</CheckinDate>\n"
  688. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  689. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  690. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  691. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  692. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  693. << std::endl;
  694. if ( srevision2 != srevision1 )
  695. {
  696. os
  697. << "\t\t<Revisions>\n"
  698. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  699. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  700. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  701. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1) << "</Date>\n"
  702. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1) << "</Comment>\n"
  703. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  704. << "\t\t</Revisions>\n"
  705. << "\t\t<Revisions>\n"
  706. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  707. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  708. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2) << "</Author>\n"
  709. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2) << "</Date>\n"
  710. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2) << "</Comment>\n"
  711. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2) << "</Email>\n"
  712. << "\t\t</Revisions>" << std::endl;
  713. }
  714. if ( mod == 'C' )
  715. {
  716. os << "\t</Conflicting>" << std::endl;
  717. }
  718. else if ( mod == 'G' )
  719. {
  720. os << "\t</Conflicting>" << std::endl;
  721. }
  722. else if ( mod == 'M' )
  723. {
  724. os << "\t</Modified>" << std::endl;
  725. }
  726. else
  727. {
  728. os << "\t</Updated>" << std::endl;
  729. }
  730. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  731. cmCTestUpdateHandler::StringPair p;
  732. p.first = path;
  733. p.second = fname;
  734. u->push_back(p);
  735. current_path = path;
  736. }
  737. file_count ++;
  738. }
  739. }
  740. if ( file_count )
  741. {
  742. std::cout << std::endl;
  743. }
  744. if ( num_updated )
  745. {
  746. std::cout << " Found " << num_updated << " updated files" << std::endl;
  747. }
  748. if ( num_modified )
  749. {
  750. std::cout << " Found " << num_modified << " locally modified files"
  751. << std::endl;
  752. }
  753. if ( num_conflicting )
  754. {
  755. std::cout << " Found " << num_conflicting << " conflicting files"
  756. << std::endl;
  757. }
  758. if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 )
  759. {
  760. std::cout << " Project is up-to-date" << std::endl;
  761. }
  762. if ( !first_file )
  763. {
  764. os << "\t</Directory>" << std::endl;
  765. }
  766. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  767. for ( it = authors_files_map.begin();
  768. it != authors_files_map.end();
  769. it ++ )
  770. {
  771. os << "\t<Author>\n"
  772. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  773. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  774. for ( cc = 0; cc < u->size(); cc ++ )
  775. {
  776. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  777. << (*u)[cc].second << "</File>" << std::endl;
  778. }
  779. os << "\t</Author>" << std::endl;
  780. }
  781. //std::cout << "End" << std::endl;
  782. std::string end_time = m_CTest->CurrentTime();
  783. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  784. << "<ElapsedMinutes>" <<
  785. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  786. << "</ElapsedMinutes>\n"
  787. << "\t<UpdateReturnStatus>";
  788. if ( num_modified > 0 || num_conflicting > 0 )
  789. {
  790. os << "Update error: There are modified or conflicting files in the repository";
  791. std::cerr << " There are modified or conflicting files in the repository" << std::endl;
  792. }
  793. if ( updateProducedError )
  794. {
  795. os << "Update error: ";
  796. os << m_CTest->MakeXMLSafe(goutput);
  797. std::cerr << " Update with command: " << command << " failed" << std::endl;
  798. }
  799. os << "</UpdateReturnStatus>" << std::endl;
  800. os << "</Update>" << std::endl;
  801. if ( ofs )
  802. {
  803. ofs.close();
  804. }
  805. if (! res || retVal )
  806. {
  807. std::cerr << "Error(s) when updating the project" << std::endl;
  808. std::cerr << "Output: " << goutput << std::endl;
  809. return -1;
  810. }
  811. return count;
  812. }