From 68d80e162a8c68eecb888f5f1df8cfcfa54ccd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Mon, 25 Jun 2012 15:23:54 +0200 Subject: [PATCH] fixes #801 show logs in --verbose mode for source packages --- src/Composer/Downloader/GitDownloader.php | 11 +++++++++ src/Composer/Downloader/HgDownloader.php | 11 +++++++++ src/Composer/Downloader/SvnDownloader.php | 11 +++++++++ src/Composer/Downloader/VcsDownloader.php | 28 ++++++++++++++++++++++- 4 files changed, 60 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/Composer/Downloader/GitDownloader.php mode change 100644 => 100755 src/Composer/Downloader/HgDownloader.php mode change 100644 => 100755 src/Composer/Downloader/SvnDownloader.php mode change 100644 => 100755 src/Composer/Downloader/VcsDownloader.php diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php old mode 100644 new mode 100755 index 756218da5..d00aea793 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -224,4 +224,15 @@ class GitDownloader extends VcsDownloader $this->process->execute($cmd, $ignoredOutput, $path); } } + + protected function getCommitLogs($sourceReference, $targetReference, $path) + { + $command = sprintf('cd %s && git log %s..%s --pretty=format:"%%h - %%an: %%s"', escapeshellarg($path), $sourceReference, $targetReference); + + if (0 !== $this->process->execute($command, $output)) { + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); + } + + return $output; + } } diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php old mode 100644 new mode 100755 index 7dc845a98..6e0e7401b --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -59,4 +59,15 @@ class HgDownloader extends VcsDownloader throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes'); } } + + protected function getCommitLogs($sourceReference, $targetReference, $path) + { + $command = sprintf('cd %s && hg log -r %s:%s --style compact', escapeshellarg($path), $sourceReference, $targetReference); + + if (0 !== $this->process->execute($command, $output)) { + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); + } + + return $output; + } } diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php old mode 100644 new mode 100755 index 63f654221..2f968ed57 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -79,4 +79,15 @@ class SvnDownloader extends VcsDownloader ); } } + + protected function getCommitLogs($sourceReference, $targetReference, $path) + { + $command = sprintf('cd %s && svn log -r%s:%s --incremental', escapeshellarg($path), $sourceReference, $targetReference); + + if (0 !== $this->process->execute($command, $output)) { + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); + } + + return $output; + } } diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php old mode 100644 new mode 100755 index d7c9f20c5..ccf7cb74b --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -65,9 +65,25 @@ abstract class VcsDownloader implements DownloaderInterface throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information'); } - $this->io->write(" - Updating " . $target->getName() . " (" . $target->getPrettyVersion() . ")"); + if ($initial->getPrettyVersion() == $target->getPrettyVersion()) { + $from = $initial->getSourceReference(); + $to = $target->getSourceReference(); + } else { + $from = $initial->getPrettyVersion(); + $to = $target->getPrettyVersion(); + } + + $this->io->write(" - Updating " . $target->getName() . " from (" . $from . ") to (" . $to . ")"); + $this->enforceCleanDirectory($path); $this->doUpdate($initial, $target, $path); + + //print the commit logs if in verbose mode + if ($this->io->isVerbose()) { + $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path); + $this->io->write($logs); + } + $this->io->write(''); } @@ -106,4 +122,14 @@ abstract class VcsDownloader implements DownloaderInterface * @throws \RuntimeException if the directory is not clean */ abstract protected function enforceCleanDirectory($path); + + /** + * fetches the commit logs between to commits + * + * @param string $sourceReference the source reference + * @param string $targetReference the target reference + * @param string $path the package path + * @return string + */ + abstract protected function getCommitLogs($sourceReference, $targetReference, $path); }