PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/applications/diffusion/data/pathchange/DiffusionPathChange.php

http://github.com/facebook/phabricator
PHP | 166 lines | 121 code | 30 blank | 15 comment | 5 complexity | ec6683eaa3716afdcda05f956cb2858c MD5 | raw file
Possible License(s): JSON, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause, LGPL-2.0, MIT, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * Copyright 2011 Facebook, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. final class DiffusionPathChange {
  18. private $path;
  19. private $commitIdentifier;
  20. private $commit;
  21. private $commitData;
  22. private $changeType;
  23. private $fileType;
  24. private $targetPath;
  25. private $targetCommitIdentifier;
  26. private $awayPaths = array();
  27. final public function setPath($path) {
  28. $this->path = $path;
  29. return $this;
  30. }
  31. final public function getPath() {
  32. return $this->path;
  33. }
  34. public function setChangeType($change_type) {
  35. $this->changeType = $change_type;
  36. return $this;
  37. }
  38. public function getChangeType() {
  39. return $this->changeType;
  40. }
  41. public function setFileType($file_type) {
  42. $this->fileType = $file_type;
  43. return $this;
  44. }
  45. public function getFileType() {
  46. return $this->fileType;
  47. }
  48. public function setTargetPath($target_path) {
  49. $this->targetPath = $target_path;
  50. return $this;
  51. }
  52. public function getTargetPath() {
  53. return $this->targetPath;
  54. }
  55. public function setAwayPaths(array $away_paths) {
  56. $this->awayPaths = $away_paths;
  57. return $this;
  58. }
  59. public function getAwayPaths() {
  60. return $this->awayPaths;
  61. }
  62. final public function setCommitIdentifier($commit) {
  63. $this->commitIdentifier = $commit;
  64. return $this;
  65. }
  66. final public function getCommitIdentifier() {
  67. return $this->commitIdentifier;
  68. }
  69. final public function setTargetCommitIdentifier($target_commit_identifier) {
  70. $this->targetCommitIdentifier = $target_commit_identifier;
  71. return $this;
  72. }
  73. final public function getTargetCommitIdentifier() {
  74. return $this->targetCommitIdentifier;
  75. }
  76. final public function setCommit($commit) {
  77. $this->commit = $commit;
  78. return $this;
  79. }
  80. final public function getCommit() {
  81. return $this->commit;
  82. }
  83. final public function setCommitData($commit_data) {
  84. $this->commitData = $commit_data;
  85. return $this;
  86. }
  87. final public function getCommitData() {
  88. return $this->commitData;
  89. }
  90. final public function getEpoch() {
  91. if ($this->getCommit()) {
  92. return $this->getCommit()->getEpoch();
  93. }
  94. return null;
  95. }
  96. final public function getAuthorName() {
  97. if ($this->getCommitData()) {
  98. return $this->getCommitData()->getAuthorName();
  99. }
  100. return null;
  101. }
  102. final public function getSummary() {
  103. if (!$this->getCommitData()) {
  104. return null;
  105. }
  106. $message = $this->getCommitData()->getCommitMessage();
  107. $first = idx(explode("\n", $message), 0);
  108. return substr($first, 0, 80);
  109. }
  110. final public static function convertToArcanistChanges(array $changes) {
  111. $direct = array();
  112. $result = array();
  113. foreach ($changes as $path) {
  114. $change = new ArcanistDiffChange();
  115. $change->setCurrentPath($path->getPath());
  116. $direct[] = $path->getPath();
  117. $change->setType($path->getChangeType());
  118. $file_type = $path->getFileType();
  119. if ($file_type == DifferentialChangeType::FILE_NORMAL) {
  120. $file_type = DifferentialChangeType::FILE_TEXT;
  121. }
  122. $change->setFileType($file_type);
  123. $change->setOldPath($path->getTargetPath());
  124. foreach ($path->getAwayPaths() as $away_path) {
  125. $change->addAwayPath($away_path);
  126. }
  127. $result[$path->getPath()] = $change;
  128. }
  129. return array_select_keys($result, $direct);
  130. }
  131. final public static function convertToDifferentialChangesets(array $changes) {
  132. $arcanist_changes = self::convertToArcanistChanges($changes);
  133. $diff = DifferentialDiff::newFromRawChanges($arcanist_changes);
  134. return $diff->getChangesets();
  135. }
  136. }