Differential D21616 Diff 51462 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
Show First 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
$this->ownersDiff = $diff; | $this->ownersDiff = $diff; | ||||
$this->ownersChangesets = $diff->getChangesets(); | $this->ownersChangesets = $diff->getChangesets(); | ||||
// Update these denormalized index tables when we attach a new | // Update these denormalized index tables when we attach a new | ||||
// diff to a revision. | // diff to a revision. | ||||
$this->updateRevisionHashTable($object, $diff); | $this->updateRevisionHashTable($object, $diff); | ||||
$this->updateAffectedPathTable($object, $diff); | |||||
id(new DifferentialAffectedPathEngine()) | |||||
->setRevision($object) | |||||
->setDiff($diff) | |||||
->updateAffectedPaths(); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
$xactions = $this->updateReviewStatus($object, $xactions); | $xactions = $this->updateReviewStatus($object, $xactions); | ||||
$this->markReviewerComments($object, $xactions); | $this->markReviewerComments($object, $xactions); | ||||
return $xactions; | return $xactions; | ||||
▲ Show 20 Lines • Show All 886 Lines • ▼ Show 20 Lines | if ($has_commit) { | ||||
HeraldBuildableState::STATECONST, | HeraldBuildableState::STATECONST, | ||||
DifferentialHeraldStateReasons::REASON_UNCHANGED); | DifferentialHeraldStateReasons::REASON_UNCHANGED); | ||||
} | } | ||||
return $adapter; | return $adapter; | ||||
} | } | ||||
/** | /** | ||||
* Update the table which links Differential revisions to paths they affect, | |||||
* so Diffusion can efficiently find pending revisions for a given file. | |||||
*/ | |||||
private function updateAffectedPathTable( | |||||
DifferentialRevision $revision, | |||||
DifferentialDiff $diff) { | |||||
$repository = $revision->getRepository(); | |||||
if (!$repository) { | |||||
// The repository where the code lives is untracked. | |||||
return; | |||||
} | |||||
$path_prefix = null; | |||||
$local_root = $diff->getSourceControlPath(); | |||||
if ($local_root) { | |||||
// We're in a working copy which supports subdirectory checkouts (e.g., | |||||
// SVN) so we need to figure out what prefix we should add to each path | |||||
// (e.g., trunk/projects/example/) to get the absolute path from the | |||||
// root of the repository. DVCS systems like Git and Mercurial are not | |||||
// affected. | |||||
// Normalize both paths and check if the repository root is a prefix of | |||||
// the local root. If so, throw it away. Note that this correctly handles | |||||
// the case where the remote path is "/". | |||||
$local_root = id(new PhutilURI($local_root))->getPath(); | |||||
$local_root = rtrim($local_root, '/'); | |||||
$repo_root = id(new PhutilURI($repository->getRemoteURI()))->getPath(); | |||||
$repo_root = rtrim($repo_root, '/'); | |||||
if (!strncmp($repo_root, $local_root, strlen($repo_root))) { | |||||
$path_prefix = substr($local_root, strlen($repo_root)); | |||||
} | |||||
} | |||||
$changesets = $diff->getChangesets(); | |||||
$paths = array(); | |||||
foreach ($changesets as $changeset) { | |||||
$paths[] = $path_prefix.'/'.$changeset->getFilename(); | |||||
} | |||||
// Mark this as also touching all parent paths, so you can see all pending | |||||
// changes to any file within a directory. | |||||
$all_paths = array(); | |||||
foreach ($paths as $local) { | |||||
foreach (DiffusionPathIDQuery::expandPathToRoot($local) as $path) { | |||||
$all_paths[$path] = true; | |||||
} | |||||
} | |||||
$all_paths = array_keys($all_paths); | |||||
$path_ids = | |||||
PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths( | |||||
$all_paths); | |||||
$table = new DifferentialAffectedPath(); | |||||
$conn_w = $table->establishConnection('w'); | |||||
$sql = array(); | |||||
foreach ($path_ids as $path_id) { | |||||
$sql[] = qsprintf( | |||||
$conn_w, | |||||
'(%d, %d, %d, %d)', | |||||
$repository->getID(), | |||||
$path_id, | |||||
time(), | |||||
$revision->getID()); | |||||
} | |||||
queryfx( | |||||
$conn_w, | |||||
'DELETE FROM %T WHERE revisionID = %d', | |||||
$table->getTableName(), | |||||
$revision->getID()); | |||||
foreach (array_chunk($sql, 256) as $chunk) { | |||||
queryfx( | |||||
$conn_w, | |||||
'INSERT INTO %T (repositoryID, pathID, epoch, revisionID) VALUES %LQ', | |||||
$table->getTableName(), | |||||
$chunk); | |||||
} | |||||
} | |||||
/** | |||||
* Update the table connecting revisions to DVCS local hashes, so we can | * Update the table connecting revisions to DVCS local hashes, so we can | ||||
* identify revisions by commit/tree hashes. | * identify revisions by commit/tree hashes. | ||||
*/ | */ | ||||
private function updateRevisionHashTable( | private function updateRevisionHashTable( | ||||
DifferentialRevision $revision, | DifferentialRevision $revision, | ||||
DifferentialDiff $diff) { | DifferentialDiff $diff) { | ||||
$vcs = $diff->getSourceControlSystem(); | $vcs = $diff->getSourceControlSystem(); | ||||
▲ Show 20 Lines • Show All 388 Lines • Show Last 20 Lines |