From 8dfe45a026073d641693955efcf4c234063c32c4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 16 Jan 2021 22:26:20 +0100 Subject: [PATCH 1/2] GitDownloader: combine checkout + reset commands into a single process use a single process instead of 3 to improve performance --- src/Composer/Downloader/GitDownloader.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index e43163dd0..dd8a7d873 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -454,13 +454,10 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface $command = sprintf('git checkout %s --', ProcessExecutor::escape($branch)); $fallbackCommand = sprintf('git checkout '.$force.'-B %s %s --', ProcessExecutor::escape($branch), ProcessExecutor::escape('composer/'.$branch)); - if (0 === $this->process->execute($command, $output, $path) - || 0 === $this->process->execute($fallbackCommand, $output, $path) - ) { - $command = sprintf('git reset --hard %s --', ProcessExecutor::escape($reference)); - if (0 === $this->process->execute($command, $output, $path)) { - return null; - } + $resetCommand = sprintf('git reset --hard %s --', ProcessExecutor::escape($reference)); + + if (0 === $this->process->execute("($command || $fallbackCommand) && $resetCommand", $output, $path)) { + return null; } } From 4a6f1792ea5a9f89b214f742a2b4dcfa6efb36b6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 18 Jan 2021 10:11:08 +0100 Subject: [PATCH 2/2] adjusted test expectations --- .../Composer/Test/Downloader/GitDownloaderTest.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 2de8f329f..c16c925b6 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -122,12 +122,7 @@ class GitDownloaderTest extends TestCase $processExecutor->expects($this->at(2)) ->method('execute') - ->with($this->equalTo($this->winCompat("git checkout 'master' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) - ->will($this->returnValue(0)); - - $processExecutor->expects($this->at(3)) - ->method('execute') - ->with($this->equalTo($this->winCompat("git reset --hard '1234567890123456789012345678901234567890' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) + ->with($this->equalTo($this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) ->will($this->returnValue(0)); $downloader = $this->getDownloaderMock(null, null, $processExecutor); @@ -198,12 +193,7 @@ class GitDownloaderTest extends TestCase $processExecutor->expects($this->at(5)) ->method('execute') - ->with($this->equalTo($this->winCompat("git checkout 'master' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) - ->will($this->returnValue(0)); - - $processExecutor->expects($this->at(6)) - ->method('execute') - ->with($this->equalTo($this->winCompat("git reset --hard '1234567890123456789012345678901234567890' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) + ->with($this->equalTo($this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) ->will($this->returnValue(0)); $downloader = $this->getDownloaderMock(null, $config, $processExecutor);