clone only meta repositories by default
authorTimo Savola <tsavola@movial.fi>
Fri, 4 Apr 2008 14:37:27 +0000 (17:37 +0300)
committerTimo Savola <tsavola@movial.fi>
Fri, 4 Apr 2008 14:37:27 +0000 (17:37 +0300)
"download" command is replaced with "clone" which clones the source code
repositories.

matrix/git.py
matrix/matrix.py

index 16530f7..e7cebaf 100644 (file)
@@ -237,5 +237,12 @@ def cat_file(name, hash, blob=False, size=False):
 def log(name, options, fd=None):
        return call_output(['log'] + options + ['--'], workdir=name, fd=fd)
 
+def exclude(name, line):
+       file = open(os.path.join(name, '.git', 'info', 'exclude'), 'a')
+       try:
+               print >>file, line
+       finally:
+               file.close()
+
 def contains_database(name):
        return os.path.exists(os.path.join(name, '.git'))
index 321e613..d31e80c 100644 (file)
@@ -43,9 +43,8 @@ def main():
 
        if command == 'install':
                build_components(targets, **params)
-       elif command == 'download':
-               # Actual downloading took place already in update_components()
-               pass
+       elif command == 'clone':
+               clone_components(targets)
        elif command == 'clean':
                clean_components(targets)
        elif command == 'pull':
@@ -63,7 +62,8 @@ Copyright (C) 2006-2008 Movial Oy
 
 Usage: %(progname)s [<options>] <command> [<params>] [<components>]
 
-If no components are specified, all of them will be targeted.
+If no components are specified, all of them will be targeted.  All component
+metadata will be downloaded regardless of the specified command and components.
 
 Options:
        -v              Verbose output.
@@ -76,7 +76,7 @@ Options:
        -h, --help      Print this help text.
 
 Commands and parameters:
-       download        Only download the components and validate the tree.
+       clone           Download the components' git repositories.
        install         Download, build and install the components.
                -j N            Execute N build jobs in parallel.
                -mj N           Run component builds with make -j N.
@@ -170,7 +170,7 @@ def update_components():
 
        for c in config.components.itervalues():
                update_component_url(c)
-               download_component(c)
+               clone_metadata(c)
                update_component_packages(c, targets, packages)
                c.active_depends = []
 
@@ -264,25 +264,59 @@ def execute(args):
        if os.spawnvp(os.P_WAIT, args[0], args) != 0:
                raise Error('Failed: ' + ' '.join(args))
 
-def download_component(c, overwrite=False):
-       if os.path.exists(c.repo.path) and not overwrite:
+def remove_tree(path):
+       execute(['rm', '-rf', path])
+
+def clone_components(targets):
+       if not targets:
+               targets = config.components.keys()
+
+       for name in targets:
+               c = config.components[name]
+               clone_component(c)
+
+def clone_component(c, overwrite=False):
+       have_repo = git.contains_database(c.repo.path)
+       have_meta = git.contains_database(c.meta.path)
+
+       if not overwrite and have_repo and have_meta:
                return
 
-       print 'Downloading component:', c.name
+       if overwrite and os.path.exists(c.repo.path):
+               print 'Removing', c.repo.path
 
-       execute(['rm', '-rf', c.repo.path])
-       download_repository(c, c.repo)
-       download_repository(c, c.meta)
+               remove_tree(c.repo.path)
+               have_repo = False
+               have_meta = False
 
-def download_repository(c, repo):
-       if config.debug:
-               print 'Downloading repository:', repo.name
+       if not have_repo:
+               clone_repository(c.repo)
+               git.exclude(c.repo.path, 'meta')
+
+       if not have_meta:
+               clone_repository(c.meta)
 
-       git.clone(repo.path, repo.active_url, checkout=False)
+def clone_metadata(c):
+       if not git.contains_database(c.meta.path):
+               clone_repository(c.meta)
 
-       branch = c.get_active_tag()
-       git.create_branch(repo.path, branch, 'origin/%s' % branch,
-                         checkout=True, link=True, force=True)
+def clone_repository(repo):
+       print 'Cloning', repo.path
+
+       if os.path.exists(repo.path):
+               tmp = os.path.join(repo.path, 'tmp')
+               git.clone(tmp, repo.active_url, checkout=False)
+               try:
+                       tmpdb = os.path.join(tmp, '.git')
+                       repodb = os.path.join(repo.path, '.git')
+                       if config.debug:
+                               print 'Renaming "%s" as "%s"' % (tmpdb, repodb)
+                       os.rename(tmpdb, repodb)
+               finally:
+                       os.rmdir(tmp)
+               git.checkout(repo.path)
+       else:
+               git.clone(repo.path, repo.active_url, checkout=True)
 
 def update_component_packages(c, targets, packages):
        c.active_packages = {}