Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistExportWorkflow.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Exports changes from Differential or the working copy to a file. | * Exports changes from Differential or the working copy to a file. | ||||
| * | |||||
| * @group workflow | |||||
| */ | */ | ||||
| final class ArcanistExportWorkflow extends ArcanistBaseWorkflow { | final class ArcanistExportWorkflow extends ArcanistBaseWorkflow { | ||||
| const SOURCE_LOCAL = 'local'; | const SOURCE_LOCAL = 'local'; | ||||
| const SOURCE_DIFF = 'diff'; | const SOURCE_DIFF = 'diff'; | ||||
| const SOURCE_REVISION = 'revision'; | const SOURCE_REVISION = 'revision'; | ||||
| const FORMAT_GIT = 'git'; | const FORMAT_GIT = 'git'; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | return array( | ||||
| 'help' => | 'help' => | ||||
| 'Instead of exporting changes from the working copy, export them '. | 'Instead of exporting changes from the working copy, export them '. | ||||
| 'from a Differential diff.' | 'from a Differential diff.' | ||||
| ), | ), | ||||
| '*' => 'paths', | '*' => 'paths', | ||||
| ); | ); | ||||
| } | } | ||||
| protected function didParseArguments() { | protected function didParseArguments() { | ||||
| $source = self::SOURCE_LOCAL; | $source = self::SOURCE_LOCAL; | ||||
| $requested = 0; | $requested = 0; | ||||
| if ($this->getArgument('revision')) { | if ($this->getArgument('revision')) { | ||||
| $source = self::SOURCE_REVISION; | $source = self::SOURCE_REVISION; | ||||
| $requested++; | $requested++; | ||||
| $source_id = $this->getArgument($source); | $source_id = $this->getArgument($source); | ||||
| $this->sourceID = $this->normalizeRevisionID($source_id); | $this->sourceID = $this->normalizeRevisionID($source_id); | ||||
| } | } | ||||
| if ($this->getArgument('diff')) { | if ($this->getArgument('diff')) { | ||||
| $source = self::SOURCE_DIFF; | $source = self::SOURCE_DIFF; | ||||
| $requested++; | $requested++; | ||||
| $this->sourceID = $this->getArgument($source); | $this->sourceID = $this->getArgument($source); | ||||
| } | } | ||||
| $this->source = $source; | $this->source = $source; | ||||
| if ($requested > 1) { | if ($requested > 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Options '--revision' and '--diff' are not compatible. Choose exactly ". | "Options '--revision' and '--diff' are not compatible. Choose exactly ". | ||||
| "one change source."); | "one change source."); | ||||
| } | } | ||||
| $format = null; | $format = null; | ||||
| $requested = 0; | $requested = 0; | ||||
| if ($this->getArgument('git')) { | if ($this->getArgument('git')) { | ||||
| $format = self::FORMAT_GIT; | $format = self::FORMAT_GIT; | ||||
| $requested++; | $requested++; | ||||
| } | } | ||||
| if ($this->getArgument('unified')) { | if ($this->getArgument('unified')) { | ||||
| $format = self::FORMAT_UNIFIED; | $format = self::FORMAT_UNIFIED; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | private function getSourceID() { | ||||
| return $this->sourceID; | return $this->sourceID; | ||||
| } | } | ||||
| private function getFormat() { | private function getFormat() { | ||||
| return $this->format; | return $this->format; | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
| $source = $this->getSource(); | $source = $this->getSource(); | ||||
| switch ($source) { | switch ($source) { | ||||
| case self::SOURCE_LOCAL: | case self::SOURCE_LOCAL: | ||||
| $repository_api = $this->getRepositoryAPI(); | $repository_api = $this->getRepositoryAPI(); | ||||
| $parser = new ArcanistDiffParser(); | $parser = new ArcanistDiffParser(); | ||||
| $parser->setRepositoryAPI($repository_api); | $parser->setRepositoryAPI($repository_api); | ||||
| Show All 34 Lines | switch ($source) { | ||||
| $paths); | $paths); | ||||
| $author = $this->getUserName(); | $author = $this->getUserName(); | ||||
| } | } | ||||
| $bundle = ArcanistBundle::newFromChanges($changes); | $bundle = ArcanistBundle::newFromChanges($changes); | ||||
| $bundle->setProjectID($this->getWorkingCopy()->getProjectID()); | $bundle->setProjectID($this->getWorkingCopy()->getProjectID()); | ||||
| $bundle->setBaseRevision( | $bundle->setBaseRevision( | ||||
| $repository_api->getSourceControlBaseRevision()); | $repository_api->getSourceControlBaseRevision()); | ||||
| // note we can't get a revision ID for SOURCE_LOCAL | // NOTE: we can't get a revision ID for SOURCE_LOCAL | ||||
| $parser = new PhutilEmailAddress($author); | $parser = new PhutilEmailAddress($author); | ||||
| $bundle->setAuthorName($parser->getDisplayName()); | $bundle->setAuthorName($parser->getDisplayName()); | ||||
| $bundle->setAuthorEmail($parser->getAddress()); | $bundle->setAuthorEmail($parser->getAddress()); | ||||
| break; | break; | ||||
| case self::SOURCE_REVISION: | case self::SOURCE_REVISION: | ||||
| $bundle = $this->loadRevisionBundleFromConduit( | $bundle = $this->loadRevisionBundleFromConduit( | ||||
| $this->getConduit(), | $this->getConduit(), | ||||
| Show All 38 Lines | switch ($format) { | ||||
| echo "Writing bundle to '{$path}'...\n"; | echo "Writing bundle to '{$path}'...\n"; | ||||
| $bundle->writeToDisk($path); | $bundle->writeToDisk($path); | ||||
| echo "done.\n"; | echo "done.\n"; | ||||
| break; | break; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||