@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.

at recaptime-dev/main 108 lines 2.8 kB view raw
1<?php 2 3final class PhabricatorRepositoryManagementMarkReachableWorkflow 4 extends PhabricatorRepositoryManagementWorkflow { 5 6 private $untouchedCount = 0; 7 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, 20 ), 21 )); 22 } 23 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.')); 31 } 32 33 foreach ($repos as $repo) { 34 $this->markReachable($repo); 35 } 36 37 echo tsprintf( 38 "%s\n", 39 pht( 40 'Examined %s commits already in the correct state.', 41 new PhutilNumber($this->untouchedCount))); 42 43 echo tsprintf( 44 "%s\n", 45 pht('Done.')); 46 47 return 0; 48 } 49 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())); 57 } 58 59 $viewer = $this->getViewer(); 60 61 $commits = id(new DiffusionCommitQuery()) 62 ->setViewer($viewer) 63 ->withRepository($repository) 64 ->execute(); 65 66 $flag = PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE; 67 68 if ($repository->isGit()) { 69 $graph = new PhabricatorGitGraphStream($repository); 70 } else if ($repository->isHg()) { 71 $graph = new PhabricatorMercurialGraphStream($repository); 72 } 73 74 foreach ($commits as $commit) { 75 $identifier = $commit->getCommitIdentifier(); 76 77 try { 78 $graph->getCommitDate($identifier); 79 $unreachable = false; 80 } catch (Exception $ex) { 81 $unreachable = true; 82 } 83 84 // The commit has proper reachability, so do nothing. 85 if ($commit->isUnreachable() === $unreachable) { 86 $this->untouchedCount++; 87 continue; 88 } 89 90 if ($unreachable) { 91 echo tsprintf( 92 "%s: %s\n", 93 $commit->getMonogram(), 94 pht('Marking commit unreachable.')); 95 96 $commit->writeImportStatusFlag($flag); 97 } else { 98 echo tsprintf( 99 "%s: %s\n", 100 $commit->getMonogram(), 101 pht('Marking commit reachable.')); 102 103 $commit->clearImportStatusFlag($flag); 104 } 105 } 106 } 107 108}