def _merge_dicts(self): self._backup_lists() non_list_merger = Merger(self.root, self.head, self.update, {}) try: non_list_merger.run() except UnresolvedConflictsException as e: self._solve_dict_conflict(non_list_merger, e) self._restore_lists() self.merged_root = patch(non_list_merger.unified_patches, self.root)
def _merge_dicts(self): self._backup_lists() non_list_merger = Merger(self.root, self.head, self.update, {}) try: non_list_merger.run() except UnresolvedConflictsException as e: self._solve_dict_conflicts(non_list_merger, e.content) self._restore_lists() self.merged_root = patch( dedupe_list(non_list_merger.unified_patches), self.root )
def merge_with_published(self): """Merge changes with latest published version.""" pid, first = self.fetch_published() lca = first.revisions[self['_deposit']['pid']['revision_id']] # ignore _deposit and $schema field args = [lca.dumps(), first.dumps(), self.dumps()] for arg in args: del arg['$schema'], arg['_deposit'] args.append({}) m = Merger(*args) try: m.run() except UnresolvedConflictsException: raise MergeConflict() return patch(m.unified_patches, lca)
def test_run(self): lca = {'changeme': 'Jo'} first = {'changeme': 'Joe'} second = {'changeme': 'John'} m = Merger(lca, first, second, {}) self.assertRaises(UnresolvedConflictsException, m.run)
def _merge_dicts(self): self._backup_lists() LOGGER.debug( "Merging dicts with root=%s, head=%s, update=%s", self.root, self.head, self.update, ) non_list_merger = Merger(self.root, self.head, self.update, {}) try: non_list_merger.run() except UnresolvedConflictsException as e: self._solve_dict_conflicts(non_list_merger, e.content) self._restore_lists() self.merged_root = patch(dedupe_list(non_list_merger.unified_patches), self.root)
def test_continue_run_multiple_conflicts_per_patch(self): lca = {'foo': [{'x': 1}, {'y': 2}]} first = {'foo': [{'x': 1}, {'y': 2}, {'z': 4}]} second = {'bar': 'baz'} expected = { 'f': {'foo': [{'x': 1}, {'y': 2}, {'z': 4}], 'bar': 'baz'}, 's': {'bar': 'baz'}} for resolution, expected_value in expected.items(): m = Merger(lca, first, second, {}) try: m.run() except UnresolvedConflictsException as e: m.continue_run([resolution for _ in e.content]) self.assertEqual(patch(m.unified_patches, lca), expected_value)
def test_continue_run(self): def take_first(conflict, _, __, ___): conflict.take = [('f', x) for x in range(len(conflict.first_patch.patches))] return True lca = {'changeme': 'Jo'} first = {'changeme': 'Joe'} second = {'changeme': 'John'} m = Merger(lca, first, second, {}) try: m.run() except UnresolvedConflictsException: pass m.continue_run(['f']) self.assertEqual(m.unified_patches, [('change', 'changeme', ('Jo', 'Joe'))])
def test_continue_run_multiple_conflicts_per_patch(self): lca = {'foo': [{'x': 1}, {'y': 2}]} first = {'foo': [{'x': 1}, {'y': 2}, {'z': 4}]} second = {'bar': 'baz'} expected = { 'f': { 'foo': [{ 'x': 1 }, { 'y': 2 }, { 'z': 4 }], 'bar': 'baz' }, 's': { 'bar': 'baz' } } for resolution, expected_value in expected.items(): m = Merger(lca, first, second, {}) try: m.run() except UnresolvedConflictsException as e: m.continue_run([resolution for _ in e.content]) self.assertEqual(patch(m.unified_patches, lca), expected_value)
def _merge_dicts(self): self._backup_lists() non_list_merger = Merger(self.root, self.head, self.update, {}) try: non_list_merger.run() except UnresolvedConflictsException as e: non_list_merger.continue_run( [self.pick for i in range(len(e.content))]) for conflict in e.content: conflict_patch = { 'f': conflict.second_patch, 's': conflict.first_patch }[self.pick] self.conflict_set.update(patch_to_conflict_set(conflict_patch)) self._restore_lists() self.merged_root = patch(non_list_merger.unified_patches, self.root)