Path: blob/master/src/applications/diffusion/data/DiffusionPathChange.php
12241 views
<?php12final class DiffusionPathChange extends Phobject {34private $path;5private $commitIdentifier;6private $commit;7private $commitData;89private $changeType;10private $fileType;11private $targetPath;12private $targetCommitIdentifier;13private $awayPaths = array();1415public function setPath($path) {16$this->path = $path;17return $this;18}1920public function getPath() {21return $this->path;22}2324public function setChangeType($change_type) {25$this->changeType = $change_type;26return $this;27}2829public function getChangeType() {30return $this->changeType;31}3233public function setFileType($file_type) {34$this->fileType = $file_type;35return $this;36}3738public function getFileType() {39return $this->fileType;40}4142public function setTargetPath($target_path) {43$this->targetPath = $target_path;44return $this;45}4647public function getTargetPath() {48return $this->targetPath;49}5051public function setAwayPaths(array $away_paths) {52$this->awayPaths = $away_paths;53return $this;54}5556public function getAwayPaths() {57return $this->awayPaths;58}5960public function setCommitIdentifier($commit) {61$this->commitIdentifier = $commit;62return $this;63}6465public function getCommitIdentifier() {66return $this->commitIdentifier;67}6869public function setTargetCommitIdentifier($target_commit_identifier) {70$this->targetCommitIdentifier = $target_commit_identifier;71return $this;72}7374public function getTargetCommitIdentifier() {75return $this->targetCommitIdentifier;76}7778public function setCommit($commit) {79$this->commit = $commit;80return $this;81}8283public function getCommit() {84return $this->commit;85}8687public function setCommitData($commit_data) {88$this->commitData = $commit_data;89return $this;90}9192public function getCommitData() {93return $this->commitData;94}959697public function getEpoch() {98if ($this->getCommit()) {99return $this->getCommit()->getEpoch();100}101return null;102}103104public function getAuthorName() {105if ($this->getCommitData()) {106return $this->getCommitData()->getAuthorString();107}108return null;109}110111public function getSummary() {112if (!$this->getCommitData()) {113return null;114}115return $this->getCommitData()->getSummary();116}117118public static function convertToArcanistChanges(array $changes) {119assert_instances_of($changes, __CLASS__);120$direct = array();121$result = array();122foreach ($changes as $path) {123$change = new ArcanistDiffChange();124$change->setCurrentPath($path->getPath());125$direct[] = $path->getPath();126$change->setType($path->getChangeType());127$file_type = $path->getFileType();128if ($file_type == DifferentialChangeType::FILE_NORMAL) {129$file_type = DifferentialChangeType::FILE_TEXT;130}131$change->setFileType($file_type);132$change->setOldPath($path->getTargetPath());133foreach ($path->getAwayPaths() as $away_path) {134$change->addAwayPath($away_path);135}136$result[$path->getPath()] = $change;137}138139return array_select_keys($result, $direct);140}141142public static function convertToDifferentialChangesets(143PhabricatorUser $user,144array $changes) {145assert_instances_of($changes, __CLASS__);146$arcanist_changes = self::convertToArcanistChanges($changes);147$diff = DifferentialDiff::newEphemeralFromRawChanges(148$arcanist_changes);149return $diff->getChangesets();150}151152public function toDictionary() {153$commit = $this->getCommit();154if ($commit) {155$commit_dict = $commit->toDictionary();156} else {157$commit_dict = array();158}159$commit_data = $this->getCommitData();160if ($commit_data) {161$commit_data_dict = $commit_data->toDictionary();162} else {163$commit_data_dict = array();164}165return array(166'path' => $this->getPath(),167'commitIdentifier' => $this->getCommitIdentifier(),168'commit' => $commit_dict,169'commitData' => $commit_data_dict,170'fileType' => $this->getFileType(),171'changeType' => $this->getChangeType(),172'targetPath' => $this->getTargetPath(),173'targetCommitIdentifier' => $this->getTargetCommitIdentifier(),174'awayPaths' => $this->getAwayPaths(),175);176}177178public static function newFromConduit(array $dicts) {179$results = array();180foreach ($dicts as $dict) {181$commit = PhabricatorRepositoryCommit::newFromDictionary($dict['commit']);182$commit_data =183PhabricatorRepositoryCommitData::newFromDictionary(184$dict['commitData']);185$results[] = id(new DiffusionPathChange())186->setPath($dict['path'])187->setCommitIdentifier($dict['commitIdentifier'])188->setCommit($commit)189->setCommitData($commit_data)190->setFileType($dict['fileType'])191->setChangeType($dict['changeType'])192->setTargetPath($dict['targetPath'])193->setTargetCommitIdentifier($dict['targetCommitIdentifier'])194->setAwayPaths($dict['awayPaths']);195}196return $results;197}198199}200201202