Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php b/src/applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php
index 80a8a33396..e3f5d590ba 100644
--- a/src/applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php
+++ b/src/applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php
@@ -1,112 +1,96 @@
<?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->attachOldPrimaryOwnerPHID($package->getPrimaryOwnerPHID());
$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();
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Dec 2, 2:49 AM (1 d, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
431578
Default Alt Text
(4 KB)

Event Timeline