Page MenuHomePhabricator

D16132.diff
No OneTemporary

D16132.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3263,6 +3263,7 @@
'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php',
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php',
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php',
+ 'PhabricatorRepositoryManagementMarkReachableWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkReachableWorkflow.php',
'PhabricatorRepositoryManagementMirrorWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php',
'PhabricatorRepositoryManagementMovePathsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php',
'PhabricatorRepositoryManagementParentsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php',
@@ -8052,6 +8053,7 @@
'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+ 'PhabricatorRepositoryManagementMarkReachableWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMirrorWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMovePathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementParentsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
diff --git a/src/applications/repository/daemon/PhabricatorGitGraphStream.php b/src/applications/repository/daemon/PhabricatorGitGraphStream.php
--- a/src/applications/repository/daemon/PhabricatorGitGraphStream.php
+++ b/src/applications/repository/daemon/PhabricatorGitGraphStream.php
@@ -11,14 +11,20 @@
public function __construct(
PhabricatorRepository $repository,
- $start_commit) {
+ $start_commit = null) {
$this->repository = $repository;
- $future = $repository->getLocalCommandFuture(
- 'log --format=%s %s --',
- '%H%x01%P%x01%ct',
- $start_commit);
+ if ($start_commit !== null) {
+ $future = $repository->getLocalCommandFuture(
+ 'log --format=%s %s --',
+ '%H%x01%P%x01%ct',
+ $start_commit);
+ } else {
+ $future = $repository->getLocalCommandFuture(
+ 'log --format=%s --all --',
+ '%H%x01%P%x01%ct');
+ }
$this->iterator = new LinesOfALargeExecFuture($future);
$this->iterator->setDelimiter("\n");
diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementMarkReachableWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementMarkReachableWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/management/PhabricatorRepositoryManagementMarkReachableWorkflow.php
@@ -0,0 +1,103 @@
+<?php
+
+final class PhabricatorRepositoryManagementMarkReachableWorkflow
+ extends PhabricatorRepositoryManagementWorkflow {
+
+ private $untouchedCount = 0;
+
+ protected function didConstruct() {
+ $this
+ ->setName('mark-reachable')
+ ->setExamples('**mark-reachable** [__options__] __repository__ ...')
+ ->setSynopsis(
+ pht(
+ 'Rebuild "unreachable" flags for commits in __repository__.'))
+ ->setArguments(
+ array(
+ array(
+ 'name' => 'repos',
+ 'wildcard' => true,
+ ),
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $repos = $this->loadRepositories($args, 'repos');
+ if (!$repos) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Specify one or more repositories to correct reachability status '.
+ 'for.'));
+ }
+
+ foreach ($repos as $repo) {
+ $this->markReachable($repo);
+ }
+
+ echo tsprintf(
+ "%s\n",
+ pht(
+ 'Examined %s commits already in the correct state.',
+ new PhutilNumber($this->untouchedCount)));
+
+ echo tsprintf(
+ "%s\n",
+ pht('Done.'));
+
+ return 0;
+ }
+
+ private function markReachable(PhabricatorRepository $repository) {
+ if (!$repository->isGit()) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Only Git repositories are supported, this repository ("%s") is '.
+ 'not a Git repository.',
+ $repository->getDisplayName()));
+ }
+
+ $viewer = $this->getViewer();
+
+ $commits = id(new DiffusionCommitQuery())
+ ->setViewer($viewer)
+ ->withRepository($repository)
+ ->execute();
+
+ $flag = PhabricatorRepositoryCommit::IMPORTED_UNREACHABLE;
+
+ $graph = new PhabricatorGitGraphStream($repository);
+ foreach ($commits as $commit) {
+ $identifier = $commit->getCommitIdentifier();
+
+ try {
+ $graph->getCommitDate($identifier);
+ $unreachable = false;
+ } catch (Exception $ex) {
+ $unreachable = true;
+ }
+
+ // The commit has proper reachability, so do nothing.
+ if ($commit->isUnreachable() === $unreachable) {
+ $this->untouchedCount++;
+ continue;
+ }
+
+ if ($unreachable) {
+ echo tsprintf(
+ "%s: %s\n",
+ $commit->getMonogram(),
+ pht('Marking commit unreachable.'));
+
+ $commit->writeImportStatusFlag($flag);
+ } else {
+ echo tsprintf(
+ "%s: %s\n",
+ $commit->getMonogram(),
+ pht('Marking commit reachable.'));
+
+ $commit->clearImportStatusFlag($flag);
+ }
+ }
+ }
+
+}
diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php
--- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php
@@ -64,13 +64,38 @@
}
public function writeImportStatusFlag($flag) {
- queryfx(
- $this->establishConnection('w'),
- 'UPDATE %T SET importStatus = (importStatus | %d) WHERE id = %d',
- $this->getTableName(),
- $flag,
- $this->getID());
- $this->setImportStatus($this->getImportStatus() | $flag);
+ return $this->adjustImportStatusFlag($flag, true);
+ }
+
+ public function clearImportStatusFlag($flag) {
+ return $this->adjustImportStatusFlag($flag, false);
+ }
+
+ private function adjustImportStatusFlag($flag, $set) {
+ $conn_w = $this->establishConnection('w');
+ $table_name = $this->getTableName();
+ $id = $this->getID();
+
+ if ($set) {
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET importStatus = (importStatus | %d) WHERE id = %d',
+ $table_name,
+ $flag,
+ $id);
+
+ $this->setImportStatus($this->getImportStatus() | $flag);
+ } else {
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET importStatus = (importStatus & ~%d) WHERE id = %d',
+ $table_name,
+ $flag,
+ $id);
+
+ $this->setImportStatus($this->getImportStatus() & ~$flag);
+ }
+
return $this;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 30, 6:06 AM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6743736
Default Alt Text
D16132.diff (7 KB)

Event Timeline