cmCTestUpdateHandler.cxx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. // Get source dir
  188. const char* sourceDirectory = this->GetOption("SourceDirectory");
  189. if ( !sourceDirectory )
  190. {
  191. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  192. return -1;
  193. }
  194. std::cout << "Updating the repository: " << sourceDirectory << std::endl;
  195. // Get update command
  196. std::string updateCommand = m_CTest->GetDartConfiguration("UpdateCommand");
  197. if ( updateCommand.empty() )
  198. {
  199. updateCommand = m_CTest->GetDartConfiguration("CVSCommand");
  200. if ( updateCommand.empty() )
  201. {
  202. updateCommand = m_CTest->GetDartConfiguration("SVNCommand");
  203. if ( updateCommand.empty() )
  204. {
  205. std::cerr << "Cannot find CVSCommand, SVNCommand, or UpdateCommand key in the DartConfiguration.tcl" << std::endl;
  206. return -1;
  207. }
  208. else
  209. {
  210. updateType = e_SVN;
  211. }
  212. }
  213. else
  214. {
  215. updateType = e_CVS;
  216. }
  217. }
  218. else
  219. {
  220. updateType = this->DetermineType(updateCommand.c_str(), m_CTest->GetDartConfiguration("UpdateType").c_str());
  221. }
  222. // And update options
  223. std::string updateOptions = m_CTest->GetDartConfiguration("UpdateOptions");
  224. if ( updateOptions.empty() )
  225. {
  226. switch (updateType)
  227. {
  228. case cmCTestUpdateHandler::e_CVS:
  229. updateOptions = m_CTest->GetDartConfiguration("CVSUpdateOptions");
  230. break;
  231. case cmCTestUpdateHandler::e_SVN:
  232. updateOptions = m_CTest->GetDartConfiguration("SVNUpdateOptions");
  233. break;
  234. }
  235. }
  236. // Get update time
  237. std::string extra_update_opts;
  238. if ( m_CTest->GetTestModel() == cmCTest::NIGHTLY )
  239. {
  240. struct tm* t = cmCTest::GetNightlyTime(m_CTest->GetDartConfiguration("NightlyStartTime"),
  241. m_Verbose, m_CTest->GetTomorrowTag());
  242. char current_time[1024];
  243. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d",
  244. t->tm_year + 1900,
  245. t->tm_mon + 1,
  246. t->tm_mday,
  247. t->tm_hour,
  248. t->tm_min,
  249. t->tm_sec);
  250. std::string today_update_date = current_time;
  251. // TODO: SVN
  252. switch ( updateType )
  253. {
  254. case cmCTestUpdateHandler::e_CVS:
  255. extra_update_opts += "-D \"" + today_update_date +" UTC\"";
  256. break;
  257. case cmCTestUpdateHandler::e_SVN:
  258. extra_update_opts += "-r \"{" + today_update_date +" +0000}\"";
  259. break;
  260. }
  261. }
  262. // First, check what the current state of repository is
  263. std::string command = "";
  264. switch( updateType )
  265. {
  266. case cmCTestUpdateHandler::e_CVS:
  267. // TODO: CVS - for now just leave empty
  268. break;
  269. case cmCTestUpdateHandler::e_SVN:
  270. command = updateCommand + " info";
  271. break;
  272. }
  273. cmGeneratedFileStream ofs;
  274. if ( !m_CTest->GetShowOnly() )
  275. {
  276. m_CTest->OpenOutputFile("Temporary", "LastUpdate.log", ofs);
  277. }
  278. // CVS variables
  279. // SVN variables
  280. int svn_current_revision = 0;
  281. int svn_latest_revision = 0;
  282. int svn_use_status = 0;
  283. std::string goutput;
  284. int retVal = 0;
  285. bool res = true;
  286. if ( !command.empty() )
  287. {
  288. if ( m_Verbose )
  289. {
  290. std::cout << "* Get repository information: " << command.c_str() << std::endl;
  291. }
  292. if ( !m_CTest->GetShowOnly() )
  293. {
  294. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  295. &retVal, sourceDirectory,
  296. m_Verbose, 0 /*m_TimeOut*/);
  297. if ( ofs )
  298. {
  299. ofs << "--- Update information ---" << std::endl;
  300. ofs << goutput << std::endl;
  301. }
  302. switch ( updateType )
  303. {
  304. case cmCTestUpdateHandler::e_CVS:
  305. // TODO: CVS - for now just leave empty
  306. break;
  307. case cmCTestUpdateHandler::e_SVN:
  308. {
  309. cmsys::RegularExpression current_revision_regex("Revision: ([0-9]+)");
  310. if ( current_revision_regex.find(goutput.c_str()) )
  311. {
  312. std::string currentRevisionString = current_revision_regex.match(1);
  313. svn_current_revision = atoi(currentRevisionString.c_str());
  314. std::cout << " Old revision of repository is: " << svn_current_revision << std::endl;
  315. }
  316. }
  317. break;
  318. }
  319. }
  320. else
  321. {
  322. std::cout << "Update with command: " << command << std::endl;
  323. }
  324. }
  325. command = "";
  326. switch( updateType )
  327. {
  328. case cmCTestUpdateHandler::e_CVS:
  329. command = updateCommand + " -z3 update " + updateOptions +
  330. " " + extra_update_opts;
  331. break;
  332. case cmCTestUpdateHandler::e_SVN:
  333. command = updateCommand + " update " + updateOptions +
  334. " " + extra_update_opts;
  335. }
  336. cmGeneratedFileStream os;
  337. if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Update.xml", os, true) )
  338. {
  339. std::cerr << "Cannot open log file" << std::endl;
  340. }
  341. std::string start_time = m_CTest->CurrentTime();
  342. double elapsed_time_start = cmSystemTools::GetTime();
  343. if ( m_Verbose )
  344. {
  345. std::cout << "* Update repository: " << command.c_str() << std::endl;
  346. }
  347. if ( !m_CTest->GetShowOnly() )
  348. {
  349. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  350. &retVal, sourceDirectory,
  351. m_Verbose, 0 /*m_TimeOut*/);
  352. if ( ofs )
  353. {
  354. ofs << "--- Update repository ---" << std::endl;
  355. ofs << goutput << std::endl;;
  356. }
  357. }
  358. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  359. << "<Update mode=\"Client\" Generator=\"ctest-"
  360. << cmVersion::GetCMakeVersion() << "\">\n"
  361. << "\t<Site>" << m_CTest->GetDartConfiguration("Site") << "</Site>\n"
  362. << "\t<BuildName>" << m_CTest->GetDartConfiguration("BuildName")
  363. << "</BuildName>\n"
  364. << "\t<BuildStamp>" << m_CTest->GetCurrentTag() << "-"
  365. << m_CTest->GetTestModelString() << "</BuildStamp>" << std::endl;
  366. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  367. << "\t<UpdateCommand>" << m_CTest->MakeXMLSafe(command)
  368. << "</UpdateCommand>\n"
  369. << "\t<UpdateReturnStatus>";
  370. if ( !res || retVal )
  371. {
  372. os << "Update error: ";
  373. os << m_CTest->MakeXMLSafe(goutput);
  374. std::cerr << "Update with command: " << command << " failed" << std::endl;
  375. }
  376. os << "</UpdateReturnStatus>" << std::endl;
  377. // Even though it failed, we may have some useful information. Try to continue...
  378. std::vector<cmStdString> lines;
  379. cmSystemTools::Split(goutput.c_str(), lines);
  380. // CVS style regular expressions
  381. cmsys::RegularExpression cvs_date_author_regex("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  382. cmsys::RegularExpression cvs_revision_regex("^revision +([^ ]*) *$");
  383. cmsys::RegularExpression cvs_end_of_file_regex("^=============================================================================$");
  384. cmsys::RegularExpression cvs_end_of_comment_regex("^----------------------------$");
  385. // Subversion style regular expressions
  386. cmsys::RegularExpression svn_status_line_regex("^ *([0-9]+) *([0-9]+) *([^ ]+) *([^ ][^\t\r\n]*)[ \t\r\n]*$");
  387. cmsys::RegularExpression svn_latest_revision_regex("(Updated to|At) revision ([0-9]+)\\.");
  388. cmsys::RegularExpression file_update_line("([A-Z]) *(.*)");
  389. std::string current_path = "<no-path>";
  390. bool first_file = true;
  391. cmCTestUpdateHandler::AuthorsToUpdatesMap authors_files_map;
  392. int num_updated = 0;
  393. int num_modified = 0;
  394. int num_conflicting = 0;
  395. // In subversion, get the latest revision
  396. if ( updateType == cmCTestUpdateHandler::e_SVN )
  397. {
  398. for ( cc= 0 ; cc < lines.size(); cc ++ )
  399. {
  400. const char* line = lines[cc].c_str();
  401. if ( svn_latest_revision_regex.find(line) )
  402. {
  403. svn_latest_revision = atoi(svn_latest_revision_regex.match(2).c_str());
  404. }
  405. }
  406. }
  407. if ( updateType == cmCTestUpdateHandler::e_SVN )
  408. {
  409. std::cout << " Current revision of repository is: " << svn_latest_revision << std::endl;
  410. }
  411. std::cout << " Gathering version information (each . represents one updated file):" << std::endl;
  412. int file_count = 0;
  413. for ( cc= 0 ; cc < lines.size(); cc ++ )
  414. {
  415. const char* line = lines[cc].c_str();
  416. if ( file_update_line.find(line) )
  417. {
  418. if ( !m_Verbose )
  419. {
  420. if ( file_count == 0 )
  421. {
  422. std::cout << " ";
  423. std::cout.flush();
  424. }
  425. std::cout << ".";
  426. }
  427. std::cout.flush();
  428. std::string upChar = file_update_line.match(1);
  429. std::string upFile = file_update_line.match(2);
  430. char mod = upChar[0];
  431. if ( mod != 'M' && mod != 'C' && mod != 'G' )
  432. {
  433. count ++;
  434. }
  435. const char* file = upFile.c_str();
  436. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  437. std::string logcommand;
  438. switch ( updateType )
  439. {
  440. case cmCTestUpdateHandler::e_CVS:
  441. logcommand = updateCommand + " -z3 log -N \"" + file + "\"";
  442. break;
  443. case cmCTestUpdateHandler::e_SVN:
  444. if ( svn_latest_revision > 0 && svn_latest_revision > svn_current_revision )
  445. {
  446. cmOStringStream logCommandStream;
  447. logCommandStream << updateCommand << " log -r " << svn_current_revision << ":" << svn_latest_revision
  448. << " --xml \"" << file << "\"";
  449. logcommand = logCommandStream.str();
  450. }
  451. else
  452. {
  453. logcommand = updateCommand + " status --verbose \"" + file + "\"";
  454. svn_use_status = 1;
  455. }
  456. break;
  457. }
  458. //std::cout << "Do log: " << logcommand << std::endl;
  459. std::string output;
  460. if ( m_Verbose )
  461. {
  462. std::cout << "* Get file update information: " << logcommand.c_str() << std::endl;
  463. }
  464. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  465. &retVal, sourceDirectory,
  466. m_Verbose, 0 /*m_TimeOut*/);
  467. if ( ofs )
  468. {
  469. ofs << output << std::endl;
  470. }
  471. if ( res && retVal == 0)
  472. {
  473. //std::cout << output << std::endl;
  474. std::string::size_type sline = 0;
  475. std::string srevision1 = "Unknown";
  476. std::string sdate1 = "Unknown";
  477. std::string sauthor1 = "Unknown";
  478. std::string semail1 = "Unknown";
  479. std::string comment1 = "";
  480. std::string srevision2 = "Unknown";
  481. std::string sdate2 = "Unknown";
  482. std::string sauthor2 = "Unknown";
  483. std::string comment2 = "";
  484. std::string semail2 = "Unknown";
  485. if ( updateType == cmCTestUpdateHandler::e_CVS )
  486. {
  487. bool have_first = false;
  488. bool have_second = false;
  489. std::vector<cmStdString> ulines;
  490. cmSystemTools::Split(output.c_str(), ulines);
  491. for ( kk = 0; kk < ulines.size(); kk ++ )
  492. {
  493. const char* clp = ulines[kk].c_str();
  494. if ( !have_second && !sline && cvs_revision_regex.find(clp) )
  495. {
  496. if ( !have_first )
  497. {
  498. srevision1 = cvs_revision_regex.match(1);
  499. }
  500. else
  501. {
  502. srevision2 = cvs_revision_regex.match(1);
  503. }
  504. }
  505. else if ( !have_second && !sline && cvs_date_author_regex.find(clp) )
  506. {
  507. sline = kk + 1;
  508. if ( !have_first )
  509. {
  510. sdate1 = cvs_date_author_regex.match(1);
  511. sauthor1 = cvs_date_author_regex.match(2);
  512. }
  513. else
  514. {
  515. sdate2 = cvs_date_author_regex.match(1);
  516. sauthor2 = cvs_date_author_regex.match(2);
  517. }
  518. }
  519. else if ( sline && cvs_end_of_comment_regex.find(clp) || cvs_end_of_file_regex.find(clp))
  520. {
  521. if ( !have_first )
  522. {
  523. have_first = true;
  524. }
  525. else if ( !have_second )
  526. {
  527. have_second = true;
  528. }
  529. sline = 0;
  530. }
  531. else if ( sline )
  532. {
  533. if ( !have_first )
  534. {
  535. comment1 += clp;
  536. comment1 += "\n";
  537. }
  538. else
  539. {
  540. comment2 += clp;
  541. comment2 += "\n";
  542. }
  543. }
  544. }
  545. }
  546. else if ( updateType == cmCTestUpdateHandler::e_SVN )
  547. {
  548. if ( svn_use_status )
  549. {
  550. cmOStringStream str;
  551. str << svn_current_revision;
  552. srevision1 = str.str();
  553. if (!svn_status_line_regex.find(output))
  554. {
  555. std::cerr << "Bad output from SVN status command: " << output << std::endl;
  556. }
  557. else if ( svn_status_line_regex.match(4) != file )
  558. {
  559. 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;
  560. }
  561. else
  562. {
  563. srevision1 = svn_status_line_regex.match(2);
  564. int latest_revision = atoi(svn_status_line_regex.match(2).c_str());
  565. if ( svn_current_revision < latest_revision )
  566. {
  567. srevision2 = str.str();
  568. }
  569. sauthor1 = svn_status_line_regex.match(3);
  570. }
  571. }
  572. else
  573. {
  574. cmCTestUpdateHandlerSVNXMLParser parser(this);
  575. parser.SetVerbose(m_Verbose);
  576. if ( parser.Parse(output.c_str()) )
  577. {
  578. int minrev = parser.GetMinRevision();
  579. int maxrev = parser.GetMaxRevision();
  580. cmCTestUpdateHandlerSVNXMLParser::t_VectorOfCommits::iterator it;
  581. for ( it = parser.GetCommits()->begin();
  582. it != parser.GetCommits()->end();
  583. ++ it )
  584. {
  585. if ( it->m_Revision == maxrev )
  586. {
  587. cmOStringStream mRevStream;
  588. mRevStream << maxrev;
  589. srevision1 = mRevStream.str();
  590. sauthor1 = it->m_Author;
  591. comment1 = it->m_Message;
  592. sdate1 = it->m_Date;
  593. }
  594. else if ( it->m_Revision == minrev )
  595. {
  596. cmOStringStream mRevStream;
  597. mRevStream << minrev;
  598. srevision2 = mRevStream.str();
  599. sauthor2 = it->m_Author;
  600. comment2 = it->m_Message;
  601. sdate2 = it->m_Date;
  602. }
  603. }
  604. }
  605. }
  606. }
  607. if ( mod == 'M' )
  608. {
  609. comment1 = "Locally modified file\n";
  610. }
  611. if ( mod == 'C' )
  612. {
  613. comment1 = "Conflict while updating\n";
  614. }
  615. std::string path = cmSystemTools::GetFilenamePath(file);
  616. std::string fname = cmSystemTools::GetFilenameName(file);
  617. if ( path != current_path )
  618. {
  619. if ( !first_file )
  620. {
  621. os << "\t</Directory>" << std::endl;
  622. }
  623. else
  624. {
  625. first_file = false;
  626. }
  627. os << "\t<Directory>\n"
  628. << "\t\t<Name>" << path << "</Name>" << std::endl;
  629. }
  630. if ( mod == 'C' )
  631. {
  632. num_conflicting ++;
  633. os << "\t<Conflicting>" << std::endl;
  634. }
  635. else if ( mod == 'G' )
  636. {
  637. num_conflicting ++;
  638. os << "\t<Conflicting>" << std::endl;
  639. }
  640. else if ( mod == 'M' )
  641. {
  642. num_modified ++;
  643. os << "\t<Modified>" << std::endl;
  644. }
  645. else
  646. {
  647. num_updated ++;
  648. os << "\t<Updated>" << std::endl;
  649. }
  650. if ( srevision2 == "Unknown" )
  651. {
  652. srevision2 = srevision1;
  653. }
  654. if ( m_Verbose )
  655. {
  656. std::cout << "File: " << path.c_str() << " / " << fname.c_str() << " was updated by "
  657. << sauthor1.c_str() << " to revision: " << srevision1.c_str()
  658. << " from revision: " << srevision2.c_str() << std::endl;
  659. }
  660. os << "\t\t<File Directory=\"" << cmCTest::MakeXMLSafe(path) << "\">" << cmCTest::MakeXMLSafe(fname)
  661. << "</File>\n"
  662. << "\t\t<Directory>" << cmCTest::MakeXMLSafe(path) << "</Directory>\n"
  663. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(file) << "</FullName>\n"
  664. << "\t\t<CheckinDate>" << cmCTest::MakeXMLSafe(sdate1) << "</CheckinDate>\n"
  665. << "\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  666. << "\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  667. << "\t\t<Log>" << cmCTest::MakeXMLSafe(comment1) << "</Log>\n"
  668. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  669. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  670. << std::endl;
  671. if ( srevision2 != srevision1 )
  672. {
  673. os
  674. << "\t\t<Revisions>\n"
  675. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  676. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  677. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor1) << "</Author>\n"
  678. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate1) << "</Date>\n"
  679. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment1) << "</Comment>\n"
  680. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail1) << "</Email>\n"
  681. << "\t\t</Revisions>\n"
  682. << "\t\t<Revisions>\n"
  683. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  684. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  685. << "\t\t\t<Author>" << cmCTest::MakeXMLSafe(sauthor2) << "</Author>\n"
  686. << "\t\t\t<Date>" << cmCTest::MakeXMLSafe(sdate2) << "</Date>\n"
  687. << "\t\t\t<Comment>" << cmCTest::MakeXMLSafe(comment2) << "</Comment>\n"
  688. << "\t\t\t<Email>" << cmCTest::MakeXMLSafe(semail2) << "</Email>\n"
  689. << "\t\t</Revisions>" << std::endl;
  690. }
  691. if ( mod == 'C' )
  692. {
  693. os << "\t</Conflicting>" << std::endl;
  694. }
  695. else if ( mod == 'G' )
  696. {
  697. os << "\t</Conflicting>" << std::endl;
  698. }
  699. else if ( mod == 'M' )
  700. {
  701. os << "\t</Modified>" << std::endl;
  702. }
  703. else
  704. {
  705. os << "\t</Updated>" << std::endl;
  706. }
  707. cmCTestUpdateHandler::UpdateFiles *u = &authors_files_map[sauthor1];
  708. cmCTestUpdateHandler::StringPair p;
  709. p.first = path;
  710. p.second = fname;
  711. u->push_back(p);
  712. current_path = path;
  713. }
  714. file_count ++;
  715. }
  716. }
  717. if ( file_count )
  718. {
  719. std::cout << std::endl;
  720. }
  721. if ( num_updated )
  722. {
  723. std::cout << " Found " << num_updated << " updated files" << std::endl;
  724. }
  725. if ( num_modified )
  726. {
  727. std::cout << " Found " << num_modified << " locally modified files"
  728. << std::endl;
  729. }
  730. if ( num_conflicting )
  731. {
  732. std::cout << " Found " << num_conflicting << " conflicting files"
  733. << std::endl;
  734. }
  735. if ( num_modified == 0 && num_conflicting == 0 && num_updated == 0 )
  736. {
  737. std::cout << " Project is up-to-date" << std::endl;
  738. }
  739. if ( !first_file )
  740. {
  741. os << "\t</Directory>" << std::endl;
  742. }
  743. cmCTestUpdateHandler::AuthorsToUpdatesMap::iterator it;
  744. for ( it = authors_files_map.begin();
  745. it != authors_files_map.end();
  746. it ++ )
  747. {
  748. os << "\t<Author>\n"
  749. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  750. cmCTestUpdateHandler::UpdateFiles *u = &(it->second);
  751. for ( cc = 0; cc < u->size(); cc ++ )
  752. {
  753. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  754. << (*u)[cc].second << "</File>" << std::endl;
  755. }
  756. os << "\t</Author>" << std::endl;
  757. }
  758. //std::cout << "End" << std::endl;
  759. std::string end_time = m_CTest->CurrentTime();
  760. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  761. << "<ElapsedMinutes>" <<
  762. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  763. << "</ElapsedMinutes>"
  764. << "</Update>" << std::endl;
  765. if ( ofs )
  766. {
  767. ofs.close();
  768. }
  769. if (! res || retVal )
  770. {
  771. std::cerr << "Error(s) when updating the project" << std::endl;
  772. std::cerr << "Output: " << goutput << std::endl;
  773. return -1;
  774. }
  775. return count;
  776. }