Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Implementation of AutoMergeStrategy
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <helper/keyhelper.hpp>
11 : #include <merging/automergestrategy.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 346 : void AutoMergeStrategy::resolveConflict (const MergeTask & task, Key & conflictKey, MergeResult & result)
27 : {
28 :
29 346 : ConflictOperation ourOperation = getOurConflictOperation (conflictKey);
30 346 : ConflictOperation theirOperation = getTheirConflictOperation (conflictKey);
31 :
32 692 : string ourLookup = rebasePath (conflictKey, task.mergeRoot, task.ourParent);
33 692 : string theirLookup = rebasePath (conflictKey, task.mergeRoot, task.theirParent);
34 :
35 346 : switch (ourOperation)
36 : {
37 : case CONFLICT_SAME:
38 336 : if (theirOperation == CONFLICT_MODIFY || theirOperation == CONFLICT_ADD)
39 : {
40 831 : Key source = task.theirs.lookup (theirLookup);
41 277 : copyKeyValue (source, conflictKey);
42 277 : result.resolveConflict (conflictKey);
43 277 : result.addMergeKey (conflictKey);
44 : }
45 :
46 336 : if (theirOperation == CONFLICT_DELETE)
47 : {
48 59 : result.resolveConflict (conflictKey);
49 : }
50 : break;
51 : case CONFLICT_MODIFY:
52 : case CONFLICT_ADD:
53 8 : if (theirOperation == CONFLICT_SAME)
54 : {
55 24 : Key source = task.ours.lookup (ourLookup);
56 8 : copyKeyValue (source, conflictKey);
57 8 : result.resolveConflict (conflictKey);
58 8 : result.addMergeKey (conflictKey);
59 : }
60 : break;
61 : case CONFLICT_DELETE:
62 2 : if (theirOperation == CONFLICT_SAME)
63 : {
64 2 : result.resolveConflict (conflictKey);
65 : }
66 : break;
67 : case CONFLICT_META:
68 : break;
69 : }
70 346 : }
71 : } // namespace merging
72 : } // namespace tools
73 : } // namespace kdb
|