forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changetracking.c
98 lines (85 loc) · 2.43 KB
/
changetracking.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <kdbchangetracking.h>
#include <kdbprivate.h>
/**
* Returns the changetracking context of the given KDB instance
*
* @param kdb the KDB instance
* @return ChangeTrackingContext or @p NULL if @p kdb is @p NULL
*/
const ChangeTrackingContext * elektraChangeTrackingGetContextFromKdb (KDB * kdb)
{
if (kdb == NULL)
{
return NULL;
}
return &kdb->changeTrackingContext;
}
/**
* Returns the changetracking context for the KDB instance associated with the specified plugin
*
* @param plugin the plugin
* @return ChangeTrackingContext or @p NULL if @p plugin is @p NULL or does not have a @p KDB instance associated with it
*/
const ChangeTrackingContext * elektraChangeTrackingGetContextFromPlugin (Plugin * plugin)
{
if (plugin->global == NULL)
{
return NULL;
}
Key * kdbKey = ksLookupByName (plugin->global, "system:/elektra/kdb", 0);
if (kdbKey == NULL)
{
return NULL;
}
const void * kdbPtr = keyValue (kdbKey);
KDB * kdb = kdbPtr == NULL ? NULL : *(KDB **) keyValue (kdbKey);
return elektraChangeTrackingGetContextFromKdb (kdb);
}
/**
* @internal
*
* @brief For testing purposes only: Create a ChangeTrackingContext from a keyset
*
* @param oldKeys the old keys
* @return a new changetracking context
*/
ChangeTrackingContext * elektraChangeTrackingCreateContextForTesting (KeySet * oldKeys)
{
ChangeTrackingContext * context = elektraCalloc (sizeof (ChangeTrackingContext));
ksIncRef (oldKeys);
context->oldKeys = oldKeys;
return context;
}
/**
* @internal
*
* @brief For testing purposes only: Delete a ChangeTrackingContext object
*
* @param context the object to delete
*/
void elektraChangeTrackingContextDel (ChangeTrackingContext * context)
{
if (context->oldKeys != NULL)
{
ksDecRef (context->oldKeys);
ksDel (context->oldKeys);
context->oldKeys = NULL;
}
elektraFree (context);
}
/**
* Calculates the changes between the provided KeySet and the given ChangeTrackingContext.
*
* @param newKeys the KeySet
* @param context the ChangeTrackingContext
* @param parentKey if not @p NULL, only keys below or same of this key are considered
* @return the changes between @p newKeys and @p context OR @p NULL if either one of them is @p NULL
*/
ElektraDiff * elektraChangeTrackingCalculateDiff (KeySet * newKeys, const ChangeTrackingContext * context, Key * parentKey)
{
if (newKeys == NULL || context == NULL)
{
return NULL;
}
return elektraDiffCalculate (newKeys, context->oldKeys, parentKey);
}