diff options
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 24 | ||||
-rw-r--r-- | buildstream/_artifactcache/ostreecache.py | 40 |
2 files changed, 64 insertions, 0 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index 5f3f337d1..8937afb49 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -189,6 +189,30 @@ class ArtifactCache(): raise ImplError("Cache '{kind}' does not implement commit()" .format(kind=type(self).__name__)) + # can_diff(): + # + # Whether this cache implementation can diff (unfortunately + # there's no way to tell if an implementation is going to throw + # ImplError without abc). + # + def can_diff(self): + return False + + # diff(): + # + # Return a list of files that have been added or modified between + # the artifacts described by key_a and key_b. + # + # Args: + # element (Element): The element whose artifacts to compare + # key_a (str): The first artifact key + # key_b (str): The second artifact key + # subdir (str): A subdirectory to limit the comparison to + # + def diff(self, element, key_a, key_b, *, subdir=None): + raise ImplError("Cache '{kind}' does not implement diff()" + .format(kind=type(self).__name__)) + # has_fetch_remotes(): # # Check whether any remote repositories are available for fetching. diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py index fa44beab8..76b4c3507 100644 --- a/buildstream/_artifactcache/ostreecache.py +++ b/buildstream/_artifactcache/ostreecache.py @@ -269,6 +269,46 @@ class OSTreeCache(ArtifactCache): except OSTreeError as e: raise ArtifactError("Failed to commit artifact: {}".format(e)) from e + # can_diff(): + # + # Whether this cache implementation can diff (unfortunately + # there's no way to tell if an implementation is going to throw + # ImplError without abc). + # + def can_diff(self): + return True + + # diff(): + # + # Return a list of files that have been added or modified between + # the artifacts described by key_a and key_b. + # + # Args: + # element (Element): The element whose artifacts to compare + # key_a (str): The first artifact key + # key_b (str): The second artifact key + # subdir (str): A subdirectory to limit the comparison to + # + def diff(self, element, key_a, key_b, *, subdir=None): + _, a, _ = self.repo.read_commit(buildref(element, key_a)) + _, b, _ = self.repo.read_commit(buildref(element, key_b)) + + if subdir: + a = a.get_child(subdir) + b = b.get_child(subdir) + + subpath = a.get_path() + else: + subpath = '/' + + modified, removed, added = _ostree.diff_dirs(a, b) + + modified = [os.path.relpath(item.target.get_path(), subpath) for item in modified] + removed = [os.path.relpath(item.get_path(), subpath) for item in removed] + added = [os.path.relpath(item.get_path(), subpath) for item in added] + + return modified, removed, added + # pull(): # # Pull artifact from one of the configured remote repositories. |