From 1459fb303769af0903733bfdf6d7129d82665814 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 7 Jun 2018 09:04:25 -0700 Subject: [PATCH] Make re-running `rebuild-identities` a bit faster and add a little progress information Summary: Ref T13151. Ref T12164. Two small tweaks: - If we aren't actually going to change anything, just skip the writes. This makes re-running/resuming a lot faster (~20x, locally). - Print when we touch a commit so there's some kind of visible status. This is just a small quality-of-life tweak that I wrote anyway while investigating T13152, and will make finishing off db024, db025 and db010 manually a little easier. Test Plan: - Set `authorIdentityPHID` + `committerIdentityPHID` to `NULL`. - Ran `rebuild-identities`, saw status information. - Ran `rebuild-identiites` again, saw it go faster with status information. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13151, T12164 Differential Revision: https://secure.phabricator.com/D19484 --- ...oryManagementRebuildIdentitiesWorkflow.php | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php index f7a0cf58f8..86cdcaa462 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementRebuildIdentitiesWorkflow.php @@ -44,27 +44,51 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow $iterator = new PhabricatorQueryIterator($query); foreach ($iterator as $commit) { + $needs_update = false; + $data = $commit->getCommitData(); $author_name = $data->getAuthorName(); + $author_identity = $this->getIdentityForCommit( - $commit, $author_name); + $commit, + $author_name); - $commit->setAuthorIdentityPHID($author_identity->getPHID()); - $data->setCommitDetail( - 'authorIdentityPHID', $author_identity->getPHID()); - - $committer_name = $data->getCommitDetail('committer', null); - if ($committer_name) { - $committer_identity = $this->getIdentityForCommit( - $commit, $committer_name); - - $commit->setCommitterIdentityPHID($committer_identity->getPHID()); - $data->setCommitDetail( - 'committerIdentityPHID', $committer_identity->getPHID()); + $author_phid = $commit->getAuthorIdentityPHID(); + $identity_phid = $author_identity->getPHID(); + if ($author_phid !== $identity_phid) { + $commit->setAuthorIdentityPHID($identity_phid); + $data->setCommitDetail('authorIdentityPHID', $identity_phid); + $needs_update = true; } - $commit->save(); - $data->save(); + $committer_name = $data->getCommitDetail('committer', null); + $committer_phid = $commit->getCommitterIdentityPHID(); + if (strlen($committer_name)) { + $committer_identity = $this->getIdentityForCommit( + $commit, + $committer_name); + $identity_phid = $committer_identity->getPHID(); + } else { + $identity_phid = null; + } + + if ($committer_phid !== $identity_phid) { + $commit->setCommitterIdentityPHID($identity_phid); + $data->setCommitDetail('committerIdentityPHID', $identity_phid); + $needs_update = true; + } + + if ($needs_update) { + $commit->save(); + $data->save(); + echo tsprintf( + "Rebuilt identities for %s.\n", + $commit->getDisplayName()); + } else { + echo tsprintf( + "No changes for %s.\n", + $commit->getDisplayName()); + } } }