Changeset View
Changeset View
Standalone View
Standalone View
src/parser/ArcanistBundle.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Converts changesets between different formats. | * Converts changesets between different formats. | ||||
| * | |||||
| * @group diff | |||||
| */ | */ | ||||
| final class ArcanistBundle { | final class ArcanistBundle { | ||||
| private $changes; | private $changes; | ||||
| private $conduit; | private $conduit; | ||||
| private $blobs = array(); | private $blobs = array(); | ||||
| private $diskPath; | private $diskPath; | ||||
| private $projectID; | private $projectID; | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | final class ArcanistBundle { | ||||
| public static function newFromChanges(array $changes) { | public static function newFromChanges(array $changes) { | ||||
| $obj = new ArcanistBundle(); | $obj = new ArcanistBundle(); | ||||
| $obj->changes = $changes; | $obj->changes = $changes; | ||||
| return $obj; | return $obj; | ||||
| } | } | ||||
| private function getEOL($patch_type) { | private function getEOL($patch_type) { | ||||
| // NOTE: Git always generates "\n" line endings, even under Windows, and | // NOTE: Git always generates "\n" line endings, even under Windows, and | ||||
| // can not parse certain patches with "\r\n" line endings. SVN generates | // can not parse certain patches with "\r\n" line endings. SVN generates | ||||
| // patches with "\n" line endings on Mac or Linux and "\r\n" line endings | // patches with "\n" line endings on Mac or Linux and "\r\n" line endings | ||||
| // on Windows. (This EOL style is used only for patch metadata lines, not | // on Windows. (This EOL style is used only for patch metadata lines, not | ||||
| // for the actual patch content.) | // for the actual patch content.) | ||||
| // (On Windows, Mercurial generates \n newlines for `--git` diffs, as it | // (On Windows, Mercurial generates \n newlines for `--git` diffs, as it | ||||
| // must, but also \n newlines for unified diffs. We never need to deal with | // must, but also \n newlines for unified diffs. We never need to deal with | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public static function newFromDiff($data) { | ||||
| $obj = new ArcanistBundle(); | $obj = new ArcanistBundle(); | ||||
| $parser = new ArcanistDiffParser(); | $parser = new ArcanistDiffParser(); | ||||
| $obj->changes = $parser->parseDiff($data); | $obj->changes = $parser->parseDiff($data); | ||||
| return $obj; | return $obj; | ||||
| } | } | ||||
| private function __construct() { | private function __construct() {} | ||||
| } | |||||
| public function writeToDisk($path) { | public function writeToDisk($path) { | ||||
| $changes = $this->getChanges(); | $changes = $this->getChanges(); | ||||
| $change_list = array(); | $change_list = array(); | ||||
| foreach ($changes as $change) { | foreach ($changes as $change) { | ||||
| $change_list[] = $change->toDictionary(); | $change_list[] = $change->toDictionary(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public function writeToDisk($path) { | ||||
| execx( | execx( | ||||
| '(cd %s; tar -czf %s *)', | '(cd %s; tar -czf %s *)', | ||||
| $dir, | $dir, | ||||
| Filesystem::resolvePath($path)); | Filesystem::resolvePath($path)); | ||||
| Filesystem::remove($dir); | Filesystem::remove($dir); | ||||
| } | } | ||||
| public function toUnifiedDiff() { | public function toUnifiedDiff() { | ||||
| $eol = $this->getEOL('unified'); | $eol = $this->getEOL('unified'); | ||||
| $result = array(); | $result = array(); | ||||
| $changes = $this->getChanges(); | $changes = $this->getChanges(); | ||||
| foreach ($changes as $change) { | foreach ($changes as $change) { | ||||
| $hunk_changes = $this->buildHunkChanges($change->getHunks(), $eol); | $hunk_changes = $this->buildHunkChanges($change->getHunks(), $eol); | ||||
| if (!$hunk_changes) { | if (!$hunk_changes) { | ||||
| ▲ Show 20 Lines • Show All 604 Lines • Show Last 20 Lines | |||||