Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/storage/DifferentialHunk.php
<?php | <?php | ||||
abstract class DifferentialHunk extends DifferentialDAO | final class DifferentialHunk extends DifferentialDAO | ||||
implements PhabricatorPolicyInterface { | implements PhabricatorPolicyInterface { | ||||
const FLAG_LINES_ADDED = 1; | |||||
const FLAG_LINES_REMOVED = 2; | |||||
const FLAG_LINES_STABLE = 4; | |||||
const DATATYPE_TEXT = 'text'; | |||||
const DATATYPE_FILE = 'file'; | |||||
const DATAFORMAT_RAW = 'byte'; | |||||
const DATAFORMAT_DEFLATED = 'gzde'; | |||||
protected $changesetID; | protected $changesetID; | ||||
protected $oldOffset; | protected $oldOffset; | ||||
protected $oldLen; | protected $oldLen; | ||||
protected $newOffset; | protected $newOffset; | ||||
protected $newLen; | protected $newLen; | ||||
private $changeset; | private $changeset; | ||||
private $splitLines; | private $splitLines; | ||||
private $structuredLines; | private $structuredLines; | ||||
private $structuredFiles = array(); | private $structuredFiles = array(); | ||||
const FLAG_LINES_ADDED = 1; | protected $dataType; | ||||
const FLAG_LINES_REMOVED = 2; | protected $dataEncoding; | ||||
const FLAG_LINES_STABLE = 4; | protected $dataFormat; | ||||
protected $data; | |||||
private $rawData; | |||||
private $forcedEncoding; | |||||
protected function getConfiguration() { | |||||
return array( | |||||
self::CONFIG_BINARY => array( | |||||
'data' => true, | |||||
), | |||||
self::CONFIG_COLUMN_SCHEMA => array( | |||||
'dataType' => 'bytes4', | |||||
'dataEncoding' => 'text16?', | |||||
'dataFormat' => 'bytes4', | |||||
'oldOffset' => 'uint32', | |||||
'oldLen' => 'uint32', | |||||
'newOffset' => 'uint32', | |||||
'newLen' => 'uint32', | |||||
), | |||||
self::CONFIG_KEY_SCHEMA => array( | |||||
'key_changeset' => array( | |||||
'columns' => array('changesetID'), | |||||
), | |||||
'key_created' => array( | |||||
'columns' => array('dateCreated'), | |||||
), | |||||
), | |||||
) + parent::getConfiguration(); | |||||
} | |||||
public function getAddedLines() { | public function getAddedLines() { | ||||
return $this->makeContent($include = '+'); | return $this->makeContent($include = '+'); | ||||
} | } | ||||
public function getRemovedLines() { | public function getRemovedLines() { | ||||
return $this->makeContent($include = '-'); | return $this->makeContent($include = '-'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | public function getChangeset() { | ||||
return $this->assertAttached($this->changeset); | return $this->assertAttached($this->changeset); | ||||
} | } | ||||
public function attachChangeset(DifferentialChangeset $changeset) { | public function attachChangeset(DifferentialChangeset $changeset) { | ||||
$this->changeset = $changeset; | $this->changeset = $changeset; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setChanges($text) { | |||||
$this->rawData = $text; | |||||
$this->dataEncoding = $this->detectEncodingForStorage($text); | |||||
$this->dataType = self::DATATYPE_TEXT; | |||||
$this->dataFormat = self::DATAFORMAT_RAW; | |||||
$this->data = $text; | |||||
return $this; | |||||
} | |||||
public function getChanges() { | |||||
return $this->getUTF8StringFromStorage( | |||||
$this->getRawData(), | |||||
nonempty($this->forcedEncoding, $this->getDataEncoding())); | |||||
} | |||||
public function forceEncoding($encoding) { | |||||
$this->forcedEncoding = $encoding; | |||||
return $this; | |||||
} | |||||
public function save() { | |||||
$type = $this->getDataType(); | |||||
$format = $this->getDataFormat(); | |||||
// Before saving the data, attempt to compress it. | |||||
if ($type == self::DATATYPE_TEXT) { | |||||
if ($format == self::DATAFORMAT_RAW) { | |||||
$data = $this->getData(); | |||||
$deflated = PhabricatorCaches::maybeDeflateData($data); | |||||
if ($deflated !== null) { | |||||
$this->data = $deflated; | |||||
$this->dataFormat = self::DATAFORMAT_DEFLATED; | |||||
} | |||||
} | |||||
} | |||||
return parent::save(); | |||||
} | |||||
private function getRawData() { | |||||
if ($this->rawData === null) { | |||||
$type = $this->getDataType(); | |||||
$data = $this->getData(); | |||||
switch ($type) { | |||||
case self::DATATYPE_TEXT: | |||||
// In this storage type, the changes are stored on the object. | |||||
$data = $data; | |||||
break; | |||||
case self::DATATYPE_FILE: | |||||
default: | |||||
throw new Exception( | |||||
pht('Hunk has unsupported data type "%s"!', $type)); | |||||
} | |||||
$format = $this->getDataFormat(); | |||||
switch ($format) { | |||||
case self::DATAFORMAT_RAW: | |||||
// In this format, the changes are stored as-is. | |||||
$data = $data; | |||||
break; | |||||
case self::DATAFORMAT_DEFLATED: | |||||
$data = PhabricatorCaches::inflateData($data); | |||||
break; | |||||
default: | |||||
throw new Exception( | |||||
pht('Hunk has unsupported data encoding "%s"!', $type)); | |||||
} | |||||
$this->rawData = $data; | |||||
} | |||||
return $this->rawData; | |||||
} | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
); | ); | ||||
Show All 15 Lines |