Closed (fixed)
Project:
Multiversion
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 May 2016 at 12:04 UTC
Updated:
9 Jul 2016 at 11:54 UTC
Jump to comment: Most recent
This issue will be used to track the work needed to create two new Composer libraries, as per the first steps of this GSoC proposal: https://summerofcode.withgoogle.com/serve/6537380831952896/
We should depend on clue/graph and graphp/algorithms for creating and traversing the graph. There might even be solutions for LCA in these libraries that we should look for.
Stub code:
namespace Relaxed\LCA\LowestCommonAncerstor;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Graph;
class LowestCommonAncestor {
function __construct(Graph $graph) {
$this->graph = $graph;
}
function find(Vertex $local, Vertex $remote) {
// @TODO
return $ancestor;
}
}
Example use:
use \Fhaculty\Graph\Graph as Graph;
use Relaxed\LCA\LowestCommonAncerstor as LCA;
$graph = new Graph();
// Create vertices.
$rev_a = $graph->createVertex('revision-A');
$rev_b = $graph->createVertex('revision-B');
$rev_c1 = $graph->createVertex('revision-C1');
$rev_c2 = $graph->createVertex('revision-C2');
// Connect edges.
$rev_b->createEdgeTo($rev_a);
$rev_c1->createEdgeTo($rev_b);
$rev_c2->createEdgeTo($rev_b);
// Search
$lca = new LCA($graph);
$ancestor = $lca->find($rev_c1, $rev_c2);
// In the above example $rev_b == $ancestor
The three-way merge library should work on normalized arrays and be able to create a merge out of an original, local and remote versions of an array.
Ideally the algorithm should also handle merging of fields with multiple lines of text.
Stub code:
namespace Relaxed\Merge\ThreeWayMerge;
class ThreeWayMerge {
function do(array $ancestor, array $local, array $remote) {
// @TODO
if ($conflict) {
throw new MergeConflictException();
}
return $merged;
}
}
Example use:
use Relaxed\Merge\ThreeWayMerge;
$original = [
'title' => 'abc',
'body' => "lorem ipsum",
];
$local = [
'title' => 'abc',
'body' => 'dolor',
];
$remote = [
'title' => '123',
'body' => 'lorem ipsum',
];
$merge = new ThreeWayMerge();
$merged = $merge->do($original, $local, $remote);
// $merged = [
// 'title' => '123',
// 'body' => 'dolor',
// ];
Both libraries should have PHPUnit tests.
Comments
Comment #2
dixon_Comment #3
dixon_Comment #4
dixon_Comment #5
dixon_Comment #6
dixon_Comment #7
dixon_Comment #8
rakesh_verma commentedIf B is direct child of A and C is direct child of B, what would be the LCA of B and C? B or A??
Comment #9
jeqq commented@rakesh_verma the LCA of
BandC, in this case, would beB.Comment #10
rakesh_verma commentedLibrary for LCA
Library to perform 3-way merge Algorithm
Comment #11
dixon_Marking this issue as fixed. As the libraries are done.