Skip to content
Snippets Groups Projects
Commit c6064a7b authored by Mark Haines's avatar Mark Haines Committed by Erik Johnston
Browse files

Only construct sets when necessary

parent a8594fd1
No related branches found
No related tags found
No related merge requests found
...@@ -453,22 +453,27 @@ def _seperate(state_sets): ...@@ -453,22 +453,27 @@ def _seperate(state_sets):
unconflicted_state = dict(state_sets[0]) unconflicted_state = dict(state_sets[0])
conflicted_state = {} conflicted_state = {}
full_states = defaultdict(
set,
{k: set((v,)) for k, v in state_sets[0].iteritems()}
)
for state_set in state_sets[1:]: for state_set in state_sets[1:]:
for key, value in state_set.iteritems(): for key, value in state_set.iteritems():
ls = full_states[key] # Check if there is an unconflicted entry for the state key.
if not ls: unconflicted_value = unconflicted_state.get(key)
ls.add(value) if unconflicted_value is None:
unconflicted_state[key] = value # There isn't an unconflicted entry so check if there is a
elif value not in ls: # conflicted entry.
ls.add(value) ls = conflicted_state.get(key)
if len(ls) == 2: if ls is None:
conflicted_state[key] = ls # There wasn't a conflicted entry so haven't seen this key before.
unconflicted_state.pop(key, None) # Therefore it isn't conflicted yet.
unconflicted_state[key] = value
else:
# This key is already conflicted, add our value to the conflict set.
ls.add(value)
elif unconflicted_value != value:
# If the unconflicted value is not the same as our value then we
# have a new conflict. So move the key from the unconflicted_state
# to the conflicted state.
conflicted_state[key] = {value, unconflicted_value}
unconflicted_state.pop(key, None)
return unconflicted_state, conflicted_state return unconflicted_state, conflicted_state
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment