Add support for `depth` option in wrap-git

This allows cloning subprojects shallowly.  It works recursively for a
subproject's submodules in case `clone-recursive` is set to `true`.
pull/5702/head
Christoph Weiss 6 years ago committed by Jussi Pakkanen
parent a65d5801f3
commit 0008b326ff
  1. 8
      docs/markdown/Wrap-dependency-system-manual.md
  2. 7
      docs/markdown/snippets/depth.md
  3. 19
      mesonbuild/wrap/wrap.py

@ -143,6 +143,14 @@ automatically by adding the following *(since 0.48.0)*:
clone-recursive = true
```
Setting the clone depth is supported using the `depth` directive *(since 0.52.0)*.
Note that git always allow shallowly cloning branches, but in order to clone commit ids
shallowly, the server must support `uploadpack.allowReachableSHA1InWant=true`.
```ini
depth = 1
```
## Using wrapped projects
Wraps provide a convenient way of obtaining a project into your subproject directory.

@ -0,0 +1,7 @@
## Add `depth` option to `wrap-git`
To allow shallow cloning, an option `depth` has been added to `wrap-git`.
This applies recursively to submodules when `clone-recursive` is set to `true`.
Note that the git server may have to be configured to support shallow cloning
not only for branches but also for tags.

@ -226,16 +226,21 @@ class Resolver:
self.apply_patch()
def get_git(self):
# git doesn't support directly cloning shallowly for commits,
# so we follow https://stackoverflow.com/a/43136160
subprocess.check_call(['git', 'init', self.directory], cwd=self.subdir_root)
subprocess.check_call(['git', 'remote', 'add', 'origin', self.wrap.get('url')],
cwd=self.dirname)
git_options = []
revno = self.wrap.get('revision')
subprocess.check_call(['git', 'clone', self.wrap.get('url'),
self.directory], cwd=self.subdir_root)
if revno.lower() != 'head':
if subprocess.call(['git', 'checkout', revno], cwd=self.dirname) != 0:
subprocess.check_call(['git', 'fetch', self.wrap.get('url'), revno], cwd=self.dirname)
subprocess.check_call(['git', 'checkout', revno], cwd=self.dirname)
if self.wrap.values.get('depth', '') != '':
git_options.extend(['--depth', self.wrap.values.get('depth')])
subprocess.check_call(['git', 'fetch'] + git_options + ['origin', revno],
cwd=self.dirname)
subprocess.check_call(['git', 'checkout', revno], cwd=self.dirname)
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
subprocess.check_call(['git', 'submodule', 'update',
'--init', '--checkout', '--recursive'],
'--init', '--checkout', '--recursive'] + git_options,
cwd=self.dirname)
push_url = self.wrap.values.get('push-url')
if push_url:

Loading…
Cancel
Save