From aa4834c1a911600ffa26b04285eb56cc863b63de Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Wed, 22 Feb 2012 13:09:48 +0000 Subject: Use "cp -a" and "git checkout" to unpack sources in the build tree. This is done to keep the git repository intact with history and all that. cp + checkout turns out to be faster than a regular "git clone". In order to avoid roundtrips to the internet whenever a chunk tries to do something with submodules, we force the submodule URLs to point to our locally cached repos. --- morphlib/git.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'morphlib/git.py') diff --git a/morphlib/git.py b/morphlib/git.py index cca51eed..05a55e06 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -211,12 +211,6 @@ class Submodules(object): return len(self.submodules) -def export_sources(treeish, tar_filename, msg=logging.debug): - '''Export the contents of a specific commit into a compressed tarball.''' - ex = morphlib.execute.Execute('.', msg=msg) - ex.env['GIT_DIR'] = os.path.join(treeish.repo, '.git') - ex.runv(['git', 'archive', '-o', tar_filename, treeish.sha1]) - def get_morph_text(treeish, filename, msg=logging.debug): '''Return a morphology from a git repository.''' ex = morphlib.execute.Execute(treeish.repo, msg=msg) @@ -248,8 +242,19 @@ def update_remote(gitdir, name, msg=logging.debug): ex = morphlib.execute.Execute(gitdir, msg=msg) return ex.runv(['git', 'remote', 'update', name]) -def archive_and_extract(app, treeish, destdir, msg=logging.debug): - return app.runcmd(['git', 'archive', treeish.ref], - ['tar', '-C', destdir, '-xv'], - cwd=treeish.repo, - msg=msg) +def copy_repository(treeish, destdir, msg=logging.debug): + '''Copies a cached repository into a directory using cp.''' + ex = morphlib.execute.Execute('.', msg=msg) + return ex.runv(['cp', '-a', os.path.join(treeish.repo, '.git'), destdir]) + +def checkout_ref(gitdir, ref, msg=logging.debug): + '''Checks out a specific ref/SHA1 in a git working tree.''' + ex = morphlib.execute.Execute(gitdir, msg=msg) + return ex.runv(['git', 'checkout', ref]) + +def set_submodule_url(gitdir, name, url, msg=logging.debug): + '''Changes the URL of a submodule to point to a specific location.''' + ex = morphlib.execute.Execute(gitdir, msg=msg) + ex.runv(['git', 'config', 'submodule.%s.url' % name, url]) + ex.runv(['git', 'config', '-f', '.gitmodules', + 'submodule.%s.url' % name, url]) -- cgit v1.2.1