Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Implementation of InteractiveMergeStrategy
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <helper/keyhelper.hpp>
11 : #include <merging/interactivemergestrategy.hpp>
12 : #include <merging/onesidestrategy.hpp>
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 outputKeyInfo (string whichKey, Key & key, ostream & outputStream)
27 : {
28 0 : if (!key)
29 : {
30 0 : outputStream << whichKey << ": does not exist" << endl;
31 : }
32 : else
33 : {
34 0 : outputStream << whichKey << " value: " << key.getString () << endl;
35 : }
36 0 : }
37 :
38 0 : void InteractiveMergeStrategy::resolveConflict (const MergeTask & task, Key & conflictKey, MergeResult & result)
39 : {
40 0 : ConflictOperation ours = getOurConflictOperation (conflictKey);
41 0 : ConflictOperation theirs = getTheirConflictOperation (conflictKey);
42 :
43 0 : outputStream << "merging key " << conflictKey.getName () << endl;
44 0 : outputStream << endl;
45 0 : outputStream << "======== CONFLICT ========" << endl;
46 0 : outputStream << "our operation: " << MergeConflictOperation::getFromTag (ours) << endl;
47 0 : outputStream << "their operation: " << MergeConflictOperation::getFromTag (theirs) << endl;
48 0 : outputStream << endl;
49 :
50 0 : Key baseKey = task.base.lookup (rebasePath (conflictKey, task.mergeRoot, task.baseParent));
51 0 : Key ourKey = task.ours.lookup (rebasePath (conflictKey, task.mergeRoot, task.ourParent));
52 0 : Key theirKey = task.theirs.lookup (rebasePath (conflictKey, task.mergeRoot, task.theirParent));
53 :
54 0 : outputStream << "======== KEY VALUES ========" << endl;
55 0 : outputKeyInfo ("base", baseKey, outputStream);
56 0 : outputKeyInfo ("ours", ourKey, outputStream);
57 0 : outputKeyInfo ("theirs", theirKey, outputStream);
58 :
59 0 : outputStream << endl;
60 :
61 : char choice;
62 :
63 : ConflictResolutionSide side;
64 :
65 : bool repeat;
66 0 : string input;
67 0 : do
68 : {
69 0 : outputStream << "What do you want to do?" << endl;
70 0 : outputStream << "Take [o]urs, [t]eirs, [b]ase, [m]erge meta: ";
71 :
72 0 : repeat = false;
73 0 : getline (inputStream, input);
74 :
75 0 : if (input.size () == 0 || input.size () > 1)
76 : {
77 : repeat = true;
78 : continue;
79 : }
80 :
81 0 : choice = input.at (0);
82 :
83 0 : switch (choice)
84 : {
85 : case 'o':
86 0 : side = OURS;
87 0 : outputStream << "Choose our key" << endl;
88 : break;
89 : case 't':
90 0 : side = THEIRS;
91 0 : outputStream << "Choose their key" << endl;
92 : break;
93 : case 'b':
94 0 : side = BASE;
95 0 : outputStream << "Choose base key" << endl;
96 : break;
97 : default:
98 : repeat = true;
99 : }
100 : } while (repeat);
101 :
102 0 : outputStream << endl;
103 :
104 0 : OneSideStrategy strategy (side);
105 0 : strategy.resolveConflict (task, conflictKey, result);
106 0 : outputStream << "Key merged..." << endl;
107 0 : }
108 : } // namespace merging
109 : } // namespace tools
110 : } // namespace kdb
|