mirror of
https://we.phorge.it/source/phorge.git
synced 2024-09-23 02:38:48 +02:00
c42f767e37
Summary: When we delete a DifferentialChangeset, also delete the cache if it exists. Test Plan: Destroyed a revision, verified cache was destroyed. See marked line below. $ ./scripts/differential/destroy_revision.php D1 --trace >>> [0] <connect> <<< [0] <connect> 1,324 us >>> [1] <query> SELECT * FROM `differential_revision` WHERE `id` = 1 <<< [1] <query> 517 us Really destroy 'D1: asdb' forever? [y/N] y >>> [2] <connect> <<< [2] <connect> 633 us >>> [3] <query> START TRANSACTION <<< [3] <query> 183 us >>> [4] <query> SELECT * FROM `differential_diff` WHERE revisionID = 1 <<< [4] <query> 560 us >>> [5] <query> SAVEPOINT Aphront_Savepoint_1 <<< [5] <query> 197 us >>> [6] <query> SELECT * FROM `differential_changeset` WHERE diffID = 3 <<< [6] <query> 672 us >>> [7] <query> SAVEPOINT Aphront_Savepoint_2 <<< [7] <query> 188 us >>> [8] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 6 <<< [8] <query> 946 us >>> [9] <query> DELETE FROM `differential_hunk` WHERE `id` = 6 <<< [9] <query> 335 us **** >>> [10] <query> DELETE FROM `differential_changeset_parse_cache` WHERE id = 6 <<< [10] <query> 1,464 us >>> [11] <query> DELETE FROM `differential_changeset` WHERE `id` = 6 <<< [11] <query> 313 us >>> [12] <query> SAVEPOINT Aphront_Savepoint_2 <<< [12] <query> 151 us >>> [13] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 7 <<< [13] <query> 226 us >>> [14] <query> DELETE FROM `differential_hunk` WHERE `id` = 7 <<< [14] <query> 164 us >>> [15] <query> DELETE FROM `differential_changeset_parse_cache` WHERE id = 7 <<< [15] <query> 318 us >>> [16] <query> DELETE FROM `differential_changeset` WHERE `id` = 7 <<< [16] <query> 189 us >>> [17] <query> SELECT * FROM `differential_diffproperty` WHERE diffID = 3 <<< [17] <query> 500 us >>> [18] <query> DELETE FROM `differential_diffproperty` WHERE `id` = 1 <<< [18] <query> 179 us >>> [19] <query> DELETE FROM `differential_diff` WHERE `id` = 3 <<< [19] <query> 211 us >>> [20] <query> DELETE FROM `differential_relationship` WHERE revisionID = 1 <<< [20] <query> 391 us >>> [21] <query> DELETE FROM `differential_commit` WHERE revisionID = 1 <<< [21] <query> 397 us >>> [22] <query> SELECT * FROM `differential_comment` WHERE revisionID = 1 <<< [22] <query> 448 us >>> [23] <query> DELETE FROM `differential_comment` WHERE `id` = 1 <<< [23] <query> 212 us >>> [24] <query> DELETE FROM `differential_comment` WHERE `id` = 2 <<< [24] <query> 160 us >>> [25] <query> SELECT * FROM `differential_inlinecomment` WHERE revisionID = 1 <<< [25] <query> 549 us >>> [26] <query> SELECT * FROM `differential_auxiliaryfield` WHERE revisionPHID = 'PHID-DREV-orsh7alzcj764ubv2f34' <<< [26] <query> 531 us >>> [27] <query> SELECT * FROM `differential_affectedpath` WHERE revisionID = 1 <<< [27] <query> 5,676 us >>> [28] <query> DELETE FROM `differential_revision` WHERE `id` = 1 <<< [28] <query> 442 us >>> [29] <query> COMMIT <<< [29] <query> 324 us OK, destroyed revision. Reviewers: csilvers, btrahan Reviewed By: csilvers CC: aran Differential Revision: https://secure.phabricator.com/D2835
212 lines
5.6 KiB
PHP
212 lines
5.6 KiB
PHP
<?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 DifferentialChangeset extends DifferentialDAO {
|
|
|
|
protected $diffID;
|
|
protected $oldFile;
|
|
protected $filename;
|
|
protected $awayPaths;
|
|
protected $changeType;
|
|
protected $fileType;
|
|
protected $metadata;
|
|
protected $oldProperties;
|
|
protected $newProperties;
|
|
protected $addLines;
|
|
protected $delLines;
|
|
|
|
private $unsavedHunks = array();
|
|
private $hunks;
|
|
|
|
const TABLE_CACHE = 'differential_changeset_parse_cache';
|
|
|
|
protected function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_SERIALIZATION => array(
|
|
'metadata' => self::SERIALIZATION_JSON,
|
|
'oldProperties' => self::SERIALIZATION_JSON,
|
|
'newProperties' => self::SERIALIZATION_JSON,
|
|
'awayPaths' => self::SERIALIZATION_JSON,
|
|
)) + parent::getConfiguration();
|
|
}
|
|
|
|
public function getAffectedLineCount() {
|
|
return $this->getAddLines() + $this->getDelLines();
|
|
}
|
|
|
|
public function attachHunks(array $hunks) {
|
|
assert_instances_of($hunks, 'DifferentialHunk');
|
|
$this->hunks = $hunks;
|
|
return $this;
|
|
}
|
|
|
|
public function getHunks() {
|
|
if ($this->hunks === null) {
|
|
throw new Exception("Must load and attach hunks first!");
|
|
}
|
|
return $this->hunks;
|
|
}
|
|
|
|
public function getDisplayFilename() {
|
|
$name = $this->getFilename();
|
|
if ($this->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
|
|
$name .= '/';
|
|
}
|
|
return $name;
|
|
}
|
|
|
|
public function addUnsavedHunk(DifferentialHunk $hunk) {
|
|
if ($this->hunks === null) {
|
|
$this->hunks = array();
|
|
}
|
|
$this->hunks[] = $hunk;
|
|
$this->unsavedHunks[] = $hunk;
|
|
return $this;
|
|
}
|
|
|
|
public function loadHunks() {
|
|
if (!$this->getID()) {
|
|
return array();
|
|
}
|
|
return id(new DifferentialHunk())->loadAllWhere(
|
|
'changesetID = %d',
|
|
$this->getID());
|
|
}
|
|
|
|
public function save() {
|
|
$this->openTransaction();
|
|
$ret = parent::save();
|
|
foreach ($this->unsavedHunks as $hunk) {
|
|
$hunk->setChangesetID($this->getID());
|
|
$hunk->save();
|
|
}
|
|
$this->saveTransaction();
|
|
return $ret;
|
|
}
|
|
|
|
public function delete() {
|
|
$this->openTransaction();
|
|
foreach ($this->loadHunks() as $hunk) {
|
|
$hunk->delete();
|
|
}
|
|
$this->_hunks = array();
|
|
|
|
queryfx(
|
|
$this->establishConnection('w'),
|
|
'DELETE FROM %T WHERE id = %d',
|
|
self::TABLE_CACHE,
|
|
$this->getID());
|
|
|
|
$ret = parent::delete();
|
|
$this->saveTransaction();
|
|
return $ret;
|
|
}
|
|
|
|
public function getSortKey() {
|
|
$sort_key = $this->getFilename();
|
|
// Sort files with ".h" in them first, so headers (.h, .hpp) come before
|
|
// implementations (.c, .cpp, .cs).
|
|
$sort_key = str_replace('.h', '.!h', $sort_key);
|
|
return $sort_key;
|
|
}
|
|
|
|
public function makeNewFile() {
|
|
$file = array();
|
|
foreach ($this->getHunks() as $hunk) {
|
|
$file[] = $hunk->makeNewFile();
|
|
}
|
|
return implode("\n", $file);
|
|
}
|
|
|
|
public function makeOldFile() {
|
|
$file = array();
|
|
foreach ($this->getHunks() as $hunk) {
|
|
$file[] = $hunk->makeOldFile();
|
|
}
|
|
return implode("\n", $file);
|
|
}
|
|
|
|
public function makeChangesWithContext($num_lines = 3) {
|
|
$with_context = array();
|
|
foreach ($this->getHunks() as $hunk) {
|
|
$context = array();
|
|
$changes = explode("\n", $hunk->getChanges());
|
|
foreach ($changes as $l => $line) {
|
|
if ($line[0] == '+' || $line[0] == '-') {
|
|
$context += array_fill($l - $num_lines, 2 * $num_lines + 1, true);
|
|
}
|
|
}
|
|
$with_context[] = array_intersect_key($changes, $context);
|
|
}
|
|
return array_mergev($with_context);
|
|
}
|
|
|
|
public function getAnchorName() {
|
|
return substr(md5($this->getFilename()), 0, 8);
|
|
}
|
|
|
|
public function getAbsoluteRepositoryPath(
|
|
PhabricatorRepository $repository = null,
|
|
DifferentialDiff $diff = null) {
|
|
|
|
$base = '/';
|
|
if ($diff && $diff->getSourceControlPath()) {
|
|
$base = id(new PhutilURI($diff->getSourceControlPath()))->getPath();
|
|
}
|
|
|
|
$path = $this->getFilename();
|
|
$path = rtrim($base, '/').'/'.ltrim($path, '/');
|
|
|
|
$svn = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN;
|
|
if ($repository && $repository->getVersionControlSystem() == $svn) {
|
|
$prefix = $repository->getDetail('remote-uri');
|
|
$prefix = id(new PhutilURI($prefix))->getPath();
|
|
if (!strncmp($path, $prefix, strlen($prefix))) {
|
|
$path = substr($path, strlen($prefix));
|
|
}
|
|
$path = '/'.ltrim($path, '/');
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
/**
|
|
* Retreive the configured wordwrap width for this changeset.
|
|
*/
|
|
public function getWordWrapWidth() {
|
|
$config = PhabricatorEnv::getEnvConfig('differential.wordwrap');
|
|
foreach ($config as $regexp => $width) {
|
|
if (preg_match($regexp, $this->getFilename())) {
|
|
return $width;
|
|
}
|
|
}
|
|
return 80;
|
|
}
|
|
|
|
public function getWhitespaceMatters() {
|
|
$config = PhabricatorEnv::getEnvConfig('differential.whitespace-matters');
|
|
foreach ($config as $regexp) {
|
|
if (preg_match($regexp, $this->getFilename())) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|