1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 10:52:41 +01:00
phorge-phorge/src/applications/differential/storage/DifferentialChangeset.php

205 lines
5.2 KiB
PHP
Raw Normal View History

2011-01-24 20:01:53 +01:00
<?php
final class DifferentialChangeset extends DifferentialDAO
implements PhabricatorPolicyInterface {
2011-01-24 20:01:53 +01:00
protected $diffID;
protected $oldFile;
protected $filename;
2011-01-24 20:01:53 +01:00
protected $awayPaths;
protected $changeType;
protected $fileType;
protected $metadata;
protected $oldProperties;
protected $newProperties;
protected $addLines;
protected $delLines;
2011-01-24 20:36:53 +01:00
private $unsavedHunks = array();
private $hunks = self::ATTACHABLE;
private $diff = self::ATTACHABLE;
2011-01-24 20:36:53 +01:00
const TABLE_CACHE = 'differential_changeset_parse_cache';
2011-01-24 20:01:53 +01:00
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();
}
2011-01-25 00:52:35 +01:00
public function attachHunks(array $hunks) {
assert_instances_of($hunks, 'DifferentialHunk');
2011-01-25 00:52:35 +01:00
$this->hunks = $hunks;
return $this;
}
public function getHunks() {
return $this->assertAttached($this->hunks);
2011-01-25 00:52:35 +01:00
}
2011-01-24 20:01:53 +01:00
public function getDisplayFilename() {
$name = $this->getFilename();
if ($this->getFileType() == DifferentialChangeType::FILE_DIRECTORY) {
$name .= '/';
}
return $name;
}
2011-01-24 20:36:53 +01:00
public function addUnsavedHunk(DifferentialHunk $hunk) {
if ($this->hunks === self::ATTACHABLE) {
2011-01-25 00:52:35 +01:00
$this->hunks = array();
}
$this->hunks[] = $hunk;
2011-01-24 20:36:53 +01:00
$this->unsavedHunks[] = $hunk;
2011-01-24 20:01:53 +01:00
return $this;
}
2011-01-24 20:36:53 +01:00
public function save() {
Provide a script to completely destroy revisions Summary: Someone may or may not have accidentally uploaded secrets to Differential. Provide an administrative mechanism to permanently destroy a revision. Also fix some of the transaction handling code. Test Plan: $ ./scripts/differential/destroy_revision.php --trace D1 >>> [0] <connect> <<< [0] <connect> 1,060 us >>> [1] <query> SELECT * FROM `differential_revision` WHERE `id` = 1 <<< [1] <query> 473 us Really destroy 'D1: asdbas' forever? [y/N] y >>> [2] <connect> <<< [2] <connect> 628 us >>> [3] <query> START TRANSACTION <<< [3] <query> 190 us >>> [4] <query> SELECT * FROM `differential_diff` WHERE revisionID = 1 <<< [4] <query> 510 us >>> [5] <query> SAVEPOINT Aphront_Savepoint_1 <<< [5] <query> 122 us >>> [6] <query> SELECT * FROM `differential_changeset` WHERE diffID = 1 <<< [6] <query> 307 us >>> [7] <query> SAVEPOINT Aphront_Savepoint_2 <<< [7] <query> 241 us >>> [8] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 1 <<< [8] <query> 212 us >>> [9] <query> DELETE FROM `differential_hunk` WHERE `id` = 1 <<< [9] <query> 216 us >>> [10] <query> DELETE FROM `differential_changeset` WHERE `id` = 1 <<< [10] <query> 154 us >>> [11] <query> SAVEPOINT Aphront_Savepoint_2 <<< [11] <query> 118 us >>> [12] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 2 <<< [12] <query> 194 us >>> [13] <query> DELETE FROM `differential_hunk` WHERE `id` = 2 <<< [13] <query> 179 us >>> [14] <query> DELETE FROM `differential_changeset` WHERE `id` = 2 <<< [14] <query> 163 us >>> [15] <query> SAVEPOINT Aphront_Savepoint_2 <<< [15] <query> 105 us >>> [16] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 3 <<< [16] <query> 211 us >>> [17] <query> DELETE FROM `differential_hunk` WHERE `id` = 3 <<< [17] <query> 159 us >>> [18] <query> DELETE FROM `differential_changeset` WHERE `id` = 3 <<< [18] <query> 152 us >>> [19] <query> SAVEPOINT Aphront_Savepoint_2 <<< [19] <query> 124 us >>> [20] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 4 <<< [20] <query> 191 us >>> [21] <query> DELETE FROM `differential_hunk` WHERE `id` = 4 <<< [21] <query> 155 us >>> [22] <query> DELETE FROM `differential_changeset` WHERE `id` = 4 <<< [22] <query> 149 us >>> [23] <query> SELECT * FROM `differential_diffproperty` WHERE diffID = 1 <<< [23] <query> 242 us >>> [24] <query> DELETE FROM `differential_diffproperty` WHERE `id` = 1 <<< [24] <query> 196 us >>> [25] <query> DELETE FROM `differential_diff` WHERE `id` = 1 <<< [25] <query> 169 us >>> [26] <query> DELETE FROM `differential_relationship` WHERE revisionID = 1 <<< [26] <query> 178 us >>> [27] <query> DELETE FROM `differential_commit` WHERE revisionID = 1 <<< [27] <query> 164 us >>> [28] <query> SELECT * FROM `differential_comment` WHERE revisionID = 1 <<< [28] <query> 221 us >>> [29] <query> DELETE FROM `differential_comment` WHERE `id` = 1 <<< [29] <query> 172 us >>> [30] <query> SELECT * FROM `differential_inlinecomment` WHERE revisionID = 1 <<< [30] <query> 296 us >>> [31] <query> SELECT * FROM `differential_auxiliaryfield` WHERE revisionPHID = 'PHID-DREV-ooky7ozqukpmwget32oc' <<< [31] <query> 308 us >>> [32] <query> SELECT * FROM `differential_affectedpath` WHERE revisionID = 1 <<< [32] <query> 4,173 us >>> [33] <query> DELETE FROM `differential_revision` WHERE `id` = 1 <<< [33] <query> 231 us >>> [34] <query> COMMIT <<< [34] <query> 686 us OK, destroyed revision. Reviewers: csilvers, vrana, jungejason Reviewed By: csilvers CC: aran Differential Revision: https://secure.phabricator.com/D2796
2012-06-19 20:52:50 +02:00
$this->openTransaction();
2011-01-24 20:36:53 +01:00
$ret = parent::save();
foreach ($this->unsavedHunks as $hunk) {
$hunk->setChangesetID($this->getID());
$hunk->save();
}
Provide a script to completely destroy revisions Summary: Someone may or may not have accidentally uploaded secrets to Differential. Provide an administrative mechanism to permanently destroy a revision. Also fix some of the transaction handling code. Test Plan: $ ./scripts/differential/destroy_revision.php --trace D1 >>> [0] <connect> <<< [0] <connect> 1,060 us >>> [1] <query> SELECT * FROM `differential_revision` WHERE `id` = 1 <<< [1] <query> 473 us Really destroy 'D1: asdbas' forever? [y/N] y >>> [2] <connect> <<< [2] <connect> 628 us >>> [3] <query> START TRANSACTION <<< [3] <query> 190 us >>> [4] <query> SELECT * FROM `differential_diff` WHERE revisionID = 1 <<< [4] <query> 510 us >>> [5] <query> SAVEPOINT Aphront_Savepoint_1 <<< [5] <query> 122 us >>> [6] <query> SELECT * FROM `differential_changeset` WHERE diffID = 1 <<< [6] <query> 307 us >>> [7] <query> SAVEPOINT Aphront_Savepoint_2 <<< [7] <query> 241 us >>> [8] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 1 <<< [8] <query> 212 us >>> [9] <query> DELETE FROM `differential_hunk` WHERE `id` = 1 <<< [9] <query> 216 us >>> [10] <query> DELETE FROM `differential_changeset` WHERE `id` = 1 <<< [10] <query> 154 us >>> [11] <query> SAVEPOINT Aphront_Savepoint_2 <<< [11] <query> 118 us >>> [12] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 2 <<< [12] <query> 194 us >>> [13] <query> DELETE FROM `differential_hunk` WHERE `id` = 2 <<< [13] <query> 179 us >>> [14] <query> DELETE FROM `differential_changeset` WHERE `id` = 2 <<< [14] <query> 163 us >>> [15] <query> SAVEPOINT Aphront_Savepoint_2 <<< [15] <query> 105 us >>> [16] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 3 <<< [16] <query> 211 us >>> [17] <query> DELETE FROM `differential_hunk` WHERE `id` = 3 <<< [17] <query> 159 us >>> [18] <query> DELETE FROM `differential_changeset` WHERE `id` = 3 <<< [18] <query> 152 us >>> [19] <query> SAVEPOINT Aphront_Savepoint_2 <<< [19] <query> 124 us >>> [20] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 4 <<< [20] <query> 191 us >>> [21] <query> DELETE FROM `differential_hunk` WHERE `id` = 4 <<< [21] <query> 155 us >>> [22] <query> DELETE FROM `differential_changeset` WHERE `id` = 4 <<< [22] <query> 149 us >>> [23] <query> SELECT * FROM `differential_diffproperty` WHERE diffID = 1 <<< [23] <query> 242 us >>> [24] <query> DELETE FROM `differential_diffproperty` WHERE `id` = 1 <<< [24] <query> 196 us >>> [25] <query> DELETE FROM `differential_diff` WHERE `id` = 1 <<< [25] <query> 169 us >>> [26] <query> DELETE FROM `differential_relationship` WHERE revisionID = 1 <<< [26] <query> 178 us >>> [27] <query> DELETE FROM `differential_commit` WHERE revisionID = 1 <<< [27] <query> 164 us >>> [28] <query> SELECT * FROM `differential_comment` WHERE revisionID = 1 <<< [28] <query> 221 us >>> [29] <query> DELETE FROM `differential_comment` WHERE `id` = 1 <<< [29] <query> 172 us >>> [30] <query> SELECT * FROM `differential_inlinecomment` WHERE revisionID = 1 <<< [30] <query> 296 us >>> [31] <query> SELECT * FROM `differential_auxiliaryfield` WHERE revisionPHID = 'PHID-DREV-ooky7ozqukpmwget32oc' <<< [31] <query> 308 us >>> [32] <query> SELECT * FROM `differential_affectedpath` WHERE revisionID = 1 <<< [32] <query> 4,173 us >>> [33] <query> DELETE FROM `differential_revision` WHERE `id` = 1 <<< [33] <query> 231 us >>> [34] <query> COMMIT <<< [34] <query> 686 us OK, destroyed revision. Reviewers: csilvers, vrana, jungejason Reviewed By: csilvers CC: aran Differential Revision: https://secure.phabricator.com/D2796
2012-06-19 20:52:50 +02:00
$this->saveTransaction();
2011-01-24 20:36:53 +01:00
return $ret;
}
2011-01-24 20:01:53 +01:00
public function delete() {
Provide a script to completely destroy revisions Summary: Someone may or may not have accidentally uploaded secrets to Differential. Provide an administrative mechanism to permanently destroy a revision. Also fix some of the transaction handling code. Test Plan: $ ./scripts/differential/destroy_revision.php --trace D1 >>> [0] <connect> <<< [0] <connect> 1,060 us >>> [1] <query> SELECT * FROM `differential_revision` WHERE `id` = 1 <<< [1] <query> 473 us Really destroy 'D1: asdbas' forever? [y/N] y >>> [2] <connect> <<< [2] <connect> 628 us >>> [3] <query> START TRANSACTION <<< [3] <query> 190 us >>> [4] <query> SELECT * FROM `differential_diff` WHERE revisionID = 1 <<< [4] <query> 510 us >>> [5] <query> SAVEPOINT Aphront_Savepoint_1 <<< [5] <query> 122 us >>> [6] <query> SELECT * FROM `differential_changeset` WHERE diffID = 1 <<< [6] <query> 307 us >>> [7] <query> SAVEPOINT Aphront_Savepoint_2 <<< [7] <query> 241 us >>> [8] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 1 <<< [8] <query> 212 us >>> [9] <query> DELETE FROM `differential_hunk` WHERE `id` = 1 <<< [9] <query> 216 us >>> [10] <query> DELETE FROM `differential_changeset` WHERE `id` = 1 <<< [10] <query> 154 us >>> [11] <query> SAVEPOINT Aphront_Savepoint_2 <<< [11] <query> 118 us >>> [12] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 2 <<< [12] <query> 194 us >>> [13] <query> DELETE FROM `differential_hunk` WHERE `id` = 2 <<< [13] <query> 179 us >>> [14] <query> DELETE FROM `differential_changeset` WHERE `id` = 2 <<< [14] <query> 163 us >>> [15] <query> SAVEPOINT Aphront_Savepoint_2 <<< [15] <query> 105 us >>> [16] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 3 <<< [16] <query> 211 us >>> [17] <query> DELETE FROM `differential_hunk` WHERE `id` = 3 <<< [17] <query> 159 us >>> [18] <query> DELETE FROM `differential_changeset` WHERE `id` = 3 <<< [18] <query> 152 us >>> [19] <query> SAVEPOINT Aphront_Savepoint_2 <<< [19] <query> 124 us >>> [20] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 4 <<< [20] <query> 191 us >>> [21] <query> DELETE FROM `differential_hunk` WHERE `id` = 4 <<< [21] <query> 155 us >>> [22] <query> DELETE FROM `differential_changeset` WHERE `id` = 4 <<< [22] <query> 149 us >>> [23] <query> SELECT * FROM `differential_diffproperty` WHERE diffID = 1 <<< [23] <query> 242 us >>> [24] <query> DELETE FROM `differential_diffproperty` WHERE `id` = 1 <<< [24] <query> 196 us >>> [25] <query> DELETE FROM `differential_diff` WHERE `id` = 1 <<< [25] <query> 169 us >>> [26] <query> DELETE FROM `differential_relationship` WHERE revisionID = 1 <<< [26] <query> 178 us >>> [27] <query> DELETE FROM `differential_commit` WHERE revisionID = 1 <<< [27] <query> 164 us >>> [28] <query> SELECT * FROM `differential_comment` WHERE revisionID = 1 <<< [28] <query> 221 us >>> [29] <query> DELETE FROM `differential_comment` WHERE `id` = 1 <<< [29] <query> 172 us >>> [30] <query> SELECT * FROM `differential_inlinecomment` WHERE revisionID = 1 <<< [30] <query> 296 us >>> [31] <query> SELECT * FROM `differential_auxiliaryfield` WHERE revisionPHID = 'PHID-DREV-ooky7ozqukpmwget32oc' <<< [31] <query> 308 us >>> [32] <query> SELECT * FROM `differential_affectedpath` WHERE revisionID = 1 <<< [32] <query> 4,173 us >>> [33] <query> DELETE FROM `differential_revision` WHERE `id` = 1 <<< [33] <query> 231 us >>> [34] <query> COMMIT <<< [34] <query> 686 us OK, destroyed revision. Reviewers: csilvers, vrana, jungejason Reviewed By: csilvers CC: aran Differential Revision: https://secure.phabricator.com/D2796
2012-06-19 20:52:50 +02:00
$this->openTransaction();
$hunks = id(new DifferentialHunk())->loadAllWhere(
'changesetID = %d',
$this->getID());
foreach ($hunks as $hunk) {
2011-01-24 20:01:53 +01:00
$hunk->delete();
}
$this->unsavedHunks = array();
Destroy changeset parse cache when destroying a revision 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
2012-06-23 01:16:44 +02:00
queryfx(
$this->establishConnection('w'),
'DELETE FROM %T WHERE id = %d',
self::TABLE_CACHE,
$this->getID());
$ret = parent::delete();
Provide a script to completely destroy revisions Summary: Someone may or may not have accidentally uploaded secrets to Differential. Provide an administrative mechanism to permanently destroy a revision. Also fix some of the transaction handling code. Test Plan: $ ./scripts/differential/destroy_revision.php --trace D1 >>> [0] <connect> <<< [0] <connect> 1,060 us >>> [1] <query> SELECT * FROM `differential_revision` WHERE `id` = 1 <<< [1] <query> 473 us Really destroy 'D1: asdbas' forever? [y/N] y >>> [2] <connect> <<< [2] <connect> 628 us >>> [3] <query> START TRANSACTION <<< [3] <query> 190 us >>> [4] <query> SELECT * FROM `differential_diff` WHERE revisionID = 1 <<< [4] <query> 510 us >>> [5] <query> SAVEPOINT Aphront_Savepoint_1 <<< [5] <query> 122 us >>> [6] <query> SELECT * FROM `differential_changeset` WHERE diffID = 1 <<< [6] <query> 307 us >>> [7] <query> SAVEPOINT Aphront_Savepoint_2 <<< [7] <query> 241 us >>> [8] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 1 <<< [8] <query> 212 us >>> [9] <query> DELETE FROM `differential_hunk` WHERE `id` = 1 <<< [9] <query> 216 us >>> [10] <query> DELETE FROM `differential_changeset` WHERE `id` = 1 <<< [10] <query> 154 us >>> [11] <query> SAVEPOINT Aphront_Savepoint_2 <<< [11] <query> 118 us >>> [12] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 2 <<< [12] <query> 194 us >>> [13] <query> DELETE FROM `differential_hunk` WHERE `id` = 2 <<< [13] <query> 179 us >>> [14] <query> DELETE FROM `differential_changeset` WHERE `id` = 2 <<< [14] <query> 163 us >>> [15] <query> SAVEPOINT Aphront_Savepoint_2 <<< [15] <query> 105 us >>> [16] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 3 <<< [16] <query> 211 us >>> [17] <query> DELETE FROM `differential_hunk` WHERE `id` = 3 <<< [17] <query> 159 us >>> [18] <query> DELETE FROM `differential_changeset` WHERE `id` = 3 <<< [18] <query> 152 us >>> [19] <query> SAVEPOINT Aphront_Savepoint_2 <<< [19] <query> 124 us >>> [20] <query> SELECT * FROM `differential_hunk` WHERE changesetID = 4 <<< [20] <query> 191 us >>> [21] <query> DELETE FROM `differential_hunk` WHERE `id` = 4 <<< [21] <query> 155 us >>> [22] <query> DELETE FROM `differential_changeset` WHERE `id` = 4 <<< [22] <query> 149 us >>> [23] <query> SELECT * FROM `differential_diffproperty` WHERE diffID = 1 <<< [23] <query> 242 us >>> [24] <query> DELETE FROM `differential_diffproperty` WHERE `id` = 1 <<< [24] <query> 196 us >>> [25] <query> DELETE FROM `differential_diff` WHERE `id` = 1 <<< [25] <query> 169 us >>> [26] <query> DELETE FROM `differential_relationship` WHERE revisionID = 1 <<< [26] <query> 178 us >>> [27] <query> DELETE FROM `differential_commit` WHERE revisionID = 1 <<< [27] <query> 164 us >>> [28] <query> SELECT * FROM `differential_comment` WHERE revisionID = 1 <<< [28] <query> 221 us >>> [29] <query> DELETE FROM `differential_comment` WHERE `id` = 1 <<< [29] <query> 172 us >>> [30] <query> SELECT * FROM `differential_inlinecomment` WHERE revisionID = 1 <<< [30] <query> 296 us >>> [31] <query> SELECT * FROM `differential_auxiliaryfield` WHERE revisionPHID = 'PHID-DREV-ooky7ozqukpmwget32oc' <<< [31] <query> 308 us >>> [32] <query> SELECT * FROM `differential_affectedpath` WHERE revisionID = 1 <<< [32] <query> 4,173 us >>> [33] <query> DELETE FROM `differential_revision` WHERE `id` = 1 <<< [33] <query> 231 us >>> [34] <query> COMMIT <<< [34] <query> 686 us OK, destroyed revision. Reviewers: csilvers, vrana, jungejason Reviewed By: csilvers CC: aran Differential Revision: https://secure.phabricator.com/D2796
2012-06-19 20:52:50 +02:00
$this->saveTransaction();
2011-01-24 20:01:53 +01:00
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 = mpull($this->getHunks(), 'makeNewFile');
return implode('', $file);
2011-01-24 20:01:53 +01:00
}
public function makeOldFile() {
$file = mpull($this->getHunks(), 'makeOldFile');
return implode('', $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) {
$type = substr($line, 0, 1);
if ($type == '+' || $type == '-') {
$context += array_fill($l - $num_lines, 2 * $num_lines + 1, true);
}
}
$with_context[] = array_intersect_key($changes, $context);
}
2012-06-15 05:39:48 +02:00
return array_mergev($with_context);
}
2011-02-05 01:18:08 +01:00
public function getAnchorName() {
return substr(md5($this->getFilename()), 0, 8);
}
2011-01-24 20:01:53 +01:00
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;
}
public function getWhitespaceMatters() {
$config = PhabricatorEnv::getEnvConfig('differential.whitespace-matters');
foreach ($config as $regexp) {
if (preg_match($regexp, $this->getFilename())) {
return true;
}
}
return false;
}
public function attachDiff(DifferentialDiff $diff) {
$this->diff = $diff;
return $this;
}
public function getDiff() {
return $this->assertAttached($this->diff);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return $this->getDiff()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getDiff()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return null;
}
2011-01-24 20:01:53 +01:00
}