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

Kintsugi: Avoid adding duplicates if settings don't allow. #76

Merged
merged 2 commits into from
Aug 4, 2022

Conversation

byohay
Copy link
Collaborator

@byohay byohay commented Jul 18, 2022

  • Kintusgi: Add Settings class.
  • Kintsugi: Avoid adding duplicates if settings don't allow.

@byohay byohay force-pushed the feature/avoid-adding-duplicates branch 2 times, most recently from cd6cb75 to e2b25c8 Compare July 18, 2022 11:38
(old_value || []) + (added_change || []) - (removed_change || [])

new_value = (old_value || []) + (added_change || []) - (removed_change || [])
Settings.allow_duplicates ? new_value : new_value.uniq
Copy link
Member

Choose a reason for hiding this comment

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

If you use uniq here, you will also delete duplicates in the old values, which is beyond the mandate given to Kintsugi.

@@ -506,6 +514,11 @@ def add_build_file(build_phase, change, change_path)
return
end

duplicate_build_file_exist = build_phase.files.find do |build_file|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
duplicate_build_file_exist = build_phase.files.find do |build_file|
duplicate_build_file_exists = build_phase.files.find do |build_file|

@@ -581,6 +594,13 @@ def find_containing_project_uuid(project, container_item_proxy_change)
end

def add_subproject_reference(root_object, project_reference_change, change_path)
duplicate_subproject_exist =
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
duplicate_subproject_exist =
duplicate_subproject_exists =

@@ -649,6 +669,10 @@ def add_file_reference(containing_component, change, change_path)
return
end

return if !Settings.allow_duplicates &&
Copy link
Member

Choose a reason for hiding this comment

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

also merge duplicate groups

@byohay byohay marked this pull request as ready for review August 3, 2022 13:12
@byohay byohay force-pushed the feature/avoid-adding-duplicates branch from e2b25c8 to 4db7f04 Compare August 3, 2022 13:12
@byohay
Copy link
Collaborator Author

byohay commented Aug 3, 2022

@ashdnazg round done.

@byohay byohay changed the title feature/avoid adding duplicates Kintsugi: Avoid adding duplicates if settings don't allow. Aug 3, 2022
@byohay byohay linked an issue Aug 4, 2022 that may be closed by this pull request
Copy link
Member

@ashdnazg ashdnazg 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&M

def find_file_in_group(group, filetype, filepath)
group
.children
.select { |child| child.instance_of?(filetype) }
Copy link
Member

Choose a reason for hiding this comment

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

why instance_of and not is_a?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because PBXVariantGroup inherit from PBXGroup, and I didn't want to treat them as duplicates if they have a different type.

@@ -1400,6 +1380,164 @@
expect(base_project).to be_equivalent_to_project(theirs_project)
end

describe "avoiding duplicate references to the same component" do
it "avoids adding file reference that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding file reference that already exist" do
it "avoids adding file reference that already exists" do

expect(other_project).to be_equivalent_to_project(base_project)
end

it "avoids adding group that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding group that already exist" do
it "avoids adding group that already exists" do

expect(other_project).to be_equivalent_to_project(base_project)
end

it "avoids adding variant group that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding variant group that already exist" do
it "avoids adding variant group that already exists" do

expect(other_project).to be_equivalent_to_project(base_project)
end

it "avoids adding subproject that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding subproject that already exist" do
it "avoids adding subproject that already exists" do

expect(ours_project.root_object.project_references.count).to equal(1)
end

it "avoids adding build file that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding build file that already exist" do
it "avoids adding build file that already exists" do

expect(other_project).to be_equivalent_to_project(base_project)
end

it "avoids adding reference proxy that already exist" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "avoids adding reference proxy that already exist" do
it "avoids adding reference proxy that already exists" do

expect(other_project).to be_equivalent_to_project(base_project)
end

it "keeps array if adding string value that already exist in array" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it "keeps array if adding string value that already exist in array" do
it "keeps array if adding string value that already exists in array" do

@byohay byohay force-pushed the feature/avoid-adding-duplicates branch 5 times, most recently from e7a71a9 to 0bc1680 Compare August 4, 2022 13:03
Copy link
Member

@ashdnazg ashdnazg 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&M

Comment on lines 668 to 672
duplicate_build_file_exists = !build_phase.files.find do |build_file|
build_file.file_ref.path == change["fileRef"]["path"]
end.nil?
return if !Settings.allow_duplicates && duplicate_build_file_exists

Copy link
Member

Choose a reason for hiding this comment

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

it's a bit hard to read when the ! is in the beginning and the .nil? is in the end.
consider

Suggested change
duplicate_build_file_exists = !build_phase.files.find do |build_file|
build_file.file_ref.path == change["fileRef"]["path"]
end.nil?
return if !Settings.allow_duplicates && duplicate_build_file_exists
duplicate_build_file = build_phase.files.find do |build_file|
build_file.file_ref.path == change["fileRef"]["path"]
end
return if !Settings.allow_duplicates && !duplicate_build_file.nil?

same in other places

Copy link
Member

Choose a reason for hiding this comment

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

maybe existing_build_file instead of duplicate_build_file

# frozen_string_literal: true

module Kintsugi
# Kintsugi global settings
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Kintsugi global settings
# Kintsugi global settings.

@byohay byohay force-pushed the feature/avoid-adding-duplicates branch from 0bc1680 to a58f65b Compare August 4, 2022 14:19
The class contains global build settings, e.g. the `allow_duplicates`
flag.
@byohay byohay force-pushed the feature/avoid-adding-duplicates branch from a58f65b to c978bff Compare August 4, 2022 14:35
This setting is relevant to:
- File references.
- Subprojects
- Build files
- Array build settings.
- Groups and variant groups.
@byohay byohay force-pushed the feature/avoid-adding-duplicates branch from c978bff to ed85ff5 Compare August 4, 2022 14:36
@byohay byohay merged commit 123192e into Lightricks:main Aug 4, 2022
@byohay byohay deleted the feature/avoid-adding-duplicates branch August 4, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for ignoring duplicates
2 participants