Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HgDownloader.php

class HgDownloader

@author Per Bernhardt <plb@webfactory.de>

Hierarchy

  • class \Composer\Downloader\VcsDownloader implements \Composer\Downloader\DownloaderInterface, \Composer\Downloader\ChangeReportInterface, \Composer\Downloader\VcsCapableDownloaderInterface
    • class \Composer\Downloader\HgDownloader extends \Composer\Downloader\VcsDownloader

Expanded class hierarchy of HgDownloader

File

vendor/composer/composer/src/Composer/Downloader/HgDownloader.php, line 23

Namespace

Composer\Downloader
View source
class HgDownloader extends VcsDownloader {
    
    /**
     * @inheritDoc
     */
    protected function doDownload(PackageInterface $package, string $path, string $url, ?PackageInterface $prevPackage = null) : PromiseInterface {
        if (null === HgUtils::getVersion($this->process)) {
            throw new \RuntimeException('hg was not found in your PATH, skipping source download');
        }
        return \React\Promise\resolve(null);
    }
    
    /**
     * @inheritDoc
     */
    protected function doInstall(PackageInterface $package, string $path, string $url) : PromiseInterface {
        $hgUtils = new HgUtils($this->io, $this->config, $this->process);
        $cloneCommand = static function (string $url) use ($path) : array {
            return [
                'hg',
                'clone',
                '--',
                $url,
                $path,
            ];
        };
        $hgUtils->runCommand($cloneCommand, $url, $path);
        $command = [
            'hg',
            'up',
            '--',
            (string) $package->getSourceReference(),
        ];
        if (0 !== $this->process
            ->execute($command, $ignoredOutput, realpath($path))) {
            throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process
                ->getErrorOutput());
        }
        return \React\Promise\resolve(null);
    }
    
    /**
     * @inheritDoc
     */
    protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url) : PromiseInterface {
        $hgUtils = new HgUtils($this->io, $this->config, $this->process);
        $ref = $target->getSourceReference();
        $this->io
            ->writeError(" Updating to " . $target->getSourceReference());
        if (!$this->hasMetadataRepository($path)) {
            throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information');
        }
        $command = static function ($url) : array {
            return [
                'hg',
                'pull',
                '--',
                $url,
            ];
        };
        $hgUtils->runCommand($command, $url, $path);
        $command = static function () use ($ref) : array {
            return [
                'hg',
                'up',
                '--',
                $ref,
            ];
        };
        $hgUtils->runCommand($command, $url, $path);
        return \React\Promise\resolve(null);
    }
    
    /**
     * @inheritDoc
     */
    public function getLocalChanges(PackageInterface $package, string $path) : ?string {
        if (!is_dir($path . '/.hg')) {
            return null;
        }
        $this->process
            ->execute([
            'hg',
            'st',
        ], $output, realpath($path));
        $output = trim($output);
        return strlen($output) > 0 ? $output : null;
    }
    
    /**
     * @inheritDoc
     */
    protected function getCommitLogs(string $fromReference, string $toReference, string $path) : string {
        $command = [
            'hg',
            'log',
            '-r',
            $fromReference . ':' . $toReference,
            '--style',
            'compact',
        ];
        if (0 !== $this->process
            ->execute($command, $output, realpath($path))) {
            throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process
                ->getErrorOutput());
        }
        return $output;
    }
    
    /**
     * @inheritDoc
     */
    protected function hasMetadataRepository(string $path) : bool {
        return is_dir($path . '/.hg');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
HgDownloader::doDownload protected function @inheritDoc Overrides VcsDownloader::doDownload
HgDownloader::doInstall protected function @inheritDoc Overrides VcsDownloader::doInstall
HgDownloader::doUpdate protected function @inheritDoc Overrides VcsDownloader::doUpdate
HgDownloader::getCommitLogs protected function @inheritDoc Overrides VcsDownloader::getCommitLogs
HgDownloader::getLocalChanges public function @inheritDoc Overrides ChangeReportInterface::getLocalChanges
HgDownloader::hasMetadataRepository protected function @inheritDoc Overrides VcsDownloader::hasMetadataRepository
VcsDownloader::$config protected property @var Config
VcsDownloader::$filesystem protected property @var Filesystem
VcsDownloader::$hasCleanedChanges protected property @var array&lt;string, true&gt;
VcsDownloader::$io protected property @var IOInterface
VcsDownloader::$process protected property @var ProcessExecutor
VcsDownloader::cleanChanges protected function Prompt the user to check if changes should be stashed/removed or the operation aborted 2
VcsDownloader::cleanup public function @inheritDoc Overrides DownloaderInterface::cleanup
VcsDownloader::download public function @inheritDoc Overrides DownloaderInterface::download
VcsDownloader::getInstallationSource public function @inheritDoc Overrides DownloaderInterface::getInstallationSource
VcsDownloader::getVcsReference public function @inheritDoc Overrides VcsCapableDownloaderInterface::getVcsReference
VcsDownloader::install public function @inheritDoc Overrides DownloaderInterface::install
VcsDownloader::prepare public function @inheritDoc Overrides DownloaderInterface::prepare
VcsDownloader::prepareUrls private function
VcsDownloader::reapplyChanges protected function Reapply previously stashes changes if applicable, only called after an update (regardless if successful or not) 1
VcsDownloader::remove public function @inheritDoc Overrides DownloaderInterface::remove
VcsDownloader::update public function @inheritDoc Overrides DownloaderInterface::update
VcsDownloader::__construct public function 1

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal