mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Add repository list-paths
and repository move-paths
Summary: Ref T7149. These formalize the local path adjustment step for cluster imports, rather than relying on an ad-hoc script. Test Plan: Used `list-paths` and `move-paths` to list and move repositories. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7149 Differential Revision: https://secure.phabricator.com/D13621
This commit is contained in:
parent
ef556090f8
commit
fc72b000f0
3 changed files with 200 additions and 0 deletions
|
@ -2572,10 +2572,12 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryManagementDiscoverWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php',
|
||||
'PhabricatorRepositoryManagementEditWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementEditWorkflow.php',
|
||||
'PhabricatorRepositoryManagementImportingWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementImportingWorkflow.php',
|
||||
'PhabricatorRepositoryManagementListPathsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListPathsWorkflow.php',
|
||||
'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php',
|
||||
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php',
|
||||
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMarkImportedWorkflow.php',
|
||||
'PhabricatorRepositoryManagementMirrorWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMirrorWorkflow.php',
|
||||
'PhabricatorRepositoryManagementMovePathsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php',
|
||||
'PhabricatorRepositoryManagementParentsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementParentsWorkflow.php',
|
||||
'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php',
|
||||
'PhabricatorRepositoryManagementRefsWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementRefsWorkflow.php',
|
||||
|
@ -6438,10 +6440,12 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementEditWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementImportingWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementListPathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementMirrorWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementMovePathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementParentsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
'PhabricatorRepositoryManagementRefsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRepositoryManagementListPathsWorkflow
|
||||
extends PhabricatorRepositoryManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('list-paths')
|
||||
->setSynopsis(pht('List repository local paths.'))
|
||||
->setArguments(array());
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->execute();
|
||||
if (!$repos) {
|
||||
$console->writeErr("%s\n", pht('There are no repositories.'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
$table = id(new PhutilConsoleTable())
|
||||
->addColumn(
|
||||
'monogram',
|
||||
array(
|
||||
'title' => pht('Repository'),
|
||||
))
|
||||
->addColumn(
|
||||
'path',
|
||||
array(
|
||||
'title' => pht('Path'),
|
||||
))
|
||||
->setBorders(true);
|
||||
|
||||
foreach ($repos as $repo) {
|
||||
$table->addRow(
|
||||
array(
|
||||
'monogram' => $repo->getMonogram(),
|
||||
'path' => $repo->getLocalPath(),
|
||||
));
|
||||
}
|
||||
|
||||
$table->draw();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRepositoryManagementMovePathsWorkflow
|
||||
extends PhabricatorRepositoryManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('move-paths')
|
||||
->setSynopsis(pht('Move repository local paths.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'from',
|
||||
'param' => 'prefix',
|
||||
'help' => pht('Move paths with this prefix.'),
|
||||
),
|
||||
array(
|
||||
'name' => 'to',
|
||||
'param' => 'prefix',
|
||||
'help' => pht('Replace matching prefixes with this string.'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->execute();
|
||||
if (!$repos) {
|
||||
$console->writeErr("%s\n", pht('There are no repositories.'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
$from = $args->getArg('from');
|
||||
if (!strlen($from)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'You must specify a path prefix to move from with --from.'));
|
||||
}
|
||||
|
||||
$to = $args->getArg('to');
|
||||
if (!strlen($to)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'You must specify a path prefix to move to with --to.'));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
|
||||
$any_changes = false;
|
||||
foreach ($repos as $repo) {
|
||||
$src = $repo->getLocalPath();
|
||||
|
||||
$row = array(
|
||||
'repository' => $repo,
|
||||
'move' => false,
|
||||
'monogram' => $repo->getMonogram(),
|
||||
'src' => $src,
|
||||
'dst' => '',
|
||||
);
|
||||
|
||||
if (strncmp($src, $from, strlen($from))) {
|
||||
$row['action'] = pht('Ignore');
|
||||
} else {
|
||||
$dst = $to.substr($src, strlen($from));
|
||||
|
||||
$row['action'] = phutil_console_format('**%s**', pht('Move'));
|
||||
$row['dst'] = $dst;
|
||||
$row['move'] = true;
|
||||
$any_changes = true;
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$table = id(new PhutilConsoleTable())
|
||||
->addColumn(
|
||||
'action',
|
||||
array(
|
||||
'title' => pht('Action'),
|
||||
))
|
||||
->addColumn(
|
||||
'monogram',
|
||||
array(
|
||||
'title' => pht('Repository'),
|
||||
))
|
||||
->addColumn(
|
||||
'src',
|
||||
array(
|
||||
'title' => pht('Src'),
|
||||
))
|
||||
->addColumn(
|
||||
'dst',
|
||||
array(
|
||||
'title' => pht('dst'),
|
||||
))
|
||||
->setBorders(true);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$display = array_select_keys(
|
||||
$row,
|
||||
array(
|
||||
'action',
|
||||
'monogram',
|
||||
'src',
|
||||
'dst',
|
||||
));
|
||||
$table->addRow($display);
|
||||
}
|
||||
|
||||
$table->draw();
|
||||
|
||||
if (!$any_changes) {
|
||||
$console->writeOut(pht('No matching repositories.')."\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$prompt = pht('Apply these changes?');
|
||||
if (!phutil_console_confirm($prompt)) {
|
||||
throw new Exception(pht('Declining to apply changes.'));
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (empty($row['move'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$repo = $row['repository'];
|
||||
$details = $repo->getDetails();
|
||||
$details['local-path'] = $row['dst'];
|
||||
|
||||
queryfx(
|
||||
$repo->establishConnection('w'),
|
||||
'UPDATE %T SET details = %s WHERE id = %d',
|
||||
$repo->getTableName(),
|
||||
phutil_json_encode($details),
|
||||
$repo->getID());
|
||||
}
|
||||
|
||||
$console->writeOut(pht('Applied changes.')."\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue