This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch issue-21_Caching_build_trees
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 8ea9a3f29a5326647086a845ffff6621478d4119
Author: Phillip Smyth <[email protected]>
AuthorDate: Fri May 4 15:07:25 2018 +0100

    temp - done git.py
---
 buildstream/_frontend/cli.py       | 21 +++++++++++++++------
 buildstream/plugins/sources/git.py | 22 +++++++++++++++-------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index d2b86c9..0990cd6 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -216,12 +216,15 @@ def init(app, project_name, format_version, element_path, 
force):
               help="Except certain dependencies from tracking")
 @click.option('--track-cross-junctions', '-J', default=False, is_flag=True,
               help="Allow tracking to cross junction boundaries")
[email protected]('--cached-build-tree', default='False',
+              type=click.Choice(['True', 'False']),
+              help="Toggle the download of the cached build tree")
 @click.option('--track-save', default=False, is_flag=True,
               help="Deprecated: This is ignored")
 @click.argument('elements', nargs=-1,
                 type=click.Path(dir_okay=False, readable=True))
 @click.pass_obj
-def build(app, elements, all_, track_, track_save, track_all, track_except, 
track_cross_junctions):
+def build(app, elements, all_, track_, track_save, track_all, track_except, 
track_cross_junctions, cached_build_tree):
     """Build elements in a pipeline"""
 
     if (track_except or track_cross_junctions) and not (track_ or track_all):
@@ -240,7 +243,8 @@ def build(app, elements, all_, track_, track_save, 
track_all, track_except, trac
                          track_targets=track_,
                          track_except=track_except,
                          track_cross_junctions=track_cross_junctions,
-                         build_all=all_)
+                         build_all=all_,
+                         cached_build_tree)
 
 
 ##################################################################
@@ -338,10 +342,13 @@ def track(app, elements, deps, except_, cross_junctions):
               help='The dependency artifacts to pull (default: none)')
 @click.option('--remote', '-r',
               help="The URL of the remote cache (defaults to the first 
configured cache)")
[email protected]('--cached-build-tree', default='False',
+              type=click.Choice(['True', 'False']),
+              help="Toggle the download of the cached build tree")
 @click.argument('elements', nargs=-1,
                 type=click.Path(dir_okay=False, readable=True))
 @click.pass_obj
-def pull(app, elements, deps, remote):
+def pull(app, elements, deps, remote, cached_build_tree):
     """Pull a built artifact from the configured remote artifact cache.
 
     By default the artifact will be pulled one of the configured caches
@@ -355,7 +362,7 @@ def pull(app, elements, deps, remote):
         all:   All dependencies
     """
     with app.initialized(session_name="Pull"):
-        app.stream.pull(elements, selection=deps, remote=remote)
+        app.stream.pull(elements, selection=deps, remote=remote, 
cached_build_tree=cached_build_tree)
 
 
 ##################################################################
@@ -579,7 +586,8 @@ def workspace():
               help="Overwrite files existing in checkout directory")
 @click.option('--track', 'track_', default=False, is_flag=True,
               help="Track and fetch new source references before checking out 
the workspace")
[email protected]('--no-cache', 'no_cache', default=False, is_flag=True,
[email protected]('--no-cache', 'no_cache',  default='False',
+              type=click.Choice(['True', 'False']),
               help="Use Cached build tree if available")
 @click.argument('element',
                 type=click.Path(dir_okay=False, readable=True))
@@ -658,7 +666,8 @@ def workspace_close(app, remove_dir, all_, elements):
               help="Track and fetch the latest source before resetting")
 @click.option('--all', '-a', 'all_', default=False, is_flag=True,
               help="Reset all open workspaces")
[email protected]('--no-cache', 'no_cache', default=False, is_flag=True,
[email protected]('--no-cache', 'no_cache',  default='False',
+              type=click.Choice(['True', 'False']),
               help="Use Cached build tree if available")
 @click.argument('elements', nargs=-1,
                 type=click.Path(dir_okay=False, readable=True))
diff --git a/buildstream/plugins/sources/git.py 
b/buildstream/plugins/sources/git.py
index 70a725f..0ded13e 100644
--- a/buildstream/plugins/sources/git.py
+++ b/buildstream/plugins/sources/git.py
@@ -121,12 +121,6 @@ class GitMirror():
                          fail="Failed to fetch from remote git repository: 
{}".format(self.url),
                          cwd=self.mirror)
 
-    def describe(self):
-        self.source.call([self.source.host_git, 'describe'],
-                         fail="Failed to find a tag in remote git repository: 
{}".format(self.url),
-                         cwd=self.mirror)
-
-
     def has_ref(self):
         if not self.ref:
             return False
@@ -157,7 +151,21 @@ class GitMirror():
         # We need to pass '--no-hardlinks' because there's nothing to
         # stop the build from overwriting the files in the .git directory
         # inside the sandbox.
-        self.source.call([self.source.host_git, 'clone', '--no-checkout', 
'--no-hardlinks', self.mirror, fullpath],
+
+        # Need to get every commit since the last tagged object until the 
tracking commit
+        if has_ref():
+            all_tags = subprocess.check_output(['git', 'tag'])
+            tags_since_sha = subprocess.check_output(['git', 'tag', 
'--contains', self.ref])
+            preceeding_tags = all_tags - set(tags_since) 
+            last_tag_before_ref = preceeding_tags[-1]
+
+        # find number of commits since last_tag_before_ref
+            target_depth = subprocess.check_output(['git', 'rev-list', 
'--count', 'HEAD...{}'.format(last_tag_before_ref)])
+
+        else:
+            target_depth = subprocess.check_output(['git', 'rev-list', 
'--count', 'HEAD...{}'.format(self.ref)])
+
+        self.source.call([self.source.host_git, 'clone', '--depth 
{}'.format(target_depth), '--no-checkout', '--no-hardlinks', self.mirror, 
fullpath],
                          fail="Failed to create git mirror {} in directory: 
{}".format(self.mirror, fullpath))
 
         self.source.call([self.source.host_git, 'checkout', '--force', 
self.ref],

Reply via email to