-
Notifications
You must be signed in to change notification settings - Fork 94
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
unify: unified_patches duplicates fix #110
Conversation
* 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: |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]
Closing PR because it's been stale for a long time. |
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.
Related issue: Unifier class:
unify
method returns duplicated patches #109Signed-off-by: Iuliana Voinea [email protected]