@@ -218,71 +218,72 @@ def aggressive_tree_merge(odb, tree_shas):
218218 for entry in traverse_tree_recursive (odb , tree_shas [- 1 ], '' ):
219219 out_append (_tree_entry_to_baseindexentry (entry , 0 ))
220220 # END for each entry
221- elif len (tree_shas ) == 3 :
222- for base , ours , theirs in traverse_trees_recursive (odb , tree_shas , '' ):
223- if base is not None :
224- # base version exists
225- if ours is not None :
226- # ours exists
227- if theirs is not None :
228- # it exists in all branches, if it was changed in both
229- # its a conflict, otherwise we take the changed version
230- # This should be the most common branch, so it comes first
231- if ( base [0 ] != ours [0 ] and base [0 ] != theirs [0 ] and ours [0 ] != theirs [0 ] ) or \
232- ( base [1 ] != ours [1 ] and base [1 ] != theirs [1 ] and ourse [1 ] != theirs [1 ] ):
233- # changed by both
234- out_append (_tree_entry_to_baseindexentry (base , 1 ))
235- out_append (_tree_entry_to_baseindexentry (ours , 2 ))
236- out_append (_tree_entry_to_baseindexentry (theirs , 3 ))
237- elif base [0 ] != ours [0 ] or base [1 ] != ours [1 ]:
238- # only we changed it
239- out_append (_tree_entry_to_baseindexentry (ours , 0 ))
240- else :
241- # either nobody changed it, or they did. In either
242- # case, use theirs
243- out_append (_tree_entry_to_baseindexentry (theirs , 0 ))
244- # END handle modification
221+ return out
222+ # END handle single tree
223+
224+ if len (tree_shas ) > 3 :
225+ raise ValueError ("Cannot handle %i trees at once" % len (tree_shas ))
226+
227+ # three trees
228+ for base , ours , theirs in traverse_trees_recursive (odb , tree_shas , '' ):
229+ if base is not None :
230+ # base version exists
231+ if ours is not None :
232+ # ours exists
233+ if theirs is not None :
234+ # it exists in all branches, if it was changed in both
235+ # its a conflict, otherwise we take the changed version
236+ # This should be the most common branch, so it comes first
237+ if ( base [0 ] != ours [0 ] and base [0 ] != theirs [0 ] and ours [0 ] != theirs [0 ] ) or \
238+ ( base [1 ] != ours [1 ] and base [1 ] != theirs [1 ] and ours [1 ] != theirs [1 ] ):
239+ # changed by both
240+ out_append (_tree_entry_to_baseindexentry (base , 1 ))
241+ out_append (_tree_entry_to_baseindexentry (ours , 2 ))
242+ out_append (_tree_entry_to_baseindexentry (theirs , 3 ))
243+ elif base [0 ] != ours [0 ] or base [1 ] != ours [1 ]:
244+ # only we changed it
245+ out_append (_tree_entry_to_baseindexentry (ours , 0 ))
245246 else :
246-
247- if ours [0 ] != base [0 ] or ours [1 ] != base [1 ]:
248- # they deleted it, we changed it, conflict
249- out_append (_tree_entry_to_baseindexentry (base , 1 ))
250- out_append (_tree_entry_to_baseindexentry (ours , 2 ))
251- out_append (_tree_entry_to_baseindexentry (theirs , 3 ))
252- # else:
253- # we didn't change it, ignore
254- # pass
255- # END handle our change
256- # END handle theirs
247+ # either nobody changed it, or they did. In either
248+ # case, use theirs
249+ out_append (_tree_entry_to_baseindexentry (theirs , 0 ))
250+ # END handle modification
257251 else :
258- if theirs is None :
259- # deleted in both, its fine - its out
260- pass
261- else :
262- if theirs [0 ] != base [0 ] or theirs [1 ] != base [1 ]:
263- # deleted in ours, changed theirs, conflict
264- out_append (_tree_entry_to_baseindexentry (base , 1 ))
265- out_append (_tree_entry_to_baseindexentry (ours , 2 ))
266- out_append (_tree_entry_to_baseindexentry (theirs , 3 ))
267- # END theirs changed
268- #else:
269- # theirs didnt change
270- # pass
271- # END handle theirs
272- # END handle ours
252+
253+ if ours [0 ] != base [0 ] or ours [1 ] != base [1 ]:
254+ # they deleted it, we changed it, conflict
255+ out_append (_tree_entry_to_baseindexentry (base , 1 ))
256+ out_append (_tree_entry_to_baseindexentry (ours , 2 ))
257+ # else:
258+ # we didn't change it, ignore
259+ # pass
260+ # END handle our change
261+ # END handle theirs
273262 else :
274- # all three can't be None
275- if ours is None :
276- # added in their branch
277- out_append (_tree_entry_to_baseindexentry (theirs , 0 ))
278- elif theirs is None :
279- # added in our branch
280- out_append (_tree_entry_to_baseindexentry (ours , 0 ))
281- # END hanle heads
282- # END handle base exists
283- # END for each entries tuple
284- else :
285- raise ValueError ("Cannot handle %i trees at once" % len (tree_shas ))
286- # END handle tree shas
287-
263+ if theirs is None :
264+ # deleted in both, its fine - its out
265+ pass
266+ else :
267+ if theirs [0 ] != base [0 ] or theirs [1 ] != base [1 ]:
268+ # deleted in ours, changed theirs, conflict
269+ out_append (_tree_entry_to_baseindexentry (base , 1 ))
270+ out_append (_tree_entry_to_baseindexentry (theirs , 3 ))
271+ # END theirs changed
272+ #else:
273+ # theirs didnt change
274+ # pass
275+ # END handle theirs
276+ # END handle ours
277+ else :
278+ # all three can't be None
279+ if ours is None :
280+ # added in their branch
281+ out_append (_tree_entry_to_baseindexentry (theirs , 0 ))
282+ elif theirs is None :
283+ # added in our branch
284+ out_append (_tree_entry_to_baseindexentry (ours , 0 ))
285+ # END hanle heads
286+ # END handle base exists
287+ # END for each entries tuple
288+
288289 return out
0 commit comments