Differential D21515 Diff 51209 src/applications/repository/engine/PhabricatorRepositoryRefEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/engine/PhabricatorRepositoryRefEngine.php
| Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | foreach ($maps as $type => $refs) { | ||||
| $cursor_group = idx($cursor_groups, $type, array()); | $cursor_group = idx($cursor_groups, $type, array()); | ||||
| $this->updateCursors($cursor_group, $refs, $type, $all_closing_heads); | $this->updateCursors($cursor_group, $refs, $type, $all_closing_heads); | ||||
| } | } | ||||
| if ($this->permanentCommits) { | if ($this->permanentCommits) { | ||||
| $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(); | ||||
| $this->saveNewPositions(); | $this->saveNewPositions(); | ||||
| $this->deleteDeadPositions(); | $this->deleteDeadPositions(); | ||||
| foreach ($save_cursors as $cursor) { | foreach ($save_cursors as $cursor) { | ||||
| $cursor->save(); | $cursor->save(); | ||||
| } | } | ||||
| $repository->saveTransaction(); | $repository->saveTransaction(); | ||||
| } | } | ||||
| $branches = $maps[PhabricatorRepositoryRefCursor::TYPE_BRANCH]; | $branches = $maps[PhabricatorRepositoryRefCursor::TYPE_BRANCH]; | ||||
| if ($branches && $branches_may_close) { | if ($branches && $branches_may_close) { | ||||
| $this->updateBranchStates($repository, $branches); | $this->updateBranchStates($repository, $branches); | ||||
| } | } | ||||
| } | } | ||||
| 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; | ||||
| } | } | ||||
| $cursor->setIsPermanent((int)$is_permanent); | $cursor->setIsPermanent((int)$is_permanent); | ||||
| $results[] = $cursor; | $results[] = $cursor; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | final class PhabricatorRepositoryRefEngine | ||||
| } | } | ||||
| private function updateCursors( | private function updateCursors( | ||||
| array $cursors, | array $cursors, | ||||
| array $new_refs, | array $new_refs, | ||||
| $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. | ||||
| $cursors = mpull($cursors, null, 'getRefNameRaw'); | $cursors = mpull($cursors, null, 'getRefNameRaw'); | ||||
| // Group all the new ref values by their name. As above, these groups may | // Group all the new ref values by their name. As above, these groups may | ||||
| // have multiple members in Mercurial. | // have multiple members in Mercurial. | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | foreach ($ref_groups as $name => $refs) { | ||||
| $new_position = id(new PhabricatorRepositoryRefPosition()) | $new_position = id(new PhabricatorRepositoryRefPosition()) | ||||
| ->setCursorID($ref_cursor->getID()) | ->setCursorID($ref_cursor->getID()) | ||||
| ->setCommitIdentifier($identifier) | ->setCommitIdentifier($identifier) | ||||
| ->setIsClosed(0); | ->setIsClosed(0); | ||||
| $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 | ||||
| // this cursor was not previously permanent but has become permanent, | // this cursor was not previously permanent but has become permanent, | ||||
| // we need to publish all the ref positions. | // we need to publish all the ref positions. | ||||
| // This corresponds to users reconfiguring a branch to make it | // This corresponds to users reconfiguring a branch to make it | ||||
| // permanent without pushing any new commits to it. | // permanent without pushing any new commits to it. | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | foreach ($cursors as $name => $cursor) { | ||||
| $cursor->getRefType(), | $cursor->getRefType(), | ||||
| $cursor->getRefName())); | $cursor->getRefName())); | ||||
| $this->markPositionDead($position); | $this->markPositionDead($position); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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. | ||||
| */ | */ | ||||
| private function loadNewCommitIdentifiers( | private function loadNewCommitIdentifiers( | ||||
| $new_head, | $new_head, | ||||
| array $all_closing_heads) { | array $all_closing_heads) { | ||||
| ▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines | |||||