cmCTestGIT.cxx 19 KB

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