3 abstract class PhabricatorRepositoryCommitParserWorker
4 extends PhabricatorWorker
{
9 private function loadCommit() {
14 $viewer = $this->getViewer();
15 $task_data = $this->getTaskData();
17 $commit_query = id(new DiffusionCommitQuery())
20 $commit_phid = idx($task_data, 'commitPHID');
22 // TODO: See T13591. This supports execution of legacy tasks and can
23 // eventually be removed. Newer tasks use "commitPHID" instead of
26 $commit_id = idx($task_data, 'commitID');
28 $legacy_commit = id(clone $commit_query)
29 ->withIDs(array($commit_id))
32 $commit_phid = $legacy_commit->getPHID();
38 throw new PhabricatorWorkerPermanentFailureException(
39 pht('Task data has no "commitPHID".'));
42 $commit = id(clone $commit_query)
43 ->withPHIDs(array($commit_phid))
46 throw new PhabricatorWorkerPermanentFailureException(
47 pht('Commit "%s" does not exist.', $commit_phid));
50 if ($commit->isUnreachable()) {
51 throw new PhabricatorWorkerPermanentFailureException(
53 'Commit "%s" (with PHID "%s") is no longer reachable from any '.
54 'branch, tag, or ref in this repository, so it will not be '.
55 'imported. This usually means that the branch the commit was on '.
56 'was deleted or overwritten.',
57 $commit->getMonogram(),
61 $this->commit
= $commit;
66 final protected function doWork() {
67 $commit = $this->loadCommit();
68 $repository = $commit->getRepository();
70 $this->repository
= $repository;
72 $this->parseCommit($repository, $this->commit
);
75 private function shouldQueueFollowupTasks() {
76 return !idx($this->getTaskData(), 'only');
79 final protected function queueCommitTask($task_class) {
80 if (!$this->shouldQueueFollowupTasks()) {
84 $commit = $this->loadCommit();
85 $repository = $commit->getRepository();
88 'commitPHID' => $commit->getPHID(),
91 $task_data = $this->getTaskData();
92 if (isset($task_data['via'])) {
93 $data['via'] = $task_data['via'];
97 // We queue followup tasks at default priority so that the queue finishes
98 // work it has started before starting more work. If followups are queued
99 // at the same priority level, we do all message parses first, then all
100 // change parses, etc. This makes progress uneven. See T11677 for
102 'priority' => parent
::PRIORITY_DEFAULT
,
104 'objectPHID' => $commit->getPHID(),
105 'containerPHID' => $repository->getPHID(),
108 $this->queueTask($task_class, $data, $options);
111 protected function getImportStepFlag() {
115 final protected function shouldSkipImportStep() {
116 // If this step has already been performed and this is a "natural" task
117 // which was queued by the normal daemons, decline to do the work again.
118 // This mitigates races if commits are rapidly deleted and revived.
119 $flag = $this->getImportStepFlag();
121 // This step doesn't have an associated flag.
125 $commit = $this->commit
;
126 if (!$commit->isPartiallyImported($flag)) {
127 // This commit doesn't have the flag set yet.
132 if (!$this->shouldQueueFollowupTasks()) {
133 // This task was queued by administrative tools, so do the work even
134 // if it duplicates existing work.
141 'Skipping import step; this step was previously completed for '.
147 abstract protected function parseCommit(
148 PhabricatorRepository
$repository,
149 PhabricatorRepositoryCommit
$commit);
151 protected function loadCommitHint(PhabricatorRepositoryCommit
$commit) {
152 $viewer = PhabricatorUser
::getOmnipotentUser();
154 $repository = $commit->getRepository();
156 return id(new DiffusionCommitHintQuery())
158 ->withRepositoryPHIDs(array($repository->getPHID()))
159 ->withOldCommitIdentifiers(array($commit->getCommitIdentifier()))
163 public function renderForDisplay(PhabricatorUser
$viewer) {
164 $suffix = parent
::renderForDisplay($viewer);
166 $commit = id(new DiffusionCommitQuery())
168 ->withPHIDs(array(idx($this->getTaskData(), 'commitPHID')))
174 $link = DiffusionView
::linkCommit(
175 $commit->getRepository(),
176 $commit->getCommitIdentifier());
178 return array($link, $suffix);
181 final protected function loadCommitData(PhabricatorRepositoryCommit
$commit) {
182 if ($commit->hasCommitData()) {
183 return $commit->getCommitData();
186 $commit_id = $commit->getID();
188 $data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
192 $data = id(new PhabricatorRepositoryCommitData())
193 ->setCommitID($commit_id);
196 $commit->attachCommitData($data);
201 final public function getViewer() {
202 return PhabricatorUser
::getOmnipotentUser();