diff options
author | Martin Hostettler <textshell@uchuujin.de> | 2019-10-05 12:14:16 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-10-06 14:29:32 +0300 |
commit | 507cf479411050b76dc8724de1b3b464b8f965e3 (patch) | |
tree | 6765ce0ac5be7f167e7e4b565d274d9721a5c6c1 | |
parent | 39342fbe2547337c721930a5892799dc7048caf8 (diff) | |
download | meson-507cf479411050b76dc8724de1b3b464b8f965e3.zip meson-507cf479411050b76dc8724de1b3b464b8f965e3.tar.gz meson-507cf479411050b76dc8724de1b3b464b8f965e3.tar.bz2 |
wrap: Rework `depth` support for git.
Don't manually emulate a partial `git clone` when `depth` option is not
used. This keeps `git describe` working as before and generally supports
workflows that depend on tags and branches to exist in a wrap downloaded
subproject.
This also fixes downloading via git not working at all on CentOS 7
(git version 1.8.3.1).
For the `depth` case use `git clone --branch=... --depth=...` when
possible and only fall back to manual emulation wraps that specify a
full commit id, because for some reason that does not work with the
clone based workflow.
Fixes: #5991 (Regression in wrap support with git)
-rw-r--r-- | mesonbuild/wrap/wrap.py | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 89bc307..8b19b6d 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -226,27 +226,56 @@ 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') - 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'] + git_options, + is_shallow = self.wrap.values.get('depth', '') != '' + # for some reason git only allows commit ids to be shallowly fetched by fetch not with clone + if is_shallow and self.is_git_full_commit_id(revno): + # 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) - push_url = self.wrap.values.get('push-url') - if push_url: - subprocess.check_call(['git', 'remote', 'set-url', - '--push', 'origin', push_url], + revno = self.wrap.get('revision') + subprocess.check_call(['git', 'fetch', '--depth', self.wrap.values.get('depth'), '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', '--depth', self.wrap.values.get('depth')], + cwd=self.dirname) + push_url = self.wrap.values.get('push-url') + if push_url: + subprocess.check_call(['git', 'remote', 'set-url', + '--push', 'origin', push_url], + cwd=self.dirname) + else: + if not is_shallow: + 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) + else: + subprocess.check_call(['git', 'clone', '--depth', self.wrap.values.get('depth'), + '--branch', revno, + self.wrap.get('url'), + self.directory], cwd=self.subdir_root) + if self.wrap.values.get('clone-recursive', '').lower() == 'true': + subprocess.check_call(['git', 'submodule', 'update', + '--init', '--checkout', '--recursive', '--depth', self.wrap.values.get('depth')], + cwd=self.dirname) + push_url = self.wrap.values.get('push-url') + if push_url: + subprocess.check_call(['git', 'remote', 'set-url', + '--push', 'origin', push_url], + cwd=self.dirname) + + def is_git_full_commit_id(self, revno): + result = False + if len(revno) in (40, 64): # 40 for sha1, 64 for upcoming sha256 + result = all((ch in '0123456789AaBbCcDdEeFf' for ch in revno)) + return result def get_hg(self): revno = self.wrap.get('revision') |