-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial framework for experimental three way merge (#188)
* Start smartmerge * Testable * paths * foo * Apply add * control deltas addremove * Merging! * Test fix * Clear entropy on merge * start clone * clone * Remove rename logic * Cleanup * Copyright header, warning in Program.cs * PR Feedback, IClonable, moved ControlPath
- Loading branch information
Showing
18 changed files
with
798 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.PowerPlatform.Formulas.Tools.MergeTool; | ||
using Microsoft.PowerPlatform.Formulas.Tools.MergeTool.Deltas; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.PowerPlatform.Formulas.Tools | ||
{ | ||
public static class CanvasMerger | ||
{ | ||
public static CanvasDocument Merge(CanvasDocument ours, CanvasDocument theirs, CanvasDocument commonParent) | ||
{ | ||
var ourDeltas = Diff.ComputeDelta(commonParent, ours); | ||
var theirDeltas = Diff.ComputeDelta(commonParent, theirs); | ||
|
||
var resultDelta = UnionDelta(ourDeltas, theirDeltas); | ||
|
||
return ApplyDelta(commonParent, resultDelta); | ||
} | ||
|
||
// fix these to be hashsets eventually? | ||
private static IEnumerable<IDelta> UnionDelta(IEnumerable<IDelta> ours, IEnumerable<IDelta> theirs) | ||
{ | ||
var resultDeltas = new List<IDelta>(); | ||
|
||
// If we apply the removes before the adds, adds will fail if they're in a tree that's been removed | ||
// This is intended but we should talk about it | ||
resultDeltas.AddRange(ours.OfType<RemoveControl>()); | ||
resultDeltas.AddRange(theirs.OfType<RemoveControl>()); | ||
|
||
resultDeltas.AddRange(ours.OfType<AddControl>()); | ||
resultDeltas.AddRange(theirs.OfType<AddControl>()); | ||
|
||
var ourPropChanges = ours.OfType<ChangeProperty>(); | ||
var theirPropChanges = theirs.OfType<ChangeProperty>(); | ||
resultDeltas.AddRange(ourPropChanges); | ||
resultDeltas.AddRange(theirPropChanges.Where(change => !ourPropChanges.Any(ourChange => ourChange.PropertyName == change.PropertyName && ourChange.ControlPath.Equals(change.ControlPath)))); | ||
return resultDeltas; | ||
} | ||
|
||
|
||
private static CanvasDocument ApplyDelta(CanvasDocument parent, IEnumerable<IDelta> delta) | ||
{ | ||
var result = new CanvasDocument(parent); | ||
foreach (var change in delta) | ||
{ | ||
change.Apply(result); | ||
} | ||
|
||
if (delta.Any()) | ||
{ | ||
result._entropy = new Entropy(); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.