LCOV - code coverage report
Current view: top level - src/libs/tools/src/merging - mergeresult.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 24 24 100.0 %
Date: 2019-09-12 12:28:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Implementation of MergeResult
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #include <merging/mergeresult.hpp>
      11             : 
      12             : using namespace std;
      13             : 
      14             : namespace kdb
      15             : {
      16             : 
      17             : namespace tools
      18             : {
      19             : 
      20             : namespace merging
      21             : {
      22             : 
      23        1434 : MergeResult::MergeResult () : resolvedKeys (0)
      24             : {
      25         478 : }
      26             : 
      27          52 : MergeResult::MergeResult (KeySet & _conflictSet, KeySet & _mergedKeys)
      28         156 : : conflictSet (_conflictSet), mergedKeys (_mergedKeys), resolvedKeys (0)
      29             : {
      30          52 : }
      31             : 
      32         392 : void MergeResult::addConflict (Key & key, ConflictOperation ourOperation, ConflictOperation theirOperation)
      33             : {
      34             :         key.rewindMeta ();
      35        1525 :         while (Key currentMeta = key.nextMeta ())
      36             :         {
      37         741 :                 key.delMeta (currentMeta.getName ());
      38             :         }
      39             : 
      40         392 :         if (key.isString ())
      41             :         {
      42        1960 :                 key.setString ("");
      43             :         }
      44             :         else
      45             :         {
      46             :                 key.setBinary (nullptr, 0);
      47             :         }
      48             : 
      49         392 :         removeMergeKey (key);
      50        1960 :         key.setMeta ("conflict/operation/our", MergeConflictOperation::getFromTag (ourOperation));
      51        1960 :         key.setMeta ("conflict/operation/their", MergeConflictOperation::getFromTag (theirOperation));
      52         784 :         conflictSet.append (key);
      53         392 : }
      54             : 
      55         382 : void MergeResult::resolveConflict (Key & key)
      56             : {
      57         382 :         key.rewindMeta ();
      58         382 :         Key currentMeta;
      59        6256 :         while ((currentMeta = key.nextMeta ()))
      60             :         {
      61             :                 // TODO: this is just a workaround because keys with a prefix other than
      62             :                 // user/ or system/ cannot be created and therefore isBelow cannot be used
      63        3546 :                 if (currentMeta.getName ().find ("conflict/") == 0)
      64             :                 {
      65        2238 :                         key.delMeta (currentMeta.getName ());
      66             :                 }
      67             :         }
      68             : 
      69        1146 :         conflictSet.lookup (key, KDB_O_POP);
      70         382 :         resolvedKeys++;
      71         382 : }
      72             : } // namespace merging
      73             : } // namespace tools
      74             : } // namespace kdb

Generated by: LCOV version 1.13