Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementMarkReachableWorkflow.php
blob1f235c3fb67b6f0ec72726cb236338034db6f627
1 <?php
3 final class PhabricatorRepositoryManagementMarkReachableWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 private $untouchedCount = 0;
8 protected function didConstruct() {
9 $this
10 ->setName('mark-reachable')
11 ->setExamples('**mark-reachable** [__options__] __repository__ ...')
12 ->setSynopsis(
13 pht(
14 'Rebuild "unreachable" flags for commits in __repository__.'))
15 ->setArguments(
16 array(
17 array(
18 'name' => 'repos',
19 'wildcard' => true,
21 ));
24 public function execute(PhutilArgumentParser $args) {
25 $repos = $this->loadRepositories($args, 'repos');
26 if (!$repos) {
27 throw new PhutilArgumentUsageException(
28 pht(
29 'Specify one or more repositories to correct reachability status '.
30 'for.'));
33 foreach ($repos as $repo) {
34 $this->markReachable($repo);
37 echo tsprintf(
38 "%s\n",
39 pht(
40 'Examined %s commits already in the correct state.',
41 new PhutilNumber($this->untouchedCount)));
43 echo tsprintf(
44 "%s\n",
45 pht('Done.'));
47 return 0;
50 private function markReachable(PhabricatorRepository $repository) {
51 if (!$repository->isGit() && !$repository->isHg()) {
52 throw new PhutilArgumentUsageException(
53 pht(
54 'Only Git and Mercurial repositories are supported, unable to '.
55 'operate on this repository ("%s").',
56 $repository->getDisplayName()));
59 $viewer = $this->getViewer();
61 $commits = id(new DiffusionCommitQuery())
62 ->setViewer($viewer)
63 ->withRepository($repository)
64 ->execute();
66 $flag = PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE;
68 if ($repository->isGit()) {
69 $graph = new PhabricatorGitGraphStream($repository);
70 } else if ($repository->isHg()) {
71 $graph = new PhabricatorMercurialGraphStream($repository);
74 foreach ($commits as $commit) {
75 $identifier = $commit->getCommitIdentifier();
77 try {
78 $graph->getCommitDate($identifier);
79 $unreachable = false;
80 } catch (Exception $ex) {
81 $unreachable = true;
84 // The commit has proper reachability, so do nothing.
85 if ($commit->isUnreachable() === $unreachable) {
86 $this->untouchedCount++;
87 continue;
90 if ($unreachable) {
91 echo tsprintf(
92 "%s: %s\n",
93 $commit->getMonogram(),
94 pht('Marking commit unreachable.'));
96 $commit->writeImportStatusFlag($flag);
97 } else {
98 echo tsprintf(
99 "%s: %s\n",
100 $commit->getMonogram(),
101 pht('Marking commit reachable.'));
103 $commit->clearImportStatusFlag($flag);