Adds support for setting .git/objects/info/alternates for component gits.
authorAshish Raj <ashish.raj@movial.com>
Fri, 5 Mar 2010 07:56:10 +0000 (09:56 +0200)
committerKalle Vahlman <kalle.vahlman@movial.com>
Fri, 5 Mar 2010 18:42:44 +0000 (20:42 +0200)
'--reference' option can be specified as remote/matrix/project/url::/path/to/local/matrix/project

matrix/git.py
matrix/matrix.py

index cca7e12..11db952 100644 (file)
@@ -146,12 +146,24 @@ def fetch_hash(url, branch):
 
 def clone(name, url, checkout=True):
        options = []
+       reference = []
        if not checkout:
                options = ['-n']
-
+       try:
+               if getattr(config, 'reference'):
+                       if url.rfind(config.reference[0]) is not -1:
+                               path = config.reference[1] + name.replace('/tmp','')
+                               if os.path.isdir(path + '/.git'):
+                                       reference = ['--reference', path]
+                               else:
+                                       print >>sys.stderr, 'Local reference repository at ' + path + ' does not exists!'
+       except AttributeError:
+               pass
        if config.protocol:
                url = re.sub(".*://", config.protocol + "://", url)
-       call(['clone'] + options + [url, name], fail=True)
+       if config.debug and reference:
+               print 'Set to reference', path
+       call(['clone'] + options + reference + [url, name], fail=True)
 
 def branch_active(name):
        lines = call_output(['symbolic-ref', 'HEAD'], workdir=name)
index f54be4d..26641d5 100644 (file)
@@ -14,6 +14,7 @@ import cache
 import components
 import git
 import log
+import re
 from config import config
 from config import parse as config_parse
 from build import build, build_only
@@ -28,7 +29,7 @@ def merge_config(name, value):
 def main(version):
        command, targets, options = parse_args(version)
 
-       for name in ('debug', 'initial_config_dirs', 'pull_config_dirs'):
+       for name in ('debug', 'initial_config_dirs', 'pull_config_dirs', 'reference'):
                if name in options:
                        merge_config(name, options[name])
 
@@ -116,6 +117,13 @@ def parse_args(matrix_version):
                                (opt, value))
                options[option.dest] = value
 
+       def set_reference(option, opt, value, parse):
+               if(len(re.findall(r"::", value)) != 1):
+                       raise optparse.OptionValueError(
+                                       'option %s: invalid argument : %s' % \
+                                       (opt, value))
+               options[option.dest] = re.split("::",value)
+
        def set_protocol(option, opt, value, parser):
                options[option.dest] = value
 
@@ -201,6 +209,13 @@ def parse_args(matrix_version):
                dest='make_jobs', action='callback', callback=set_jobs,
                type='int')
 
+       parser.add_option(
+               '-R', '--reference',
+               help='Setup .git/objects/info/alternates to obtain objects from gits in a local matrix project, '
+                    'specified as remote/matrix/project/url::/path/to/local/matrix/project/',
+               dest='reference', action='callback', callback=set_reference,
+               type='string')
+
        values, args = parser.parse_args(values=None)
        if not args:
                print_help(sys.stderr, parser)