Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Implementation of OneSideStrategy
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <helper/keyhelper.hpp>
11 : #include <merging/onesidevaluestrategy.hpp>
12 : #include <string>
13 :
14 : using namespace std;
15 : using namespace kdb::tools::helper;
16 :
17 : namespace kdb
18 : {
19 :
20 : namespace tools
21 : {
22 :
23 : namespace merging
24 : {
25 :
26 0 : void OneSideValueStrategy::resolveConflict (const MergeTask & task, Key & conflictKey, MergeResult & result)
27 : {
28 0 : ConflictOperation ourOperation = getOurConflictOperation (conflictKey);
29 0 : ConflictOperation theirOperation = getTheirConflictOperation (conflictKey);
30 :
31 0 : string ourLookup = rebasePath (conflictKey, task.mergeRoot, task.ourParent);
32 0 : string theirLookup = rebasePath (conflictKey, task.mergeRoot, task.theirParent);
33 :
34 : // TODO: this is a subset of the onesidestrategy
35 : // the onesidestrategy could be split up into several smaller strategies
36 0 : if ((ourOperation == CONFLICT_SAME && theirOperation == CONFLICT_MODIFY) ||
37 0 : (ourOperation == CONFLICT_MODIFY && theirOperation == CONFLICT_SAME))
38 : {
39 0 : string lookupPath;
40 0 : Key winningKey;
41 :
42 0 : switch (winningSide)
43 : {
44 : case BASE:
45 0 : lookupPath = rebasePath (conflictKey, task.mergeRoot, task.baseParent);
46 0 : winningKey = task.base.lookup (lookupPath);
47 0 : break;
48 : case OURS:
49 0 : lookupPath = rebasePath (conflictKey, task.mergeRoot, task.ourParent);
50 0 : winningKey = task.ours.lookup (lookupPath);
51 0 : break;
52 : case THEIRS:
53 0 : lookupPath = rebasePath (conflictKey, task.mergeRoot, task.theirParent);
54 0 : winningKey = task.theirs.lookup (lookupPath);
55 0 : break;
56 : }
57 :
58 0 : if (winningKey)
59 : {
60 0 : copyKeyValue (winningKey, conflictKey);
61 0 : result.resolveConflict (conflictKey);
62 0 : result.addMergeKey (conflictKey);
63 : }
64 : }
65 0 : }
66 : } // namespace merging
67 : } // namespace tools
68 : } // namespace kdb
|