diff options
-rw-r--r-- | morphlib/builder.py | 11 | ||||
-rw-r--r-- | morphlib/git.py | 27 |
2 files changed, 25 insertions, 13 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index ad0b14f9..dc7d51db 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -325,13 +325,20 @@ class ChunkBuilder(BlobBuilder): self.msg('Extracting %s into %s' % (treeish.repo, self.builddir)) - morphlib.git.archive_and_extract( - self.app, treeish, destdir, self.msg) + morphlib.git.copy_repository(treeish, destdir, self.msg) + morphlib.git.checkout_ref(destdir, treeish.ref, self.msg) for submodule in treeish.submodules: directory = os.path.join(destdir, submodule.path) extract_treeish(submodule.treeish, directory) + # we need to do this to keep any "git submodule" commands + # from accessing the internet. instead, we redirect them + # to the locally cached submodule repo + morphlib.git.set_submodule_url(destdir, submodule.name, + submodule.treeish.repo, + self.msg) + extract_treeish(self.blob.morph.treeish, self.builddir) def build_with_system_or_commands(self): 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]) |