Path: blob/master/src/applications/differential/engine/DifferentialAffectedPathEngine.php
12256 views
<?php12final class DifferentialAffectedPathEngine3extends Phobject {45private $revision;6private $diff;78public function setRevision(DifferentialRevision $revision) {9$this->revision = $revision;10return $this;11}1213public function getRevision() {14return $this->revision;15}1617public function setDiff(DifferentialDiff $diff) {18$this->diff = $diff;19return $this;20}2122public function getDiff() {23return $this->diff;24}2526public function updateAffectedPaths() {27$revision = $this->getRevision();28$diff = $this->getDiff();29$repository = $revision->getRepository();3031if ($repository) {32$repository_id = $repository->getID();33} else {34$repository_id = null;35}3637$paths = $this->getAffectedPaths();3839$path_ids =40PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(41$paths);4243$table = new DifferentialAffectedPath();44$conn = $table->establishConnection('w');4546$sql = array();47foreach ($path_ids as $path_id) {48$sql[] = qsprintf(49$conn,50'(%nd, %d, %d)',51$repository_id,52$path_id,53$revision->getID());54}5556queryfx(57$conn,58'DELETE FROM %R WHERE revisionID = %d',59$table,60$revision->getID());61if ($sql) {62foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {63queryfx(64$conn,65'INSERT INTO %R (repositoryID, pathID, revisionID) VALUES %LQ',66$table,67$chunk);68}69}70}7172public function destroyAffectedPaths() {73$revision = $this->getRevision();7475$table = new DifferentialAffectedPath();76$conn = $table->establishConnection('w');7778queryfx(79$conn,80'DELETE FROM %R WHERE revisionID = %d',81$table,82$revision->getID());83}8485public function getAffectedPaths() {86$revision = $this->getRevision();87$diff = $this->getDiff();88$repository = $revision->getRepository();8990$path_prefix = null;91if ($repository) {92$local_root = $diff->getSourceControlPath();93if ($local_root) {94// We're in a working copy which supports subdirectory checkouts (e.g.,95// SVN) so we need to figure out what prefix we should add to each path96// (e.g., trunk/projects/example/) to get the absolute path from the97// root of the repository. DVCS systems like Git and Mercurial are not98// affected.99100// Normalize both paths and check if the repository root is a prefix of101// the local root. If so, throw it away. Note that this correctly102// handles the case where the remote path is "/".103$local_root = id(new PhutilURI($local_root))->getPath();104$local_root = rtrim($local_root, '/');105106$repo_root = id(new PhutilURI($repository->getRemoteURI()))->getPath();107$repo_root = rtrim($repo_root, '/');108109if (!strncmp($repo_root, $local_root, strlen($repo_root))) {110$path_prefix = substr($local_root, strlen($repo_root));111}112}113}114115$changesets = $diff->getChangesets();116117$paths = array();118foreach ($changesets as $changeset) {119$paths[] = $path_prefix.'/'.$changeset->getFilename();120}121122// Mark this as also touching all parent paths, so you can see all pending123// changes to any file within a directory.124$all_paths = array();125foreach ($paths as $local) {126foreach (DiffusionPathIDQuery::expandPathToRoot($local) as $path) {127$all_paths[$path] = true;128}129}130$all_paths = array_keys($all_paths);131132return $all_paths;133}134135}136137138