cmCTestUpdateHandler.cxx 26 KB

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