Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/storage/DifferentialChangeset.php
| <?php | <?php | ||||
| final class DifferentialChangeset | final class DifferentialChangeset | ||||
| extends DifferentialDAO | extends DifferentialDAO | ||||
| implements | implements | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorDestructibleInterface { | PhabricatorDestructibleInterface { | ||||
| protected $diffID; | protected $diffID; | ||||
| protected $oldFile; | protected $oldFile; | ||||
| protected $filename; | protected $filename; | ||||
| protected $awayPaths; | protected $awayPaths; | ||||
| protected $changeType; | protected $changeType; | ||||
| protected $fileType; | protected $fileType; | ||||
| protected $metadata; | protected $metadata = array(); | ||||
| protected $oldProperties; | protected $oldProperties; | ||||
| protected $newProperties; | protected $newProperties; | ||||
| protected $addLines; | protected $addLines; | ||||
| protected $delLines; | protected $delLines; | ||||
| private $unsavedHunks = array(); | private $unsavedHunks = array(); | ||||
| private $hunks = self::ATTACHABLE; | private $hunks = self::ATTACHABLE; | ||||
| private $diff = self::ATTACHABLE; | private $diff = self::ATTACHABLE; | ||||
| const TABLE_CACHE = 'differential_changeset_parse_cache'; | const TABLE_CACHE = 'differential_changeset_parse_cache'; | ||||
| const METADATA_TRUSTED_ATTRIBUTES = 'attributes.trusted'; | |||||
| const METADATA_UNTRUSTED_ATTRIBUTES = 'attributes.untrusted'; | |||||
| const ATTRIBUTE_GENERATED = 'generated'; | |||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
| 'metadata' => self::SERIALIZATION_JSON, | 'metadata' => self::SERIALIZATION_JSON, | ||||
| 'oldProperties' => self::SERIALIZATION_JSON, | 'oldProperties' => self::SERIALIZATION_JSON, | ||||
| 'newProperties' => self::SERIALIZATION_JSON, | 'newProperties' => self::SERIALIZATION_JSON, | ||||
| 'awayPaths' => self::SERIALIZATION_JSON, | 'awayPaths' => self::SERIALIZATION_JSON, | ||||
| ), | ), | ||||
| ▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | switch ($this->getChangeType()) { | ||||
| case DifferentialChangeType::TYPE_COPY_HERE: | case DifferentialChangeType::TYPE_COPY_HERE: | ||||
| case DifferentialChangeType::TYPE_MULTICOPY: | case DifferentialChangeType::TYPE_MULTICOPY: | ||||
| return 'filetree-movecopy'; | return 'filetree-movecopy'; | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| public function setChangesetMetadata($key, $value) { | |||||
| if (!is_array($this->metadata)) { | |||||
| $this->metadata = array(); | |||||
| } | |||||
| $this->metadata[$key] = $value; | |||||
| return $this; | |||||
| } | |||||
| public function getChangesetMetadata($key, $default = null) { | |||||
| if (!is_array($this->metadata)) { | |||||
| return $default; | |||||
| } | |||||
| return idx($this->metadata, $key, $default); | |||||
| } | |||||
| private function setInternalChangesetAttribute($trusted, $key, $value) { | |||||
| if ($trusted) { | |||||
| $meta_key = self::METADATA_TRUSTED_ATTRIBUTES; | |||||
| } else { | |||||
| $meta_key = self::METADATA_UNTRUSTED_ATTRIBUTES; | |||||
| } | |||||
| $attributes = $this->getChangesetMetadata($meta_key, array()); | |||||
| $attributes[$key] = $value; | |||||
| $this->setChangesetMetadata($meta_key, $attributes); | |||||
| return $this; | |||||
| } | |||||
| private function getInternalChangesetAttributes($trusted) { | |||||
| if ($trusted) { | |||||
| $meta_key = self::METADATA_TRUSTED_ATTRIBUTES; | |||||
| } else { | |||||
| $meta_key = self::METADATA_UNTRUSTED_ATTRIBUTES; | |||||
| } | |||||
| return $this->getChangesetMetadata($meta_key, array()); | |||||
| } | |||||
| public function setTrustedChangesetAttribute($key, $value) { | |||||
| return $this->setInternalChangesetAttribute(true, $key, $value); | |||||
| } | |||||
| public function getTrustedChangesetAttributes() { | |||||
| return $this->getInternalChangesetAttributes(true); | |||||
| } | |||||
| public function getTrustedChangesetAttribute($key, $default = null) { | |||||
| $map = $this->getTrustedChangesetAttributes(); | |||||
| return idx($map, $key, $default); | |||||
| } | |||||
| public function setUntrustedChangesetAttribute($key, $value) { | |||||
| return $this->setInternalChangesetAttribute(false, $key, $value); | |||||
| } | |||||
| public function getUntrustedChangesetAttributes() { | |||||
| return $this->getInternalChangesetAttributes(false); | |||||
| } | |||||
| public function getUntrustedChangesetAttribute($key, $default = null) { | |||||
| $map = $this->getUntrustedChangesetAttributes(); | |||||
| return idx($map, $key, $default); | |||||
| } | |||||
| public function getChangesetAttributes() { | |||||
| // Prefer trusted values over untrusted values when both exist. | |||||
| return | |||||
| $this->getTrustedChangesetAttributes() + | |||||
| $this->getUntrustedChangesetAttributes(); | |||||
| } | |||||
| public function getChangesetAttribute($key, $default = null) { | |||||
| $map = $this->getChangesetAttributes(); | |||||
| return idx($map, $key, $default); | |||||
| } | |||||
| public function isGeneratedChangeset() { | |||||
| return $this->getChangesetAttribute(self::ATTRIBUTE_GENERATED); | |||||
| } | |||||
| /* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
| public function getCapabilities() { | public function getCapabilities() { | ||||
| return array( | return array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| ); | ); | ||||
| Show All 32 Lines | |||||