|
13 | 13 | S_IFREG, |
14 | 14 | S_IXUSR, |
15 | 15 | ) |
| 16 | + |
16 | 17 | importsubprocess |
17 | 18 |
|
18 | 19 | fromgit.cmdimportPROC_CREATIONFLAGS,handle_process_output |
@@ -339,76 +340,79 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr |
339 | 340 | raiseValueError("Cannot handle %i trees at once"%len(tree_shas)) |
340 | 341 |
|
341 | 342 | # three trees |
342 | | -forentryointraverse_trees_recursive(odb,tree_shas,''): |
343 | | -assertis_three_entry_list(entryo),f"{type(entryo)=} and{len(entryo)=}"# type:ignore |
344 | | -base,ours,theirs=entryo |
345 | | -ifbaseisnotNone: |
346 | | -# base version exists |
347 | | -ifoursisnotNone: |
348 | | -# ours exists |
349 | | -iftheirsisnotNone: |
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]andbase[0]!=theirs[0]andours[0]!=theirs[0])or \ |
354 | | - (base[1]!=ours[1]andbase[1]!=theirs[1]andours[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 | | -elifbase[0]!=ours[0]orbase[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 | +assertis_three_entry_list(entries),f"{type(entries)=} and{len(entries)=}"# type:ignore |
| 348 | + |
| 349 | +ifbaseisnotNone: |
| 350 | +# base version exists |
| 351 | +ifoursisnotNone: |
| 352 | +# ours exists |
| 353 | +iftheirsisnotNone: |
| 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]andbase[0]!=theirs[0]andours[0]!=theirs[0])or \ |
| 358 | + (base[1]!=ours[1]andbase[1]!=theirs[1]andours[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 | +elifbase[0]!=ours[0]orbase[1]!=ours[1]: |
| 364 | +# only we changed it |
| 365 | +out.append(_tree_entry_to_baseindexentry(ours,0)) |
367 | 366 | else: |
368 | | - |
369 | | -ifours[0]!=base[0]orours[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 |
378 | 371 | else: |
379 | | -iftheirsisNone: |
380 | | -# deleted in both, its fine - its out |
381 | | -pass |
382 | | -else: |
383 | | -iftheirs[0]!=base[0]ortheirs[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 | | -ifoursisNoneandtheirsisnotNone: |
396 | | -# added in their branch |
397 | | -out.append(_tree_entry_to_baseindexentry(theirs,0)) |
398 | | -eliftheirsisNoneandoursisnotNone: |
399 | | -# added in our branch |
400 | | -out.append(_tree_entry_to_baseindexentry(ours,0)) |
401 | | -elifoursisnotNoneandtheirsisnotNone: |
402 | | -# both have it, except for the base, see whether it changed |
403 | | -ifours[0]!=theirs[0]orours[1]!=theirs[1]: |
| 372 | + |
| 373 | +ifours[0]!=base[0]orours[1]!=base[1]: |
| 374 | +# they deleted it, we changed it, conflict |
| 375 | +out.append(_tree_entry_to_baseindexentry(base,1)) |
404 | 376 | 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 | +iftheirsisNone: |
| 384 | +# deleted in both, its fine - its out |
| 385 | +pass |
| 386 | +else: |
| 387 | +iftheirs[0]!=base[0]ortheirs[1]!=base[1]: |
| 388 | +# deleted in ours, changed theirs, conflict |
| 389 | +out.append(_tree_entry_to_baseindexentry(base,1)) |
405 | 390 | 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 | +ifoursisNoneandtheirsisnotNone: |
| 400 | +# added in their branch |
| 401 | +out.append(_tree_entry_to_baseindexentry(theirs,0)) |
| 402 | +eliftheirsisNoneandoursisnotNone: |
| 403 | +# added in our branch |
| 404 | +out.append(_tree_entry_to_baseindexentry(ours,0)) |
| 405 | +elifoursisnotNoneandtheirsisnotNone: |
| 406 | +# both have it, except for the base, see whether it changed |
| 407 | +ifours[0]!=theirs[0]orours[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 |
413 | 417 |
|
414 | 418 | returnout |