cmCTestGIT.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestGIT.h"
  4. #include "cmsys/FStream.hxx"
  5. #include "cmsys/Process.h"
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10. #include <vector>
  11. #include "cmAlgorithms.h"
  12. #include "cmCTest.h"
  13. #include "cmCTestVC.h"
  14. #include "cmProcessOutput.h"
  15. #include "cmProcessTools.h"
  16. #include "cmSystemTools.h"
  17. static unsigned int cmCTestGITVersion(unsigned int epic, unsigned int major,
  18. unsigned int minor, unsigned int fix)
  19. {
  20. // 1.6.5.0 maps to 10605000
  21. return fix + minor * 1000 + major * 100000 + epic * 10000000;
  22. }
  23. cmCTestGIT::cmCTestGIT(cmCTest* ct, std::ostream& log)
  24. : cmCTestGlobalVC(ct, log)
  25. {
  26. this->PriorRev = this->Unknown;
  27. this->CurrentGitVersion = 0;
  28. }
  29. cmCTestGIT::~cmCTestGIT()
  30. {
  31. }
  32. class cmCTestGIT::OneLineParser : public cmCTestVC::LineParser
  33. {
  34. public:
  35. OneLineParser(cmCTestGIT* git, const char* prefix, std::string& l)
  36. : Line1(l)
  37. {
  38. this->SetLog(&git->Log, prefix);
  39. }
  40. private:
  41. std::string& Line1;
  42. bool ProcessLine() override
  43. {
  44. // Only the first line is of interest.
  45. this->Line1 = this->Line;
  46. return false;
  47. }
  48. };
  49. std::string cmCTestGIT::GetWorkingRevision()
  50. {
  51. // Run plumbing "git rev-list" to get work tree revision.
  52. const char* git = this->CommandLineTool.c_str();
  53. const char* git_rev_list[] = { git, "rev-list", "-n", "1",
  54. "HEAD", "--", nullptr };
  55. std::string rev;
  56. OneLineParser out(this, "rl-out> ", rev);
  57. OutputLogger err(this->Log, "rl-err> ");
  58. this->RunChild(git_rev_list, &out, &err);
  59. return rev;
  60. }
  61. bool cmCTestGIT::NoteOldRevision()
  62. {
  63. this->OldRevision = this->GetWorkingRevision();
  64. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  65. " Old revision of repository is: " << this->OldRevision
  66. << "\n");
  67. this->PriorRev.Rev = this->OldRevision;
  68. return true;
  69. }
  70. bool cmCTestGIT::NoteNewRevision()
  71. {
  72. this->NewRevision = this->GetWorkingRevision();
  73. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  74. " New revision of repository is: " << this->NewRevision
  75. << "\n");
  76. return true;
  77. }
  78. std::string cmCTestGIT::FindGitDir()
  79. {
  80. std::string git_dir;
  81. // Run "git rev-parse --git-dir" to locate the real .git directory.
  82. const char* git = this->CommandLineTool.c_str();
  83. char const* git_rev_parse[] = { git, "rev-parse", "--git-dir", nullptr };
  84. std::string git_dir_line;
  85. OneLineParser rev_parse_out(this, "rev-parse-out> ", git_dir_line);
  86. OutputLogger rev_parse_err(this->Log, "rev-parse-err> ");
  87. if (this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err, nullptr,
  88. cmProcessOutput::UTF8)) {
  89. git_dir = git_dir_line;
  90. }
  91. if (git_dir.empty()) {
  92. git_dir = ".git";
  93. }
  94. // Git reports a relative path only when the .git directory is in
  95. // the current directory.
  96. if (git_dir[0] == '.') {
  97. git_dir = this->SourceDirectory + "/" + git_dir;
  98. }
  99. #if defined(_WIN32) && !defined(__CYGWIN__)
  100. else if (git_dir[0] == '/') {
  101. // Cygwin Git reports a full path that Cygwin understands, but we
  102. // are a Windows application. Run "cygpath" to get Windows path.
  103. std::string cygpath_exe = cmSystemTools::GetFilenamePath(git);
  104. cygpath_exe += "/cygpath.exe";
  105. if (cmSystemTools::FileExists(cygpath_exe)) {
  106. char const* cygpath[] = { cygpath_exe.c_str(), "-w", git_dir.c_str(),
  107. 0 };
  108. OneLineParser cygpath_out(this, "cygpath-out> ", git_dir_line);
  109. OutputLogger cygpath_err(this->Log, "cygpath-err> ");
  110. if (this->RunChild(cygpath, &cygpath_out, &cygpath_err, nullptr,
  111. cmProcessOutput::UTF8)) {
  112. git_dir = git_dir_line;
  113. }
  114. }
  115. }
  116. #endif
  117. return git_dir;
  118. }
  119. std::string cmCTestGIT::FindTopDir()
  120. {
  121. std::string top_dir = this->SourceDirectory;
  122. // Run "git rev-parse --show-cdup" to locate the top of the tree.
  123. const char* git = this->CommandLineTool.c_str();
  124. char const* git_rev_parse[] = { git, "rev-parse", "--show-cdup", nullptr };
  125. std::string cdup;
  126. OneLineParser rev_parse_out(this, "rev-parse-out> ", cdup);
  127. OutputLogger rev_parse_err(this->Log, "rev-parse-err> ");
  128. if (this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err, nullptr,
  129. cmProcessOutput::UTF8) &&
  130. !cdup.empty()) {
  131. top_dir += "/";
  132. top_dir += cdup;
  133. top_dir = cmSystemTools::CollapseFullPath(top_dir);
  134. }
  135. return top_dir;
  136. }
  137. bool cmCTestGIT::UpdateByFetchAndReset()
  138. {
  139. const char* git = this->CommandLineTool.c_str();
  140. // Use "git fetch" to get remote commits.
  141. std::vector<char const*> git_fetch;
  142. git_fetch.push_back(git);
  143. git_fetch.push_back("fetch");
  144. // Add user-specified update options.
  145. std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
  146. if (opts.empty()) {
  147. opts = this->CTest->GetCTestConfiguration("GITUpdateOptions");
  148. }
  149. std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
  150. for (std::string const& arg : args) {
  151. git_fetch.push_back(arg.c_str());
  152. }
  153. // Sentinel argument.
  154. git_fetch.push_back(nullptr);
  155. // Fetch upstream refs.
  156. OutputLogger fetch_out(this->Log, "fetch-out> ");
  157. OutputLogger fetch_err(this->Log, "fetch-err> ");
  158. if (!this->RunUpdateCommand(&git_fetch[0], &fetch_out, &fetch_err)) {
  159. return false;
  160. }
  161. // Identify the merge head that would be used by "git pull".
  162. std::string sha1;
  163. {
  164. std::string fetch_head = this->FindGitDir() + "/FETCH_HEAD";
  165. cmsys::ifstream fin(fetch_head.c_str(), std::ios::in | std::ios::binary);
  166. if (!fin) {
  167. this->Log << "Unable to open " << fetch_head << "\n";
  168. return false;
  169. }
  170. std::string line;
  171. while (sha1.empty() && cmSystemTools::GetLineFromStream(fin, line)) {
  172. this->Log << "FETCH_HEAD> " << line << "\n";
  173. if (line.find("\tnot-for-merge\t") == std::string::npos) {
  174. std::string::size_type pos = line.find('\t');
  175. if (pos != std::string::npos) {
  176. sha1 = line.substr(0, pos);
  177. }
  178. }
  179. }
  180. if (sha1.empty()) {
  181. this->Log << "FETCH_HEAD has no upstream branch candidate!\n";
  182. return false;
  183. }
  184. }
  185. // Reset the local branch to point at that tracked from upstream.
  186. char const* git_reset[] = { git, "reset", "--hard", sha1.c_str(), nullptr };
  187. OutputLogger reset_out(this->Log, "reset-out> ");
  188. OutputLogger reset_err(this->Log, "reset-err> ");
  189. return this->RunChild(&git_reset[0], &reset_out, &reset_err);
  190. }
  191. bool cmCTestGIT::UpdateByCustom(std::string const& custom)
  192. {
  193. std::vector<std::string> git_custom_command;
  194. cmSystemTools::ExpandListArgument(custom, git_custom_command, true);
  195. std::vector<char const*> git_custom;
  196. git_custom.reserve(git_custom_command.size() + 1);
  197. for (std::string const& i : git_custom_command) {
  198. git_custom.push_back(i.c_str());
  199. }
  200. git_custom.push_back(nullptr);
  201. OutputLogger custom_out(this->Log, "custom-out> ");
  202. OutputLogger custom_err(this->Log, "custom-err> ");
  203. return this->RunUpdateCommand(&git_custom[0], &custom_out, &custom_err);
  204. }
  205. bool cmCTestGIT::UpdateInternal()
  206. {
  207. std::string custom = this->CTest->GetCTestConfiguration("GITUpdateCustom");
  208. if (!custom.empty()) {
  209. return this->UpdateByCustom(custom);
  210. }
  211. return this->UpdateByFetchAndReset();
  212. }
  213. bool cmCTestGIT::UpdateImpl()
  214. {
  215. if (!this->UpdateInternal()) {
  216. return false;
  217. }
  218. std::string top_dir = this->FindTopDir();
  219. const char* git = this->CommandLineTool.c_str();
  220. const char* recursive = "--recursive";
  221. const char* sync_recursive = "--recursive";
  222. // Git < 1.6.5 did not support submodule --recursive
  223. if (this->GetGitVersion() < cmCTestGITVersion(1, 6, 5, 0)) {
  224. recursive = nullptr;
  225. // No need to require >= 1.6.5 if there are no submodules.
  226. if (cmSystemTools::FileExists(top_dir + "/.gitmodules")) {
  227. this->Log << "Git < 1.6.5 cannot update submodules recursively\n";
  228. }
  229. }
  230. // Git < 1.8.1 did not support sync --recursive
  231. if (this->GetGitVersion() < cmCTestGITVersion(1, 8, 1, 0)) {
  232. sync_recursive = nullptr;
  233. // No need to require >= 1.8.1 if there are no submodules.
  234. if (cmSystemTools::FileExists(top_dir + "/.gitmodules")) {
  235. this->Log << "Git < 1.8.1 cannot synchronize submodules recursively\n";
  236. }
  237. }
  238. OutputLogger submodule_out(this->Log, "submodule-out> ");
  239. OutputLogger submodule_err(this->Log, "submodule-err> ");
  240. bool ret;
  241. std::string init_submodules =
  242. this->CTest->GetCTestConfiguration("GITInitSubmodules");
  243. if (cmSystemTools::IsOn(init_submodules)) {
  244. char const* git_submodule_init[] = { git, "submodule", "init", nullptr };
  245. ret = this->RunChild(git_submodule_init, &submodule_out, &submodule_err,
  246. top_dir.c_str());
  247. if (!ret) {
  248. return false;
  249. }
  250. }
  251. char const* git_submodule_sync[] = { git, "submodule", "sync",
  252. sync_recursive, nullptr };
  253. ret = this->RunChild(git_submodule_sync, &submodule_out, &submodule_err,
  254. top_dir.c_str());
  255. if (!ret) {
  256. return false;
  257. }
  258. char const* git_submodule[] = { git, "submodule", "update", recursive,
  259. nullptr };
  260. return this->RunChild(git_submodule, &submodule_out, &submodule_err,
  261. top_dir.c_str());
  262. }
  263. unsigned int cmCTestGIT::GetGitVersion()
  264. {
  265. if (!this->CurrentGitVersion) {
  266. const char* git = this->CommandLineTool.c_str();
  267. char const* git_version[] = { git, "--version", nullptr };
  268. std::string version;
  269. OneLineParser version_out(this, "version-out> ", version);
  270. OutputLogger version_err(this->Log, "version-err> ");
  271. unsigned int v[4] = { 0, 0, 0, 0 };
  272. if (this->RunChild(git_version, &version_out, &version_err) &&
  273. sscanf(version.c_str(), "git version %u.%u.%u.%u", &v[0], &v[1], &v[2],
  274. &v[3]) >= 3) {
  275. this->CurrentGitVersion = cmCTestGITVersion(v[0], v[1], v[2], v[3]);
  276. }
  277. }
  278. return this->CurrentGitVersion;
  279. }
  280. /* Diff format:
  281. :src-mode dst-mode src-sha1 dst-sha1 status\0
  282. src-path\0
  283. [dst-path\0]
  284. The format is repeated for every file changed. The [dst-path\0]
  285. line appears only for lines with status 'C' or 'R'. See 'git help
  286. diff-tree' for details.
  287. */
  288. class cmCTestGIT::DiffParser : public cmCTestVC::LineParser
  289. {
  290. public:
  291. DiffParser(cmCTestGIT* git, const char* prefix)
  292. : LineParser('\0', false)
  293. , GIT(git)
  294. , DiffField(DiffFieldNone)
  295. {
  296. this->SetLog(&git->Log, prefix);
  297. }
  298. typedef cmCTestGIT::Change Change;
  299. std::vector<Change> Changes;
  300. protected:
  301. cmCTestGIT* GIT;
  302. enum DiffFieldType
  303. {
  304. DiffFieldNone,
  305. DiffFieldChange,
  306. DiffFieldSrc,
  307. DiffFieldDst
  308. };
  309. DiffFieldType DiffField;
  310. Change CurChange;
  311. void DiffReset()
  312. {
  313. this->DiffField = DiffFieldNone;
  314. this->Changes.clear();
  315. }
  316. bool ProcessLine() override
  317. {
  318. if (this->Line[0] == ':') {
  319. this->DiffField = DiffFieldChange;
  320. this->CurChange = Change();
  321. }
  322. if (this->DiffField == DiffFieldChange) {
  323. // :src-mode dst-mode src-sha1 dst-sha1 status
  324. if (this->Line[0] != ':') {
  325. this->DiffField = DiffFieldNone;
  326. return true;
  327. }
  328. const char* src_mode_first = this->Line.c_str() + 1;
  329. const char* src_mode_last = this->ConsumeField(src_mode_first);
  330. const char* dst_mode_first = this->ConsumeSpace(src_mode_last);
  331. const char* dst_mode_last = this->ConsumeField(dst_mode_first);
  332. const char* src_sha1_first = this->ConsumeSpace(dst_mode_last);
  333. const char* src_sha1_last = this->ConsumeField(src_sha1_first);
  334. const char* dst_sha1_first = this->ConsumeSpace(src_sha1_last);
  335. const char* dst_sha1_last = this->ConsumeField(dst_sha1_first);
  336. const char* status_first = this->ConsumeSpace(dst_sha1_last);
  337. const char* status_last = this->ConsumeField(status_first);
  338. if (status_first != status_last) {
  339. this->CurChange.Action = *status_first;
  340. this->DiffField = DiffFieldSrc;
  341. } else {
  342. this->DiffField = DiffFieldNone;
  343. }
  344. } else if (this->DiffField == DiffFieldSrc) {
  345. // src-path
  346. if (this->CurChange.Action == 'C') {
  347. // Convert copy to addition of destination.
  348. this->CurChange.Action = 'A';
  349. this->DiffField = DiffFieldDst;
  350. } else if (this->CurChange.Action == 'R') {
  351. // Convert rename to deletion of source and addition of destination.
  352. this->CurChange.Action = 'D';
  353. this->CurChange.Path = this->Line;
  354. this->Changes.push_back(this->CurChange);
  355. this->CurChange = Change('A');
  356. this->DiffField = DiffFieldDst;
  357. } else {
  358. this->CurChange.Path = this->Line;
  359. this->Changes.push_back(this->CurChange);
  360. this->DiffField = this->DiffFieldNone;
  361. }
  362. } else if (this->DiffField == DiffFieldDst) {
  363. // dst-path
  364. this->CurChange.Path = this->Line;
  365. this->Changes.push_back(this->CurChange);
  366. this->DiffField = this->DiffFieldNone;
  367. }
  368. return true;
  369. }
  370. const char* ConsumeSpace(const char* c)
  371. {
  372. while (*c && isspace(*c)) {
  373. ++c;
  374. }
  375. return c;
  376. }
  377. const char* ConsumeField(const char* c)
  378. {
  379. while (*c && !isspace(*c)) {
  380. ++c;
  381. }
  382. return c;
  383. }
  384. };
  385. /* Commit format:
  386. commit ...\n
  387. tree ...\n
  388. parent ...\n
  389. author ...\n
  390. committer ...\n
  391. \n
  392. Log message indented by (4) spaces\n
  393. (even blank lines have the spaces)\n
  394. [[
  395. \n
  396. [Diff format]
  397. OR
  398. \0
  399. ]]
  400. The header may have more fields. See 'git help diff-tree'.
  401. */
  402. class cmCTestGIT::CommitParser : public cmCTestGIT::DiffParser
  403. {
  404. public:
  405. CommitParser(cmCTestGIT* git, const char* prefix)
  406. : DiffParser(git, prefix)
  407. , Section(SectionHeader)
  408. {
  409. this->Separator = SectionSep[this->Section];
  410. }
  411. private:
  412. typedef cmCTestGIT::Revision Revision;
  413. enum SectionType
  414. {
  415. SectionHeader,
  416. SectionBody,
  417. SectionDiff,
  418. SectionCount
  419. };
  420. static char const SectionSep[SectionCount];
  421. SectionType Section;
  422. Revision Rev;
  423. struct Person
  424. {
  425. std::string Name;
  426. std::string EMail;
  427. unsigned long Time = 0;
  428. long TimeZone = 0;
  429. Person() {}
  430. };
  431. void ParsePerson(const char* str, Person& person)
  432. {
  433. // Person Name <[email protected]> 1234567890 +0000
  434. const char* c = str;
  435. while (*c && isspace(*c)) {
  436. ++c;
  437. }
  438. const char* name_first = c;
  439. while (*c && *c != '<') {
  440. ++c;
  441. }
  442. const char* name_last = c;
  443. while (name_last != name_first && isspace(*(name_last - 1))) {
  444. --name_last;
  445. }
  446. person.Name.assign(name_first, name_last - name_first);
  447. const char* email_first = *c ? ++c : c;
  448. while (*c && *c != '>') {
  449. ++c;
  450. }
  451. const char* email_last = *c ? c++ : c;
  452. person.EMail.assign(email_first, email_last - email_first);
  453. person.Time = strtoul(c, const_cast<char**>(&c), 10);
  454. person.TimeZone = strtol(c, const_cast<char**>(&c), 10);
  455. }
  456. bool ProcessLine() override
  457. {
  458. if (this->Line.empty()) {
  459. if (this->Section == SectionBody && this->LineEnd == '\0') {
  460. // Skip SectionDiff
  461. this->NextSection();
  462. }
  463. this->NextSection();
  464. } else {
  465. switch (this->Section) {
  466. case SectionHeader:
  467. this->DoHeaderLine();
  468. break;
  469. case SectionBody:
  470. this->DoBodyLine();
  471. break;
  472. case SectionDiff:
  473. this->DiffParser::ProcessLine();
  474. break;
  475. case SectionCount:
  476. break; // never happens
  477. }
  478. }
  479. return true;
  480. }
  481. void NextSection()
  482. {
  483. this->Section = SectionType((this->Section + 1) % SectionCount);
  484. this->Separator = SectionSep[this->Section];
  485. if (this->Section == SectionHeader) {
  486. this->GIT->DoRevision(this->Rev, this->Changes);
  487. this->Rev = Revision();
  488. this->DiffReset();
  489. }
  490. }
  491. void DoHeaderLine()
  492. {
  493. // Look for header fields that we need.
  494. if (cmHasLiteralPrefix(this->Line, "commit ")) {
  495. this->Rev.Rev = this->Line.c_str() + 7;
  496. } else if (cmHasLiteralPrefix(this->Line, "author ")) {
  497. Person author;
  498. this->ParsePerson(this->Line.c_str() + 7, author);
  499. this->Rev.Author = author.Name;
  500. this->Rev.EMail = author.EMail;
  501. this->Rev.Date = this->FormatDateTime(author);
  502. } else if (cmHasLiteralPrefix(this->Line, "committer ")) {
  503. Person committer;
  504. this->ParsePerson(this->Line.c_str() + 10, committer);
  505. this->Rev.Committer = committer.Name;
  506. this->Rev.CommitterEMail = committer.EMail;
  507. this->Rev.CommitDate = this->FormatDateTime(committer);
  508. }
  509. }
  510. void DoBodyLine()
  511. {
  512. // Commit log lines are indented by 4 spaces.
  513. if (this->Line.size() >= 4) {
  514. this->Rev.Log += this->Line.substr(4);
  515. }
  516. this->Rev.Log += "\n";
  517. }
  518. std::string FormatDateTime(Person const& person)
  519. {
  520. // Convert the time to a human-readable format that is also easy
  521. // to machine-parse: "CCYY-MM-DD hh:mm:ss".
  522. time_t seconds = static_cast<time_t>(person.Time);
  523. struct tm* t = gmtime(&seconds);
  524. char dt[1024];
  525. sprintf(dt, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900,
  526. t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
  527. std::string out = dt;
  528. // Add the time-zone field "+zone" or "-zone".
  529. char tz[32];
  530. if (person.TimeZone >= 0) {
  531. sprintf(tz, " +%04ld", person.TimeZone);
  532. } else {
  533. sprintf(tz, " -%04ld", -person.TimeZone);
  534. }
  535. out += tz;
  536. return out;
  537. }
  538. };
  539. char const cmCTestGIT::CommitParser::SectionSep[SectionCount] = { '\n', '\n',
  540. '\0' };
  541. bool cmCTestGIT::LoadRevisions()
  542. {
  543. // Use 'git rev-list ... | git diff-tree ...' to get revisions.
  544. std::string range = this->OldRevision + ".." + this->NewRevision;
  545. const char* git = this->CommandLineTool.c_str();
  546. const char* git_rev_list[] = { git, "rev-list", "--reverse",
  547. range.c_str(), "--", nullptr };
  548. const char* git_diff_tree[] = {
  549. git, "diff-tree", "--stdin", "--always", "-z",
  550. "-r", "--pretty=raw", "--encoding=utf-8", nullptr
  551. };
  552. this->Log << cmCTestGIT::ComputeCommandLine(git_rev_list) << " | "
  553. << cmCTestGIT::ComputeCommandLine(git_diff_tree) << "\n";
  554. cmsysProcess* cp = cmsysProcess_New();
  555. cmsysProcess_AddCommand(cp, git_rev_list);
  556. cmsysProcess_AddCommand(cp, git_diff_tree);
  557. cmsysProcess_SetWorkingDirectory(cp, this->SourceDirectory.c_str());
  558. CommitParser out(this, "dt-out> ");
  559. OutputLogger err(this->Log, "dt-err> ");
  560. cmCTestGIT::RunProcess(cp, &out, &err, cmProcessOutput::UTF8);
  561. // Send one extra zero-byte to terminate the last record.
  562. out.Process("", 1);
  563. cmsysProcess_Delete(cp);
  564. return true;
  565. }
  566. bool cmCTestGIT::LoadModifications()
  567. {
  568. const char* git = this->CommandLineTool.c_str();
  569. // Use 'git update-index' to refresh the index w.r.t. the work tree.
  570. const char* git_update_index[] = { git, "update-index", "--refresh",
  571. nullptr };
  572. OutputLogger ui_out(this->Log, "ui-out> ");
  573. OutputLogger ui_err(this->Log, "ui-err> ");
  574. this->RunChild(git_update_index, &ui_out, &ui_err, nullptr,
  575. cmProcessOutput::UTF8);
  576. // Use 'git diff-index' to get modified files.
  577. const char* git_diff_index[] = { git, "diff-index", "-z",
  578. "HEAD", "--", nullptr };
  579. DiffParser out(this, "di-out> ");
  580. OutputLogger err(this->Log, "di-err> ");
  581. this->RunChild(git_diff_index, &out, &err, nullptr, cmProcessOutput::UTF8);
  582. for (Change const& c : out.Changes) {
  583. this->DoModification(PathModified, c.Path);
  584. }
  585. return true;
  586. }