You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/07/26 08:48:27 UTC

[buildstream] 02/02: source.py: Pass MappingNode to Source.set_ref()

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

tvb pushed a commit to branch tristan/source-set-ref-mapping-node
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit e8b664a305626873268af9fa15919cd0d4f5d162
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Jul 26 17:44:59 2022 +0900

    source.py: Pass MappingNode to Source.set_ref()
    
    The API documentation calls for a MappingNode so we should be passing
    the plugin a MappingNode here.
    
    Fixes #1685
---
 src/buildstream/source.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index e35d734a1..6c7713c3f 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -965,7 +965,7 @@ class Source(Plugin):
             # First warn if there is a ref already loaded, and reset it
             redundant_ref = self.get_ref()  # pylint: disable=assignment-from-no-return
             if redundant_ref is not None:
-                self.set_ref(None, {})
+                self.set_ref(None, MappingNode.from_dict({}))
 
             # Try to load the ref
             refs = self._project_refs(project)
@@ -1015,14 +1015,18 @@ class Source(Plugin):
         #
         # Step 2 - Set the ref in memory, and determine changed state
         #
-        # TODO: we are working on dictionaries here, would be nicer to just work on the nodes themselves
         clean = node.strip_node_info()
-        to_modify = node.strip_node_info()
 
         # Set the ref regardless of whether it changed, the
         # TrackQueue() will want to update a specific node with
         # the ref, regardless of whether the original has changed.
-        self.set_ref(new_ref, to_modify)
+        #
+        # In the following add/del/mod merge algorithm we are working with
+        # dictionaries, but the plugin API calls for a MappingNode.
+        #
+        modify = node.clone()
+        self.set_ref(new_ref, modify)
+        to_modify = modify.strip_node_info()
 
         # FIXME: this will save things too often, as a ref might not have
         #        changed. We should optimize this to detect it differently