Page MenuHomePhabricator

D13621.diff
No OneTemporary

D13621.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
@@ -2572,10 +2572,12 @@
'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 @@
'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementEditWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementImportingWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+ 'PhabricatorRepositoryManagementListPathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementLookupUsersWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMarkImportedWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementMirrorWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+ 'PhabricatorRepositoryManagementMovePathsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementParentsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
'PhabricatorRepositoryManagementRefsWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementListPathsWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementListPathsWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/management/PhabricatorRepositoryManagementListPathsWorkflow.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/management/PhabricatorRepositoryManagementMovePathsWorkflow.php
@@ -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;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 21, 4:37 AM (19 h, 59 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6714512
Default Alt Text
D13621.diff (8 KB)

Event Timeline