diff --git a/src/applications/diffusion/identity/DiffusionRepositoryIdentityEngine.php b/src/applications/diffusion/identity/DiffusionRepositoryIdentityEngine.php --- a/src/applications/diffusion/identity/DiffusionRepositoryIdentityEngine.php +++ b/src/applications/diffusion/identity/DiffusionRepositoryIdentityEngine.php @@ -5,6 +5,7 @@ private $viewer; private $sourcePHID; + private $dryRun; public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; @@ -28,6 +29,15 @@ return $this->sourcePHID; } + public function setDryRun($dry_run) { + $this->dryRun = $dry_run; + return $this; + } + + public function getDryRun() { + return $this->dryRun; + } + public function newResolvedIdentity($raw_identity) { $identity = $this->loadRawIdentity($raw_identity); @@ -88,9 +98,13 @@ $resolved_phid = $this->resolveIdentity($identity); - $identity - ->setAutomaticGuessedUserPHID($resolved_phid) - ->save(); + $identity->setAutomaticGuessedUserPHID($resolved_phid); + + if ($this->getDryRun()) { + $identity->makeEphemeral(); + } else { + $identity->save(); + } return $identity; } diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php --- a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php @@ -4,6 +4,8 @@ extends PhabricatorRepositoryManagementWorkflow { private $identityCache = array(); + private $phidCache = array(); + private $dryRun; protected function didConstruct() { $this @@ -51,6 +53,10 @@ 'repeat' => true, 'help' => pht('Rebuild identities for a raw commit string.'), ), + array( + 'name' => 'dry-run', + 'help' => pht('Show changes, but do not make any changes.'), + ), )); } @@ -59,7 +65,6 @@ $rebuilt_anything = false; - $all_repositories = $args->getArg('all-repositories'); $repositories = $args->getArg('repository'); @@ -81,6 +86,15 @@ 'compatible.')); } + $dry_run = $args->getArg('dry-run'); + $this->dryRun = $dry_run; + + if ($this->dryRun) { + $this->logWarn( + pht('DRY RUN'), + pht('This is a dry run, so no changes will be written.')); + } + if ($all_repositories || $repositories) { $rebuilt_anything = true; @@ -245,10 +259,7 @@ $raw_identity) { if (!isset($this->identityCache[$raw_identity])) { - $viewer = $this->getViewer(); - - $identity = id(new DiffusionRepositoryIdentityEngine()) - ->setViewer($viewer) + $identity = $this->newIdentityEngine() ->setSourcePHID($commit->getPHID()) ->newResolvedIdentity($raw_identity); @@ -317,7 +328,7 @@ } private function rebuildIdentities($identities) { - $viewer = $this->getViewer(); + $dry_run = $this->dryRun; foreach ($identities as $identity) { $raw_identity = $identity->getIdentityName(); @@ -340,8 +351,7 @@ $old_auto = $identity->getAutomaticGuessedUserPHID(); $old_assign = $identity->getManuallySetUserPHID(); - $identity = id(new DiffusionRepositoryIdentityEngine()) - ->setViewer($viewer) + $identity = $this->newIdentityEngine() ->newUpdatedIdentity($identity); $this->identityCache[$raw_identity] = $identity; @@ -358,20 +368,38 @@ pht('No changes to identity.')); } else { if (!$same_auto) { - $this->logWarn( - pht('AUTOMATIC PHID'), - pht( - 'Automatic user updated from "%s" to "%s".', - $this->renderPHID($old_auto), - $this->renderPHID($new_auto))); + if ($dry_run) { + $this->logWarn( + pht('DETECTED PHID'), + pht( + '(Dry Run) Would update detected user from "%s" to "%s".', + $this->renderPHID($old_auto), + $this->renderPHID($new_auto))); + } else { + $this->logWarn( + pht('DETECTED PHID'), + pht( + 'Detected user updated from "%s" to "%s".', + $this->renderPHID($old_auto), + $this->renderPHID($new_auto))); + } } if (!$same_assign) { - $this->logWarn( - pht('ASSIGNED PHID'), - pht( - 'Assigned user updated from "%s" to "%s".', - $this->renderPHID($old_assign), - $this->renderPHID($new_assign))); + if ($dry_run) { + $this->logWarn( + pht('ASSIGNED PHID'), + pht( + '(Dry Run) Would update assigned user from "%s" to "%s".', + $this->renderPHID($old_assign), + $this->renderPHID($new_assign))); + } else { + $this->logWarn( + pht('ASSIGNED PHID'), + pht( + 'Assigned user updated from "%s" to "%s".', + $this->renderPHID($old_assign), + $this->renderPHID($new_assign))); + } } } } @@ -380,9 +408,26 @@ private function renderPHID($phid) { if ($phid == null) { return pht('NULL'); - } else { - return $phid; } + + if (!isset($this->phidCache[$phid])) { + $viewer = $this->getViewer(); + $handles = $viewer->loadHandles(array($phid)); + $this->phidCache[$phid] = pht( + '%s <%s>', + $handles[$phid]->getFullName(), + $phid); + } + + return $this->phidCache[$phid]; + } + + private function newIdentityEngine() { + $viewer = $this->getViewer(); + + return id(new DiffusionRepositoryIdentityEngine()) + ->setViewer($viewer) + ->setDryRun($this->dryRun); } }