Add support for git_reference.
authorCarl Hetherington <cth@carlh.net>
Thu, 4 Jun 2020 12:38:24 +0000 (14:38 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 4 Jun 2020 12:38:24 +0000 (14:38 +0200)
cdist

diff --git a/cdist b/cdist
index ae04483bc1255af59d5f24bad6f09e1a2e12b09a..bd64e77239c9663c5a28d1483121d93e484f3941 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -103,6 +103,7 @@ class Config:
     def __init__(self):
         self.options = [ Option('mxe_prefix'),
                          Option('git_prefix'),
+                         Option('git_reference'),
                          Option('osx_environment_prefix'),
                          Option('osx_sdk_prefix'),
                          Option('osx_sdk'),
@@ -901,7 +902,9 @@ class Tree(object):
         if globals.quiet:
             flags = '-q'
             redirect = '>/dev/null'
-        command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
+        if config.has('git_reference'):
+            ref = '--reference-if-able %s/%s.git' % (config.get('git_reference'), self.name)
+        command('git clone %s %s %s/%s.git %s/src/%s' % (flags, ref, config.get('git_prefix'), self.name, target.directory, self.name))
         os.chdir('%s/src/%s' % (target.directory, self.name))
 
         spec = self.specifier
@@ -917,9 +920,19 @@ class Tree(object):
         exec(open('%s/cscript' % proj).read(), self.cscript)
 
         # cscript can include submodules = False to stop submodules being fetched
-        if not 'submodules' in self.cscript or self.cscript['submodules'] == True:
-            command('git submodule init --quiet')
-            command('git submodule update --quiet')
+        if (not 'submodules' in self.cscript or self.cscript['submodules'] == True) and os.path.exists('.gitmodules'):
+            command('git submodule --quiet init')
+            paths = command_and_read('git config --file .gitmodules --get-regexp path')
+            urls = command_and_read('git config --file .gitmodules --get-regexp url')
+            for path, url in zip(paths, urls):
+                path = path.split(' ')[1]
+                url = url.split(' ')[1]
+            ref = ''
+            if config.has('git_reference'):
+                ref_path = os.path.join(config.get('git_reference'), os.path.basename(url))
+                if os.path.exists(ref_path):
+                    ref = '--reference %s' % ref_path
+            command('git submodule --quiet update %s %s' % (ref, path))
 
         if os.path.exists('%s/wscript' % proj):
             v = read_wscript_variable(proj, "VERSION");