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

unify: unified_patches duplicates fix #110

Conversation

iulianav
Copy link

Signed-off-by: Iuliana Voinea [email protected]

* FIX Fixes the way in which handled conflicts are unified so that the
  Merger's unified_patches does not contain duplicate patches and can
  always be applied.

Signed-off-by: Iuliana Voinea <[email protected]>
@@ -37,7 +37,8 @@ def unify(self, first_patches, second_patches, conflicts):
if conflict.take_patch() != patch:
continue

self.unified_patches.append(patch)
if patch not in self.unified_patches:
Copy link
Member

Choose a reason for hiding this comment

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

This might be quite slow if you have a long list of unified_patches.

Copy link
Author

Choose a reason for hiding this comment

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

Do you have any suggestions perhaps?

Copy link
Member

@jirikuncar jirikuncar Jun 29, 2018

Choose a reason for hiding this comment

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

Using a separate set for the lookup.

Copy link
Member

@jirikuncar jirikuncar Jun 29, 2018

Choose a reason for hiding this comment

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

I would even propose a change to this method:

unified_patches = set()
self._build_index(conflicts)

sorted_patches = sorted(first_patches + second_patches, key=get_path)

for patch in sorted_patches:
    conflict = self._index.get(nested_hash(patch))

    # Apply only the patches that were taken as part of conflict
    # resolution.
    if conflict:
        if conflict.take_patch() != patch:
            continue

    if patch not in unified_patches:
        unified_patches.add(patch)
        yield patch

Copy link
Member

Choose a reason for hiding this comment

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

also _build_index method could become static and simply return the conflict mapping.

Copy link
Author

@iulianav iulianav Jul 3, 2018

Choose a reason for hiding this comment

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

@jirikuncar I think maybe before this commit the bug was not here?

Copy link
Member

Choose a reason for hiding this comment

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

@iulianav maybe instead of sorting the lists should be merged.

>>> a = [1, 4, 3, 2]
>>> b = [1, 5, 3]
>>> merge_keys(a, b)
[1, 4, 5, 3, 2]

@lnielsen
Copy link
Member

Closing PR because it's been stale for a long time.

@lnielsen lnielsen closed this Feb 16, 2022
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.

3 participants