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/newkeystrategy.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 8 : void NewKeyStrategy::resolveConflict (const MergeTask & task, Key & conflictKey, MergeResult & result)
27 : {
28 :
29 8 : ConflictOperation ourOperation = getOurConflictOperation (conflictKey);
30 8 : ConflictOperation theirOperation = getTheirConflictOperation (conflictKey);
31 :
32 16 : string ourLookup = rebasePath (conflictKey, task.mergeRoot, task.ourParent);
33 16 : string theirLookup = rebasePath (conflictKey, task.mergeRoot, task.theirParent);
34 :
35 : // TODO: this is a subset of the automergestrategy
36 : // the automergestrategy could be split up into several smaller strategies
37 8 : switch (ourOperation)
38 : {
39 : case CONFLICT_SAME:
40 4 : if (theirOperation == CONFLICT_ADD)
41 : {
42 12 : Key source = task.theirs.lookup (theirLookup);
43 4 : copyKeyValue (source, conflictKey);
44 4 : result.resolveConflict (conflictKey);
45 4 : result.addMergeKey (conflictKey);
46 : }
47 : break;
48 : case CONFLICT_ADD:
49 4 : if (theirOperation == CONFLICT_SAME)
50 : {
51 12 : Key source = task.ours.lookup (ourLookup);
52 4 : copyKeyValue (source, conflictKey);
53 4 : result.resolveConflict (conflictKey);
54 4 : result.addMergeKey (conflictKey);
55 : }
56 : break;
57 : default:
58 : break;
59 : }
60 8 : }
61 : } // namespace merging
62 : } // namespace tools
63 : } // namespace kdb
|