mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Add a --repair flag to "bin/repository discover"
Summary: If a repository is missing commits because they mysteriously vanished, there's no reasonable way to get them back right now. Provide a way to ignore the state in the database and rediscover the entire repository unconditionally. We don't queue any reparses or anything, but when I move reparse into this script we can hook things up or something. This generally shouldn't be too important anyway. Test Plan: Ran `repository discover --repair` on Phabricator. Reviewers: jungejason, nh, vrana Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D2850
This commit is contained in:
parent
13d96e6377
commit
ca31e3e84b
2 changed files with 26 additions and 1 deletions
|
@ -46,6 +46,12 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
extends PhabricatorDaemon {
|
extends PhabricatorDaemon {
|
||||||
|
|
||||||
private $commitCache = array();
|
private $commitCache = array();
|
||||||
|
private $repair;
|
||||||
|
|
||||||
|
public function setRepair($repair) {
|
||||||
|
$this->repair = $repair;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Pulling Repositories )----------------------------------------------- */
|
/* -( Pulling Repositories )----------------------------------------------- */
|
||||||
|
@ -238,6 +244,13 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->repair) {
|
||||||
|
// In repair mode, rediscover the entire repository, ignoring the
|
||||||
|
// database state. We can hit the local cache above, but if we miss it
|
||||||
|
// stop the script from going to the database cache.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
||||||
'repositoryID = %s AND commitIdentifier = %s',
|
'repositoryID = %s AND commitIdentifier = %s',
|
||||||
$repository->getID(),
|
$repository->getID(),
|
||||||
|
@ -316,6 +329,12 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
$commit->getID(),
|
$commit->getID(),
|
||||||
$epoch);
|
$epoch);
|
||||||
|
|
||||||
|
if ($this->repair) {
|
||||||
|
// Normally, the query should throw a duplicate key exception. If we
|
||||||
|
// reach this in repair mode, we've actually performed a repair.
|
||||||
|
$this->log("Repaired commit '%s'.", $commit_identifier);
|
||||||
|
}
|
||||||
|
|
||||||
$this->setCache($repository, $commit_identifier);
|
$this->setCache($repository, $commit_identifier);
|
||||||
} catch (AphrontQueryDuplicateKeyException $ex) {
|
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||||
// Ignore. This can happen because we discover the same new commit
|
// Ignore. This can happen because we discover the same new commit
|
||||||
|
|
|
@ -22,7 +22,7 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
|
||||||
public function didConstruct() {
|
public function didConstruct() {
|
||||||
$this
|
$this
|
||||||
->setName('discover')
|
->setName('discover')
|
||||||
->setExamples('**discover** __repository__ ...')
|
->setExamples('**discover** [__options__] __repository__ ...')
|
||||||
->setSynopsis('Discover __repository__, named by callsign or PHID.')
|
->setSynopsis('Discover __repository__, named by callsign or PHID.')
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
|
@ -30,6 +30,11 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
|
||||||
'name' => 'verbose',
|
'name' => 'verbose',
|
||||||
'help' => 'Show additional debugging information.',
|
'help' => 'Show additional debugging information.',
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'repair',
|
||||||
|
'help' => 'Repair a repository with gaps in commit '.
|
||||||
|
'history.',
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'repos',
|
'name' => 'repos',
|
||||||
'wildcard' => true,
|
'wildcard' => true,
|
||||||
|
@ -52,6 +57,7 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
|
||||||
|
|
||||||
$daemon = new PhabricatorRepositoryPullLocalDaemon(array());
|
$daemon = new PhabricatorRepositoryPullLocalDaemon(array());
|
||||||
$daemon->setVerbose($args->getArg('verbose'));
|
$daemon->setVerbose($args->getArg('verbose'));
|
||||||
|
$daemon->setRepair($args->getArg('repair'));
|
||||||
$daemon->discoverRepository($repo);
|
$daemon->discoverRepository($repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue