From 7fdcdb4c54bb22ac76794ba9e4e59831e4cd80cf Mon Sep 17 00:00:00 2001 From: matt-whittom Date: Mon, 12 Aug 2013 13:28:09 -0500 Subject: [PATCH] Updated to complete functionality in Downloader to handle updates, returning change logs. --- .../Downloader/PerforceDownloader.php | 15 +++++---- src/Composer/Util/Perforce.php | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 5ed241d79..c7ca64ec1 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -22,6 +22,7 @@ use Composer\Util\Perforce; class PerforceDownloader extends VcsDownloader { protected $perforce; + protected $perforceInjected = false; /** * {@inheritDoc} @@ -31,6 +32,7 @@ class PerforceDownloader extends VcsDownloader $ref = $package->getSourceReference(); $label = $package->getPrettyVersion(); + $this->io->write(" Cloning ".$ref); $this->initPerforce($package, $path); $this->perforce->setStream($ref); $this->perforce->queryP4User($this->io); @@ -40,7 +42,7 @@ class PerforceDownloader extends VcsDownloader } private function initPerforce($package, $path){ - if (isset($this->perforce)){ + if ($this->perforceInjected){ return; } $repository = $package->getRepository(); @@ -50,6 +52,7 @@ class PerforceDownloader extends VcsDownloader public function injectPerforce($perforce){ $this->perforce = $perforce; + $this->perforceInjected = true; } private function getRepoConfig(VcsRepository $repository){ @@ -62,7 +65,7 @@ class PerforceDownloader extends VcsDownloader public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { print("PerforceDownloader:doUpdate\n"); - throw new Exception("Unsupported Operation: PerforceDownloader:doUpdate"); + $this->doDownload($target, $path); } /** @@ -70,8 +73,8 @@ class PerforceDownloader extends VcsDownloader */ public function getLocalChanges($path) { - print("PerforceDownloader:getLocalChanges\n"); - throw new Exception("Unsupported Operation: PerforceDownloader:getLocalChanges"); + print ("Perforce driver does not check for local changes before overriding\n"); + return; } @@ -80,8 +83,8 @@ class PerforceDownloader extends VcsDownloader */ protected function getCommitLogs($fromReference, $toReference, $path) { - print("PerforceDownloader:getCommitLogs\n"); - throw new Exception("Unsupported Operation: PerforceDownloader:getCommitLogs"); + $commitLogs = $this->perforce->getCommitLogs($fromReference, $toReference); + return $commitLogs; } } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 5b032b71b..7a9e26643 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -437,4 +437,35 @@ class Perforce { return FALSE; } + + protected function getChangeList($reference){ + $index = strpos($reference, "@"); + if ($index === false){ + return; + } + $label = substr($reference, $index); + $command = $this->generateP4Command(" changes -m1 $label"); + $changes = $this->executeCommand($command); + if (strpos($changes, "Change") !== 0){ + return; + } + $fields = explode(" ", $changes); + $changeList = $fields[1]; + return $changeList; + } + public function getCommitLogs($fromReference, $toReference){ + $fromChangeList = $this->getChangeList($fromReference); + if ($fromChangeList == null){ + return; + } + $toChangeList = $this->getChangeList($toReference); + if ($toChangeList == null){ + return; + } + $index = strpos($fromReference, "@"); + $main = substr($fromReference, 0, $index) . "/..."; + $command = $this->generateP4Command("filelog $main@$fromChangeList,$toChangeList"); + $result = $this->executeCommand($command); + return $result; + } } \ No newline at end of file