Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply_change_to_project: use attribute_name for building change_path. #119

Merged
merged 1 commit into from
May 13, 2024

Conversation

ashdnazg
Copy link
Contributor

@ashdnazg ashdnazg commented May 7, 2024

Fixes #118

When merging the tree, Kintsugi keeps track of where it is, to allow
finding the corresponding component in the source project.
Until this commit, the path was constructed in add_child_to_component
by appending the display name of the added component.
When adding a file reference this path was used to traverse the project
tree along each object's attributes.

This caused a bug when the display name and the attribute name
are different, e.g., a target's build configuration list has a display
name of "ConfigurationList" and an attribute name of
"build_configuration_list". The camel-case was converted correctly, but
the merge failed due to not finding the attribute "configuration_list".

The solution to this issue is to use the attribute names to create the
path, except when adding an object to a list, where there is no
attribute and then the display name is used.

Copy link
Collaborator

@byohay byohay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F&S

@@ -1022,6 +1020,7 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])
next if (%w[isa displayName] + ignore_keys).include?(change_name)

attribute_name = attribute_name_from_change_name(change_name)
attribute_path = "#{change_path}/#{change_name}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use join_path

@@ -1022,6 +1020,7 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])
next if (%w[isa displayName] + ignore_keys).include?(change_name)

attribute_name = attribute_name_from_change_name(change_name)
attribute_path = "#{change_path}/#{change_name}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you use attribute_name instead of change_name?
If not, let's call it child_path, wdyt?

Copy link
Contributor Author

@ashdnazg ashdnazg May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to use the attribute name here since it's being converted later in child_component when traversing the tree in component_at_path.

@@ -306,7 +306,8 @@ def apply_change_to_component(parent_component, change_name, change, parent_chan
component = child_component(parent_component, change_name)
elsif change[:added].is_a?(Array)
(change[:added]).each do |added_change|
add_child_to_component(parent_component, added_change, change_path)
add_child_to_component(parent_component, added_change,
"#{change_path}/#{added_change["displayName"]}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use join_path

@ashdnazg ashdnazg force-pushed the feature/fix-paths branch 2 times, most recently from e9b80bd to 550b9b6 Compare May 7, 2024 21:20
@ashdnazg
Copy link
Contributor Author

ashdnazg commented May 7, 2024

F&Sed

Copy link
Collaborator

@byohay byohay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F&S

@@ -1022,6 +1020,7 @@ def add_attributes_to_component(component, change, change_path, ignore_keys: [])
next if (%w[isa displayName] + ignore_keys).include?(change_name)

attribute_name = attribute_name_from_change_name(change_name)
child_path = join_path(change_path, attribute_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, you said you don't want to use attribute_name here, no?
Then again, if you don't use attribute_name here I don't understand what this PR fixes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I changed it too many times and got confused 🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the issue by not using the display name. It doesn't matter if you use the child name (camel case) or the attribute name (snake case), both are correct and converted later to snake case when the path is used.

@@ -306,7 +306,8 @@ def apply_change_to_component(parent_component, change_name, change, parent_chan
component = child_component(parent_component, change_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to change line 305 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we only need to use the display names when adding array elements. change_path already includes the key under which the hash is.

When merging the tree, Kintsugi keeps track of where it is, to allow
finding the corresponding component in the source project.
Until this commit, the path was constructed in `add_child_to_component`
by appending the display name of the added component.
When adding a file reference this path was used to traverse the project
tree along each object's attributes.

This caused a bug when the display name and the attribute name
are different, e.g., a target's build configuration list has a display
name of "ConfigurationList" and an attribute name of
"build_configuration_list". The camel-case was converted correctly, but
the merge failed due to not finding the attribute "configuration_list".

The solution to this issue is to use the attribute names to create the
path, except when adding an object to a list, where there is no
attribute and then the display name is used.
@ashdnazg ashdnazg force-pushed the feature/fix-paths branch from 550b9b6 to 4c26a59 Compare May 9, 2024 06:36
@ashdnazg
Copy link
Contributor Author

ashdnazg commented May 9, 2024

F&Sed

Copy link
Collaborator

@byohay byohay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ashdnazg ashdnazg merged commit 943a897 into Lightricks:main May 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants