1313 S_IFREG ,
1414 S_IXUSR ,
1515)
16+
1617import subprocess
1718
1819from git .cmd import PROC_CREATIONFLAGS , handle_process_output
@@ -339,76 +340,79 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr
339340 raise ValueError ("Cannot handle %i trees at once" % len (tree_shas ))
340341
341342 # three trees
342- for entryo in traverse_trees_recursive (odb , tree_shas , '' ):
343- assert is_three_entry_list (entryo ), f"{ type (entryo )= } and { len (entryo )= } " # type:ignore
344- base , ours , theirs = entryo
345- if base is not None :
346- # base version exists
347- if ours is not None :
348- # ours exists
349- if theirs is not None :
350- # it exists in all branches, if it was changed in both
351- # its a conflict, otherwise we take the changed version
352- # This should be the most common branch, so it comes first
353- if (base [0 ] != ours [0 ] and base [0 ] != theirs [0 ] and ours [0 ] != theirs [0 ]) or \
354- (base [1 ] != ours [1 ] and base [1 ] != theirs [1 ] and ours [1 ] != theirs [1 ]):
355- # changed by both
356- out .append (_tree_entry_to_baseindexentry (base , 1 ))
357- out .append (_tree_entry_to_baseindexentry (ours , 2 ))
358- out .append (_tree_entry_to_baseindexentry (theirs , 3 ))
359- elif base [0 ] != ours [0 ] or base [1 ] != ours [1 ]:
360- # only we changed it
361- out .append (_tree_entry_to_baseindexentry (ours , 0 ))
362- else :
363- # either nobody changed it, or they did. In either
364- # case, use theirs
365- out .append (_tree_entry_to_baseindexentry (theirs , 0 ))
366- # END handle modification
343+ entries = traverse_trees_recursive (odb , tree_shas , '' )
344+ base = entries [0 ]
345+ ours = entries [1 ]
346+ theirs = entries [2 ]
347+ assert is_three_entry_list (entries ), f"{ type (entries )= } and { len (entries )= } " # type:ignore
348+
349+ if base is not None :
350+ # base version exists
351+ if ours is not None :
352+ # ours exists
353+ if theirs is not None :
354+ # it exists in all branches, if it was changed in both
355+ # its a conflict, otherwise we take the changed version
356+ # This should be the most common branch, so it comes first
357+ if (base [0 ] != ours [0 ] and base [0 ] != theirs [0 ] and ours [0 ] != theirs [0 ]) or \
358+ (base [1 ] != ours [1 ] and base [1 ] != theirs [1 ] and ours [1 ] != theirs [1 ]):
359+ # changed by both
360+ out .append (_tree_entry_to_baseindexentry (base , 1 ))
361+ out .append (_tree_entry_to_baseindexentry (ours , 2 ))
362+ out .append (_tree_entry_to_baseindexentry (theirs , 3 ))
363+ elif base [0 ] != ours [0 ] or base [1 ] != ours [1 ]:
364+ # only we changed it
365+ out .append (_tree_entry_to_baseindexentry (ours , 0 ))
367366 else :
368-
369- if ours [0 ] != base [0 ] or ours [1 ] != base [1 ]:
370- # they deleted it, we changed it, conflict
371- out .append (_tree_entry_to_baseindexentry (base , 1 ))
372- out .append (_tree_entry_to_baseindexentry (ours , 2 ))
373- # else:
374- # we didn't change it, ignore
375- # pass
376- # END handle our change
377- # END handle theirs
367+ # either nobody changed it, or they did. In either
368+ # case, use theirs
369+ out .append (_tree_entry_to_baseindexentry (theirs , 0 ))
370+ # END handle modification
378371 else :
379- if theirs is None :
380- # deleted in both, its fine - its out
381- pass
382- else :
383- if theirs [0 ] != base [0 ] or theirs [1 ] != base [1 ]:
384- # deleted in ours, changed theirs, conflict
385- out .append (_tree_entry_to_baseindexentry (base , 1 ))
386- out .append (_tree_entry_to_baseindexentry (theirs , 3 ))
387- # END theirs changed
388- # else:
389- # theirs didn't change
390- # pass
391- # END handle theirs
392- # END handle ours
393- else :
394- # all three can't be None
395- if ours is None and theirs is not None :
396- # added in their branch
397- out .append (_tree_entry_to_baseindexentry (theirs , 0 ))
398- elif theirs is None and ours is not None :
399- # added in our branch
400- out .append (_tree_entry_to_baseindexentry (ours , 0 ))
401- elif ours is not None and theirs is not None :
402- # both have it, except for the base, see whether it changed
403- if ours [0 ] != theirs [0 ] or ours [1 ] != theirs [1 ]:
372+
373+ if ours [0 ] != base [0 ] or ours [1 ] != base [1 ]:
374+ # they deleted it, we changed it, conflict
375+ out .append (_tree_entry_to_baseindexentry (base , 1 ))
404376 out .append (_tree_entry_to_baseindexentry (ours , 2 ))
377+ # else:
378+ # we didn't change it, ignore
379+ # pass
380+ # END handle our change
381+ # END handle theirs
382+ else :
383+ if theirs is None :
384+ # deleted in both, its fine - its out
385+ pass
386+ else :
387+ if theirs [0 ] != base [0 ] or theirs [1 ] != base [1 ]:
388+ # deleted in ours, changed theirs, conflict
389+ out .append (_tree_entry_to_baseindexentry (base , 1 ))
405390 out .append (_tree_entry_to_baseindexentry (theirs , 3 ))
406- else :
407- # it was added the same in both
408- out .append (_tree_entry_to_baseindexentry (ours , 0 ))
409- # END handle two items
410- # END handle heads
411- # END handle base exists
412- # END for each entries tuple
391+ # END theirs changed
392+ # else:
393+ # theirs didn't change
394+ # pass
395+ # END handle theirs
396+ # END handle ours
397+ else :
398+ # all three can't be None
399+ if ours is None and theirs is not None :
400+ # added in their branch
401+ out .append (_tree_entry_to_baseindexentry (theirs , 0 ))
402+ elif theirs is None and ours is not None :
403+ # added in our branch
404+ out .append (_tree_entry_to_baseindexentry (ours , 0 ))
405+ elif ours is not None and theirs is not None :
406+ # both have it, except for the base, see whether it changed
407+ if ours [0 ] != theirs [0 ] or ours [1 ] != theirs [1 ]:
408+ out .append (_tree_entry_to_baseindexentry (ours , 2 ))
409+ out .append (_tree_entry_to_baseindexentry (theirs , 3 ))
410+ else :
411+ # it was added the same in both
412+ out .append (_tree_entry_to_baseindexentry (ours , 0 ))
413+ # END handle two items
414+ # END handle heads
415+ # END handle base exists
416+ # END for each entries tuple
413417
414418 return out
0 commit comments