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

Add support to marking commits as UNREACHABLE for Mercurial

Summary:
When previously known commits have been destroyed in a Mercurial repository, Phabricator does not end up marking the commits as unreachable. This results in daemon tasks which continuously fail and retry.

This updates `PhabricatorRepositoryDiscoveryEngine` and `PhabricatorManagementRepositoryMarkReachableWorkflow` to include support of marking commits as unreachable for Mercurial repositories.

The `PhabricatorMercurialGraphStream` also needed updated to support a stream with no starting commit.

Refs T13634

Test Plan:
1. I set up a hosted Mercurial repository.
2. I removed the head commit from the on-disk repository state.
3. I attempted to load the repository page and saw an exception due to a missing commit.
4. I went to `/manage` for the repository and scheduled an update of the repository.
5. After an updated performed, I went to the repository main page and saw there was no exception and the history view properly did not have the commit I had removed.
6. I checked the phd logs and verified there were no exceptions related to the repository.
7. I ran the `./bin/repository mark-reachable` command on the Mercurial repository and it reported that it marked the commit as unreachable.
8. I pushed the same commit back upstream and verified that the commit was found and displayed in the history view of the repository page and `mark-unreachable` did not identify it as being unreachable.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T13634

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

+30 -12
+14 -4
src/applications/repository/daemon/PhabricatorMercurialGraphStream.php
··· 16 16 private $local = array(); 17 17 private $localParents = array(); 18 18 19 - public function __construct(PhabricatorRepository $repository, $commit) { 19 + public function __construct(PhabricatorRepository $repository, 20 + $start_commit = null) { 21 + 20 22 $this->repository = $repository; 21 23 24 + $command = 'log --template %s --rev %s'; 25 + $template = '{rev}\1{node}\1{date}\1{parents}\2'; 26 + if ($start_commit !== null) { 27 + $revset = hgsprintf('reverse(ancestors(%s))', $start_commit); 28 + } else { 29 + $revset = 'reverse(all())'; 30 + } 31 + 22 32 $future = $repository->getLocalCommandFuture( 23 - 'log --template %s --rev %s', 24 - '{rev}\1{node}\1{date}\1{parents}\2', 25 - hgsprintf('reverse(ancestors(%s))', $commit)); 33 + $command, 34 + $template, 35 + $revset); 26 36 27 37 $this->iterator = new LinesOfALargeExecFuture($future); 28 38 $this->iterator->setDelimiter("\2");
+7 -4
src/applications/repository/engine/PhabricatorRepositoryDiscoveryEngine.php
··· 780 780 } 781 781 782 782 private function markUnreachableCommits(PhabricatorRepository $repository) { 783 - // For now, this is only supported for Git. 784 - if (!$repository->isGit()) { 783 + if (!$repository->isGit() && !$repository->isHg()) { 785 784 return; 786 785 } 787 786 ··· 799 798 } 800 799 801 800 // We can share a single graph stream across all the checks we need to do. 802 - $stream = new PhabricatorGitGraphStream($repository); 801 + if ($repository->isGit()) { 802 + $stream = new PhabricatorGitGraphStream($repository); 803 + } else if ($repository->isHg()) { 804 + $stream = new PhabricatorMercurialGraphStream($repository); 805 + } 803 806 804 807 foreach ($old_refs as $old_ref) { 805 808 $identifier = $old_ref->getCommitIdentifier(); ··· 812 815 813 816 private function markUnreachableFrom( 814 817 PhabricatorRepository $repository, 815 - PhabricatorGitGraphStream $stream, 818 + PhabricatorRepositoryGraphStream $stream, 816 819 $identifier) { 817 820 818 821 $unreachable = array();
+9 -4
src/applications/repository/management/PhabricatorRepositoryManagementMarkReachableWorkflow.php
··· 48 48 } 49 49 50 50 private function markReachable(PhabricatorRepository $repository) { 51 - if (!$repository->isGit()) { 51 + if (!$repository->isGit() && !$repository->isHg()) { 52 52 throw new PhutilArgumentUsageException( 53 53 pht( 54 - 'Only Git repositories are supported, this repository ("%s") is '. 55 - 'not a Git repository.', 54 + 'Only Git and Mercurial repositories are supported, unable to '. 55 + 'operate on this repository ("%s").', 56 56 $repository->getDisplayName())); 57 57 } 58 58 ··· 65 65 66 66 $flag = PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE; 67 67 68 - $graph = new PhabricatorGitGraphStream($repository); 68 + if ($repository->isGit()) { 69 + $graph = new PhabricatorGitGraphStream($repository); 70 + } else if ($repository->isHg()) { 71 + $graph = new PhabricatorMercurialGraphStream($repository); 72 + } 73 + 69 74 foreach ($commits as $commit) { 70 75 $identifier = $commit->getCommitIdentifier(); 71 76