This function can incorporate changes from two modified versions (our and their) into a common preceding version (base) of a key set.
This lets you merge the sets of changes represented by the two newer key sets. This is called a three-way merge between key sets.
#include <kdb.h>
#include <stdio.h>
static void print_results (KeySet * result, Key * resultRoot, Key * informationKey)
{
KeySet * conflictingKeys = elektraMergeGetConflictingKeys (informationKey, resultRoot);
for (elektraCursor i = 0; i <
ksGetSize (conflictingKeys); i++)
{
}
printf ("Result:\n");
for (elektraCursor i = 0; i <
ksGetSize (result); i++)
{
}
if (result == NULL)
{
printf ("Aborted.\n");
}
}
int main (void)
{
Key * baseRoot =
keyNew (
"user:/screen", KEY_END);
KeySet * base =
ksNew (1,
keyNew (
"user:/screen/background", KEY_VALUE,
"blue", KEY_END), KS_END);
KeySet * their =
ksNew (2,
keyNew (
"user:/screen/background", KEY_VALUE,
"red", KEY_END),
keyNew (
"user:/screen/brightness", KEY_VALUE,
"100", KEY_END), KS_END);
KeySet * our =
ksNew (2,
keyNew (
"user:/screen/background", KEY_VALUE,
"purple", KEY_END),
keyNew (
"user:/screen/standby", KEY_VALUE,
"on", KEY_END), KS_END);
Key * informationKey = keyDup (baseRoot,
KEY_CP_ALL);
printf ("Trying merge strategy ABORT\n");
KeySet * result = elektraMerge (our, ourRoot, their, theirRoot, base, baseRoot, resultRoot,
MERGE_STRATEGY_ABORT, informationKey);
print_results (result, resultRoot, informationKey);
printf ("\nTrying merge strategy OUR\n");
result = elektraMerge (our, ourRoot, their, theirRoot, base, baseRoot, resultRoot,
MERGE_STRATEGY_OUR, informationKey);
print_results (result, resultRoot, informationKey);
printf ("\nTrying merge strategy THEIR\n");
result = elektraMerge (our, ourRoot, their, theirRoot, base, baseRoot, resultRoot,
MERGE_STRATEGY_THEIR, informationKey);
print_results (result, resultRoot, informationKey);
return 0;
}
int keyDel(Key *key)
A destructor for Key objects.
Definition key.c:459
Key * keyNew(const char *name,...)
A practical way to fully create a Key object in one step.
Definition key.c:144
@ KEY_CP_ALL
Definition kdbenum.c:110
const char * keyName(const Key *key)
Returns a pointer to the abbreviated real internal key name.
Definition elektra/keyname.c:429
int ksDel(KeySet *ks)
A destructor for KeySet objects.
Definition keyset.c:521
ssize_t ksGetSize(const KeySet *ks)
Return the number of Keys that ks contains.
Definition keyset.c:791
Key * ksAtCursor(const KeySet *ks, elektraCursor pos)
Return Key at given position pos.
Definition keyset.c:1978
KeySet * ksNew(size_t alloc,...)
Allocate, initialize and return a new KeySet object.
Definition keyset.c:282
const char * keyString(const Key *key)
Get a pointer to the c-string representing the value.
Definition keyvalue.c:208
@ MERGE_STRATEGY_OUR
Definition kdbmerge.h:28
@ MERGE_STRATEGY_THEIR
Definition kdbmerge.h:29
@ MERGE_STRATEGY_ABORT
Definition kdbmerge.h:26