1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Track path moves in Owner's packages

Summary:
Currently, if a package is moved from one location to another those package paths become stale in Owner's packages.
This diff fixes that by tracking the path moves in diffusion commit messages and updating the owners package paths accordingly.

Test Plan:
Tested the script by running the reparse.php script on the following test commits:
https://phabricator.fb.com/rPHGITd7271a2de212e0b2de33d485b2ff806e75f73d36
https://phabricator.fb.com/rPHGIT0192fb41e7bd3e0faeeb14facdc7f7bea1b716d0

on the following packages:
https://phabricator.fb.com/owners/package/1167/
https://phabricator.fb.com/owners/package/1168/

Reviewers: nh

Reviewed By: nh

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D3985
This commit is contained in:
Suman Karumuri 2012-11-19 12:53:41 -08:00
parent fd5beffb99
commit 2852b4f5d3
4 changed files with 113 additions and 1 deletions

View file

@ -925,6 +925,7 @@ phutil_register_library_map(array(
'PhabricatorOwnersListController' => 'applications/owners/controller/PhabricatorOwnersListController.php',
'PhabricatorOwnersOwner' => 'applications/owners/storage/PhabricatorOwnersOwner.php',
'PhabricatorOwnersPackage' => 'applications/owners/storage/PhabricatorOwnersPackage.php',
'PhabricatorOwnersPackagePathValidator' => 'applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php',
'PhabricatorOwnersPackageQuery' => 'applications/owners/query/PhabricatorOwnersPackageQuery.php',
'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php',
'PhabricatorPHID' => 'applications/phid/storage/PhabricatorPHID.php',

View file

@ -137,5 +137,4 @@ final class PhabricatorRepositoryCommit extends PhabricatorRepositoryDAO {
return $this->setAuditStatus($status);
}
}

View file

@ -0,0 +1,111 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorOwnersPackagePathValidator {
/*
* If a file/directory was moved the paths in owners package become stale.
* This method updates the stale paths in the owners packages to their new
* paths.
*/
public static function updateOwnersPackagePaths(
PhabricatorRepositoryCommit $commit) {
$changes = self::loadDiffusionChangesForCommit($commit);
if (!$changes) {
return;
}
$repository =
id(new PhabricatorRepository())->load($commit->getRepositoryID());
$move_map = array();
foreach ($changes as $change) {
if ($change->getChangeType() == DifferentialChangeType::TYPE_MOVE_HERE) {
$from_path = "/".$change->getTargetPath();
$to_path = "/".$change->getPath();
if ($change->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
$to_path = $to_path."/";
$from_path = $from_path."/";
}
$move_map[$from_path] = $to_path;
}
}
if ($move_map) {
self::updateAffectedPackages($repository, $move_map);
}
}
private static function updateAffectedPackages($repository, array $move_map) {
$paths = array_keys($move_map);
if ($paths) {
$packages = PhabricatorOwnersPackage::loadAffectedPackages($repository,
$paths);
foreach ($packages as $package) {
self::updatePackagePaths($package, $move_map);
}
}
}
private static function updatePackagePaths($package, array $move_map) {
$paths = array_keys($move_map);
$pkg_paths = $package->loadPaths();
$new_paths = array();
foreach ($pkg_paths as $pkg_path) {
$path_changed = false;
foreach ($paths as $old_path) {
if (strncmp($pkg_path->getPath(), $old_path, strlen($old_path)) === 0) {
$new_paths[] = array (
'packageID' => $package->getID(),
'repositoryPHID' => $pkg_path->getRepositoryPHID(),
'path' => str_replace($pkg_path->getPath(), $old_path,
$move_map[$old_path])
);
$path_changed = true;
}
}
if (!$path_changed) {
$new_paths[] = array (
'packageID' => $package->getID(),
'repositoryPHID' => $pkg_path->getRepositoryPHID(),
'path' => $pkg_path->getPath(),
);
}
}
if ($new_paths) {
$package->attachUnsavedPaths($new_paths);
$package->save(); // save the changes and notify the owners.
}
}
private static function loadDiffusionChangesForCommit($commit) {
$repository =
id(new PhabricatorRepository())->load($commit->getRepositoryID());
$data = array(
'repository'=>$repository,
'commit'=>$commit->getCommitIdentifier()
);
$drequest = DiffusionRequest::newFromDictionary($data);
$change_query =
DiffusionPathChangeQuery::newFromDiffusionRequest($drequest);
return $change_query->loadChanges();
}
}

View file

@ -59,6 +59,7 @@ abstract class PhabricatorRepositoryCommitChangeParserWorker
$commit = $this->commit;
PhabricatorSearchCommitIndexer::indexCommit($commit);
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths($commit);
if ($this->shouldQueueFollowupTasks()) {
PhabricatorWorker::scheduleTask(
'PhabricatorRepositoryCommitOwnersWorker',