-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Faster git clones using cache #5384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster git clones using cache #5384
Conversation
Also added home dir to default initial settings
Added the usage of dissociate so that the repos work properly even if the cache gets deleted after the clone
When creating a DownloaderMock a home config dir is ensured to exist, so that no test fails for lack of it that on a regular run would be set by the Factory
src/Composer/Util/Git.php
Outdated
| if (0 !== $this->process->execute('git --version', $output)) { | ||
| throw new \RuntimeException(self::sanitizeUrl('Failed retrieve git version, git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput())); | ||
| } | ||
| if (strpos($output, 'git version ') === FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a regex instead to capture the version from the string and return it?
|
I see that the test cases were adjusted to work as if this new feature is not available. I would really like to see a test case that does the opposite (assume the feature is available). |
| $this->gitUtil->runCommand($mirrorCommandCallable, $url, $path, true); | ||
| } | ||
| } | ||
| $cacheOptions = file_exists($cachePath) ? '--dissociate --reference '.ProcessExecutor::escape($cachePath).' ' : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this check should be done inside the if(version_compare) check. The ternary operator could even be gone.
| if (0 !== $this->process->execute('git --version', $output)) { | ||
| throw new \RuntimeException(self::sanitizeUrl('Failed retrieve git version, git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput())); | ||
| } | ||
| if (preg_match('/^git version (.*)/', $output, $matches) !== 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this pattern is the best idea.. but it'll do for now.
|
|
||
| // --dissociate option is only available since git 2.3.0-rc0 | ||
| if (version_compare($this->gitUtil->getVersion(), '2.3.0-rc0', '>=')) { | ||
| if (!file_exists($cachePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not enought, we need to update the clone:
a) if the initial clone attempt failed (like on process timeout)
b) cache is out of date
In general, I think we need to always fetch the upstream to the cache if the directory already exists.
I tried #4685 but it seems to not being creating the git mirror, so I extended it a little, on top of @luisfaceira changes; I have also added a version check for git, given that the
--dissociateoption is only available since 2.3.0-rc0, which is not yet the default on some *nix distributions.PS: Please notice that this is my first attempt to read/modify composer, so I would be happy to rework this if needed.