@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move git commit metadata parsing into a LowLevelQuery

Summary: Ref T4195. I need to issue this command from the pre-commit hook to get commit bodies for hooks.

Test Plan: Ran `reparse.php --message --trace` and dumped the $ref, which looked correct.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4195

Differential Revision: https://secure.phabricator.com/D7793

+120 -25
+4
src/__phutil_library_map__.php
··· 482 482 'DiffusionCommitHookRejectException' => 'applications/diffusion/exception/DiffusionCommitHookRejectException.php', 483 483 'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php', 484 484 'DiffusionCommitQuery' => 'applications/diffusion/query/DiffusionCommitQuery.php', 485 + 'DiffusionCommitRef' => 'applications/diffusion/data/DiffusionCommitRef.php', 485 486 'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php', 486 487 'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php', 487 488 'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php', ··· 506 507 'DiffusionLintController' => 'applications/diffusion/controller/DiffusionLintController.php', 507 508 'DiffusionLintDetailsController' => 'applications/diffusion/controller/DiffusionLintDetailsController.php', 508 509 'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php', 510 + 'DiffusionLowLevelGitCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php', 509 511 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 510 512 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', 511 513 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', ··· 2866 2868 'DiffusionCommitHookRejectException' => 'Exception', 2867 2869 'DiffusionCommitParentsQuery' => 'DiffusionQuery', 2868 2870 'DiffusionCommitQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2871 + 'DiffusionCommitRef' => 'Phobject', 2869 2872 'DiffusionCommitTagsController' => 'DiffusionController', 2870 2873 'DiffusionController' => 'PhabricatorController', 2871 2874 'DiffusionDiffController' => 'DiffusionController', ··· 2887 2890 'DiffusionLastModifiedController' => 'DiffusionController', 2888 2891 'DiffusionLintController' => 'DiffusionController', 2889 2892 'DiffusionLintDetailsController' => 'DiffusionController', 2893 + 'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery', 2890 2894 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 2891 2895 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', 2892 2896 'DiffusionLowLevelQuery' => 'Phobject',
+59
src/applications/diffusion/data/DiffusionCommitRef.php
··· 1 + <?php 2 + 3 + final class DiffusionCommitRef extends Phobject { 4 + 5 + private $message; 6 + private $authorName; 7 + private $authorEmail; 8 + private $committerName; 9 + private $committerEmail; 10 + 11 + public function setCommitterEmail($committer_email) { 12 + $this->committerEmail = $committer_email; 13 + return $this; 14 + } 15 + 16 + public function getCommitterEmail() { 17 + return $this->committerEmail; 18 + } 19 + 20 + 21 + public function setCommitterName($committer_name) { 22 + $this->committerName = $committer_name; 23 + return $this; 24 + } 25 + 26 + public function getCommitterName() { 27 + return $this->committerName; 28 + } 29 + 30 + 31 + public function setAuthorEmail($author_email) { 32 + $this->authorEmail = $author_email; 33 + return $this; 34 + } 35 + 36 + public function getAuthorEmail() { 37 + return $this->authorEmail; 38 + } 39 + 40 + 41 + public function setAuthorName($author_name) { 42 + $this->authorName = $author_name; 43 + return $this; 44 + } 45 + 46 + public function getAuthorName() { 47 + return $this->authorName; 48 + } 49 + 50 + public function setMessage($message) { 51 + $this->message = $message; 52 + return $this; 53 + } 54 + 55 + public function getMessage() { 56 + return $this->message; 57 + } 58 + 59 + }
+48
src/applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php
··· 1 + <?php 2 + 3 + final class DiffusionLowLevelGitCommitQuery extends DiffusionLowLevelQuery { 4 + 5 + private $identifier; 6 + 7 + public function withIdentifier($identifier) { 8 + $this->identifier = $identifier; 9 + return $this; 10 + } 11 + 12 + protected function executeQuery() { 13 + $repository = $this->getRepository(); 14 + 15 + // NOTE: %B was introduced somewhat recently in git's history, so pull 16 + // commit message information with %s and %b instead. 17 + 18 + // Even though we pass --encoding here, git doesn't always succeed, so 19 + // we try a little harder, since git *does* tell us what the actual encoding 20 + // is correctly (unless it doesn't; encoding is sometimes empty). 21 + list($info) = $repository->execxLocalCommand( 22 + 'log -n 1 --encoding=%s --format=%s %s --', 23 + 'UTF-8', 24 + implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')), 25 + $this->identifier); 26 + 27 + $parts = explode("\0", $info); 28 + $encoding = array_shift($parts); 29 + 30 + foreach ($parts as $key => $part) { 31 + if ($encoding) { 32 + $part = phutil_utf8_convert($part, 'UTF-8', $encoding); 33 + } 34 + $parts[$key] = phutil_utf8ize($part); 35 + if (!strlen($parts[$key])) { 36 + $parts[$key] = null; 37 + } 38 + } 39 + 40 + return id(new DiffusionCommitRef()) 41 + ->setCommitterName($parts[0]) 42 + ->setCommitterEmail($parts[1]) 43 + ->setAuthorName($parts[2]) 44 + ->setAuthorEmail($parts[3]) 45 + ->setMessage($parts[4]); 46 + } 47 + 48 + }
+9 -25
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php
··· 7 7 PhabricatorRepository $repository, 8 8 PhabricatorRepositoryCommit $commit) { 9 9 10 - // NOTE: %B was introduced somewhat recently in git's history, so pull 11 - // commit message information with %s and %b instead. 12 - // Even though we pass --encoding here, git doesn't always succeed, so 13 - // we try a little harder, since git *does* tell us what the actual encoding 14 - // is correctly (unless it doesn't; encoding is sometimes empty). 15 - list($info) = $repository->execxLocalCommand( 16 - 'log -n 1 --encoding=%s --format=%s %s --', 17 - 'UTF-8', 18 - implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')), 19 - $commit->getCommitIdentifier()); 20 - 21 - $parts = explode("\0", $info); 22 - $encoding = array_shift($parts); 23 - 24 - foreach ($parts as $key => $part) { 25 - if ($encoding) { 26 - $part = phutil_utf8_convert($part, 'UTF-8', $encoding); 27 - } 28 - $parts[$key] = phutil_utf8ize($part); 29 - } 10 + $ref = id(new DiffusionLowLevelGitCommitQuery()) 11 + ->setRepository($repository) 12 + ->withIdentifier($commit->getCommitIdentifier()) 13 + ->execute(); 30 14 31 - $committer_name = $parts[0]; 32 - $committer_email = $parts[1]; 33 - $author_name = $parts[2]; 34 - $author_email = $parts[3]; 35 - $message = $parts[4]; 15 + $committer_name = $ref->getCommitterName(); 16 + $committer_email = $ref->getCommitterEmail(); 17 + $author_name = $ref->getAuthorName(); 18 + $author_email = $ref->getAuthorEmail(); 19 + $message = $ref->getMessage(); 36 20 37 21 if (strlen($author_email)) { 38 22 $author = "{$author_name} <{$author_email}>";