wasCreatedAfter() 공개 메소드

Returns true if $commitHash was created after the $afterWhichCommitHash commit ("after" meaning that $commitHash is more recent commit, a child of $afterWhat). Same two commits return false.
public wasCreatedAfter ( $commitHash, $afterWhichCommitHash ) : boolean
$commitHash
$afterWhichCommitHash
리턴 boolean
예제 #1
0
 /**
  * @param WP_REST_Request $request
  * @return WP_REST_Response|\WP_Error
  */
 public function getCommits(WP_REST_Request $request)
 {
     $gitLogPaginator = new GitLogPaginator($this->gitRepository);
     $gitLogPaginator->setCommitsPerPage(25);
     $page = intval($request['page']);
     $commits = $gitLogPaginator->getPage($page);
     if (empty($commits)) {
         return new \WP_Error('notice', 'No more commits to show.', array('status' => 403));
     }
     $preActivationHash = trim(file_get_contents(VERSIONPRESS_ACTIVATION_FILE));
     if (empty($preActivationHash)) {
         $initialCommitHash = $this->gitRepository->getInitialCommit()->getHash();
     } else {
         $initialCommitHash = $this->gitRepository->getChildCommit($preActivationHash);
     }
     $isChildOfInitialCommit = $this->gitRepository->wasCreatedAfter($commits[0]->getHash(), $initialCommitHash);
     $isFirstCommit = $page === 0;
     $result = array();
     foreach ($commits as $commit) {
         $isChildOfInitialCommit = $isChildOfInitialCommit && $commit->getHash() !== $initialCommitHash;
         $canUndoCommit = $isChildOfInitialCommit && !$commit->isMerge();
         $canRollbackToThisCommit = !$isFirstCommit && ($isChildOfInitialCommit || $commit->getHash() === $initialCommitHash);
         $changeInfo = ChangeInfoMatcher::buildChangeInfo($commit->getMessage());
         $isEnabled = $isChildOfInitialCommit || $canRollbackToThisCommit || $commit->getHash() === $initialCommitHash;
         $fileChanges = $this->getFileChanges($commit);
         $changeInfoList = $changeInfo instanceof ChangeInfoEnvelope ? $changeInfo->getChangeInfoList() : array();
         $result[] = array("hash" => $commit->getHash(), "date" => $commit->getDate()->format('c'), "message" => $changeInfo->getChangeDescription(), "canUndo" => $canUndoCommit, "canRollback" => $canRollbackToThisCommit, "isEnabled" => $isEnabled, "isInitial" => $commit->getHash() === $initialCommitHash, "isMerge" => $commit->isMerge(), "changes" => array_merge($this->convertChangeInfoList($changeInfoList), $fileChanges));
         $isFirstCommit = false;
     }
     return new WP_REST_Response(array('pages' => $gitLogPaginator->getPrettySteps($page), 'commits' => $result));
 }
예제 #2
0
 private function revert($commits, $method)
 {
     if (!$this->canRevert()) {
         return RevertStatus::NOT_CLEAN_WORKING_DIRECTORY;
     }
     vp_commit_all_frequently_written_entities();
     uasort($commits, function ($a, $b) {
         return $this->repository->wasCreatedAfter($b, $a);
     });
     $modifiedFiles = [];
     $vpIdsInModifiedFiles = [];
     foreach ($commits as $commitHash) {
         $commitHashForDiff = $method === "undo" ? sprintf("%s~1..%s", $commitHash, $commitHash) : $commitHash;
         $modifiedFiles = array_merge($modifiedFiles, $this->repository->getModifiedFiles($commitHashForDiff));
         $modifiedFiles = array_unique($modifiedFiles, SORT_REGULAR);
         $vpIdsInModifiedFiles = array_merge($vpIdsInModifiedFiles, $this->getAllVpIdsFromModifiedFiles($modifiedFiles));
         $vpIdsInModifiedFiles = array_unique($vpIdsInModifiedFiles, SORT_REGULAR);
         if ($method === "undo") {
             $status = $this->revertOneCommit($commitHash);
         } else {
             $status = $this->revertToCommit($commitHash);
         }
         if ($status !== RevertStatus::OK) {
             return $status;
         }
         vp_force_action('versionpress', $method, $commitHash, [], [["type" => "path", "path" => "*"]]);
     }
     if (!$this->repository->willCommit()) {
         return RevertStatus::NOTHING_TO_COMMIT;
     }
     $affectedPosts = $this->getAffectedPosts($modifiedFiles);
     $this->updateChangeDateForPosts($affectedPosts);
     $this->committer->commit();
     $vpIdsInModifiedFiles = array_merge($vpIdsInModifiedFiles, $this->getAllVpIdsFromModifiedFiles($modifiedFiles));
     $vpIdsInModifiedFiles = array_unique($vpIdsInModifiedFiles, SORT_REGULAR);
     $this->synchronizationProcess->synchronize($vpIdsInModifiedFiles);
     do_action('vp_revert', $modifiedFiles);
     return RevertStatus::OK;
 }
예제 #3
0
 /**
  * @param WP_REST_Request $request
  * @return WP_REST_Response|WP_Error
  */
 public function rollbackToCommit(WP_REST_Request $request)
 {
     $commitHash = $request['commit'];
     $initialCommitHash = $this->getInitialCommitHash();
     $log = $this->gitRepository->log($commitHash);
     if (!preg_match('/^[0-9a-f]+$/', $commitHash) || count($log) === 0) {
         return new WP_Error('error', 'Invalid commit hash', ['status' => 404]);
     }
     if (!$this->gitRepository->wasCreatedAfter($commitHash, $initialCommitHash) && $log[0]->getHash() !== $initialCommitHash) {
         return new WP_Error('error', 'Cannot roll back before initial commit', ['status' => 403]);
     }
     if ($log[0]->getHash() === $this->gitRepository->getLastCommitHash()) {
         return new WP_Error('error', 'Nothing to commit. Current state is the same as the one you want rollback to.', ['status' => 403]);
     }
     return $this->revertCommits('rollback', [$commitHash]);
 }