1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 14:51:06 +01:00

Separate "shouldPublishRef()" from "isPermanentRef()" and set "IMPORTED_PERMANENT" more narrowly

Summary:
Ref T13591. Currently, the "IMPORTED_PERMANENT" flag (previously "IMPORTED_CLOSEABLE", until D21514) flag is set by using the result of "shouldPublishRef()".

This method returns the wrong value for the flag when there is a repository-level reason not to publish the ref (most commonly, because the repository is currently importing).

Although it's correct that commits should not be published in an importing repository, that's already handled in the "PublishWorker" by testing "shouldPublishCommit()". The "IMPORTED_PERMANENT" flag should only reflect whether a commit is reachable from a permanent ref or not.

  - Move the relevant logic to a new method in Publisher.
  - Fill "IMPORTED_PERMANENT" narrowly from "isPermanentRef()", rather than broadly from "shouldPublishRef()".
  - Deduplicate some logic in "PhabricatorRepositoryRefEngine" which has the same intent as the logic in the Publisher.

Test Plan:
  - Ran discovery on a new repository, saw permanent commits marked as permanent from the beginning.
  - See later changes in this patch series for additional testing.

Maniphest Tasks: T13591

Differential Revision: https://secure.phabricator.com/D21515
This commit is contained in:
epriestley 2021-01-22 13:53:52 -08:00
parent 2d0e7c37e1
commit 6716d4f6ae
4 changed files with 49 additions and 32 deletions

View file

@ -189,7 +189,7 @@ final class PhabricatorRepositoryDiscoveryEngine
$head_refs = $this->discoverStreamAncestry( $head_refs = $this->discoverStreamAncestry(
new PhabricatorGitGraphStream($repository, $commit), new PhabricatorGitGraphStream($repository, $commit),
$commit, $commit,
$publisher->shouldPublishRef($ref)); $publisher->isPermanentRef($ref));
$this->didDiscoverRefs($head_refs); $this->didDiscoverRefs($head_refs);
@ -507,9 +507,9 @@ final class PhabricatorRepositoryDiscoveryEngine
} }
/** /**
* Sort branches so we process permanent branches first. This makes the * Sort refs so we process permanent refs first. This makes the whole import
* whole import process a little cheaper, since we can publish these commits * process a little cheaper, since we can publish these commits the first
* the first time through rather than catching them in the refs step. * time through rather than catching them in the refs step.
* *
* @task internal * @task internal
* *
@ -523,7 +523,7 @@ final class PhabricatorRepositoryDiscoveryEngine
$head_refs = array(); $head_refs = array();
$tail_refs = array(); $tail_refs = array();
foreach ($refs as $ref) { foreach ($refs as $ref) {
if ($publisher->shouldPublishRef($ref)) { if ($publisher->isPermanentRef($ref)) {
$head_refs[] = $ref; $head_refs[] = $ref;
} else { } else {
$tail_refs[] = $ref; $tail_refs[] = $ref;

View file

@ -100,7 +100,7 @@ final class PhabricatorRepositoryRefEngine
$this->setPermanentFlagOnCommits($this->permanentCommits); $this->setPermanentFlagOnCommits($this->permanentCommits);
} }
$save_cursors = $this->getCursorsForUpdate($all_cursors); $save_cursors = $this->getCursorsForUpdate($repository, $all_cursors);
if ($this->newPositions || $this->deadPositions || $save_cursors) { if ($this->newPositions || $this->deadPositions || $save_cursors) {
$repository->openTransaction(); $repository->openTransaction();
@ -121,17 +121,19 @@ final class PhabricatorRepositoryRefEngine
} }
} }
private function getCursorsForUpdate(array $cursors) { private function getCursorsForUpdate(
PhabricatorRepository $repository,
array $cursors) {
assert_instances_of($cursors, 'PhabricatorRepositoryRefCursor'); assert_instances_of($cursors, 'PhabricatorRepositoryRefCursor');
$publisher = $repository->newPublisher();
$results = array(); $results = array();
foreach ($cursors as $cursor) { foreach ($cursors as $cursor) {
$ref_type = $cursor->getRefType(); $diffusion_ref = $cursor->newDiffusionRepositoryRef();
$ref_name = $cursor->getRefName();
$is_permanent = $this->isPermanentRef($ref_type, $ref_name);
$is_permanent = $publisher->isPermanentRef($diffusion_ref);
if ($is_permanent == $cursor->getIsPermanent()) { if ($is_permanent == $cursor->getIsPermanent()) {
continue; continue;
} }
@ -259,6 +261,7 @@ final class PhabricatorRepositoryRefEngine
$ref_type, $ref_type,
array $all_closing_heads) { array $all_closing_heads) {
$repository = $this->getRepository(); $repository = $this->getRepository();
$publisher = $repository->newPublisher();
// NOTE: Mercurial branches may have multiple branch heads; this logic // NOTE: Mercurial branches may have multiple branch heads; this logic
// is complex primarily to account for that. // is complex primarily to account for that.
@ -341,7 +344,8 @@ final class PhabricatorRepositoryRefEngine
$this->markPositionNew($new_position); $this->markPositionNew($new_position);
} }
if ($this->isPermanentRef($ref_type, $name)) { $diffusion_ref = head($refs)->newDiffusionRepositoryRef();
if ($publisher->isPermanentRef($diffusion_ref)) {
// See T13284. If this cursor was already marked as permanent, we // See T13284. If this cursor was already marked as permanent, we
// only need to publish the newly created ref positions. However, if // only need to publish the newly created ref positions. However, if
@ -404,14 +408,6 @@ final class PhabricatorRepositoryRefEngine
} }
} }
private function isPermanentRef($ref_type, $ref_name) {
if ($ref_type !== PhabricatorRepositoryRefCursor::TYPE_BRANCH) {
return false;
}
return $this->getRepository()->isBranchPermanentRef($ref_name);
}
/** /**
* Find all ancestors of a new closing branch head which are not ancestors * Find all ancestors of a new closing branch head which are not ancestors
* of any old closing branch head. * of any old closing branch head.

View file

@ -38,6 +38,10 @@ final class PhabricatorRepositoryPublisher
return !$this->getCommitHoldReasons($commit); return !$this->getCommitHoldReasons($commit);
} }
public function isPermanentRef(DiffusionRepositoryRef $ref) {
return !$this->getRefImpermanentReasons($ref);
}
/* -( Hold Reasons )------------------------------------------------------- */ /* -( Hold Reasons )------------------------------------------------------- */
public function getRepositoryHoldReasons() { public function getRepositoryHoldReasons() {
@ -59,18 +63,8 @@ final class PhabricatorRepositoryPublisher
$repository = $this->getRepository(); $repository = $this->getRepository();
$reasons = $this->getRepositoryHoldReasons(); $reasons = $this->getRepositoryHoldReasons();
if (!$ref->isBranch()) { foreach ($this->getRefImpermanentReasons($ref) as $reason) {
$reasons[] = self::HOLD_REF_NOT_BRANCH; $reasons[] = $reason;
} else {
$branch_name = $ref->getShortName();
if (!$repository->shouldTrackBranch($branch_name)) {
$reasons[] = self::HOLD_UNTRACKED;
}
if (!$repository->isBranchPermanentRef($branch_name)) {
$reasons[] = self::HOLD_NOT_PERMANENT_REF;
}
} }
return $reasons; return $reasons;
@ -89,4 +83,25 @@ final class PhabricatorRepositoryPublisher
return $reasons; return $reasons;
} }
public function getRefImpermanentReasons(DiffusionRepositoryRef $ref) {
$repository = $this->getRepository();
$reasons = array();
if (!$ref->isBranch()) {
$reasons[] = self::HOLD_REF_NOT_BRANCH;
} else {
$branch_name = $ref->getShortName();
if (!$repository->shouldTrackBranch($branch_name)) {
$reasons[] = self::HOLD_UNTRACKED;
}
if (!$repository->isBranchPermanentRef($branch_name)) {
$reasons[] = self::HOLD_NOT_PERMANENT_REF;
}
}
return $reasons;
}
} }

View file

@ -88,6 +88,12 @@ final class PhabricatorRepositoryRefCursor
return mpull($this->getPositions(), 'getCommitIdentifier'); return mpull($this->getPositions(), 'getCommitIdentifier');
} }
public function newDiffusionRepositoryRef() {
return id(new DiffusionRepositoryRef())
->setRefType($this->getRefType())
->setShortName($this->getRefName());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */