Skip to content

Commit

Permalink
Remove keyRel
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Oct 7, 2019
1 parent 4db328f commit e69ef90
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 218 deletions.
4 changes: 2 additions & 2 deletions doc/help/elektra-key-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ If two keys start with the same key names, but one key name continues
after a slash, this key is **below** the other and is called a
_subkey_. For example `user/sw/apps/abc/current` is a subkey of the
key `user/sw/apps`. The key is not directly below but, for example,
`user/sw/apps/abc` is. `keyRel()` implements a way to decide the relation
between two keys.
`user/sw/apps/abc` is. Various functions in `keytest` implement
ways to determine the relationship between two keys.

## Conventions

Expand Down
3 changes: 2 additions & 1 deletion doc/man/man7/elektra-key-names.7
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ user/sw/kde/kicker/#0/current/preferred_applications/#0
.IP "" 0
.
.P
The slash (\fB/\fR) separates key names and structures them hierarchically\. If two keys start with the same key names, but one key name continues after a slash, this key is \fBbelow\fR the other and is called a \fIsubkey\fR\. For example \fBuser/sw/apps/abc/current\fR is a subkey of the key \fBuser/sw/apps\fR\. The key is not directly below but, for example, \fBuser/sw/apps/abc\fR is\. \fBkeyRel()\fR implements a way to decide the relation between two keys\.
The slash (\fB/\fR) separates key names and structures them hierarchically\. If two keys start with the same key names, but one key name continues after a slash, this key is \fBbelow\fR the other and is called a \fIsubkey\fR\. For example \fBuser/sw/apps/abc/current\fR is a subkey of the key \fBuser/sw/apps\fR\. The key is not directly below but, for example, \fBuser/sw/apps/abc\fR is\. Various functions in \fBkeytest\fR implement
ways to determine the relationship between two keys\.
.
.SH "Conventions"
For computers Elektra would work without any conventions, because it is possible to rename keys with plugins and link and transform any key\-value to any other key\-value\. Obviously, for humans such chaos would be confusing and harder to use, thus we encourage everyone to use the following conventions:
Expand Down
1 change: 0 additions & 1 deletion doc/todo/FUTURE
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Remove/Refactor/Rename obsolete/not needed methods:
- keyNextMeta
- keyCurrentMeta
- keyCmp
- keyRel
- keyNeedSync
- keyIsBelow
- keyIsBelowOrSame
Expand Down
1 change: 0 additions & 1 deletion src/include/kdb.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ ssize_t keySetMeta(Key *key, const char* metaName,

/* Methods for Making Tests */
int keyCmp(const Key *k1, const Key *k2);
int keyRel (const Key *k1, const Key *k2);

int keyNeedSync(const Key *key);

Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Backend * backendOpen (KeySet * elektraConfig, KeySet * modules, KeySet * global

while ((cur = ksNext (elektraConfig)) != 0)
{
if (keyRel (root, cur) == 1)
if (keyIsDirectBelow (root, cur) == 1)
{
// direct below root key
KeySet * cut = ksCut (elektraConfig, cur);
Expand Down
5 changes: 0 additions & 5 deletions src/libs/elektra/keyset.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,6 @@ static int keyCompareByNameOwnerCase (const void * p1, const void * p2)
*
* @note the owner will only be used if the names are equal.
*
* Often is enough to know if the other key is
* less then or greater than the other one.
* But Sometimes you need more precise information,
* see keyRel().
*
* Given any Keys k1 and k2 constructed with keyNew(), following
* equation hold true:
*
Expand Down
143 changes: 0 additions & 143 deletions src/libs/elektra/keytest.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,149 +348,6 @@ int keyIsDirectlyBelow (const Key * key, const Key * check)
}


/**
* Information about the relation in the hierarchy between
* two keys.
*
* Unlike keyCmp() the number gives information
* about hierarchical information.
*
*
* - If the keys are the same 0 is returned.
* So it is the key itself.
@verbatim
user/key
user/key
@endverbatim
*
*@code
keySetName (key, "user/key/folder");
keySetName (check, "user/key/folder");
succeed_if (keyRel (key, check) == 0, "should be same");
*@endcode
*
* @note this relation can be checked with keyCmp() too.
*
*
* - If the key is direct below the other one 1 is returned.
* That means that, in terms of hierarchy, no other key is
* between them - it is a direct child.
@verbatim
user/key/folder
user/key/folder/child
@endverbatim
*
*@code
keySetName (key, "user/key/folder");
keySetName (check, "user/key/folder/child");
succeed_if (keyRel (key, check) == 1, "should be direct below");
*@endcode
*
*
* - If the key is below the other one, but not directly 2 is returned.
* This is also called grand-child.
@verbatim
user/key/folder
user/key/folder/any/depth/deeper/grand-child
@endverbatim
*
*
*@code
keySetName (key, "user/key/folder");
keySetName (check, "user/key/folder/any/depth/deeper/grand-child");
succeed_if (keyRel (key, check) >= 2, "should be below (but not direct)");
succeed_if (keyRel (key, check) > 0, "should be below");
succeed_if (keyRel (key, check) >= 0, "should be the same or below");
*@endcode
*
*
* - If an invalid or null ptr key is passed, -1 is returned
*
*
* - If the keys have no relations, but are not invalid, -2 is returned.
*
*
* - If the keys are in the same hierarchy, a value smaller then -2 is returned.
* It means that the key is not below.
@verbatim
user/key/myself
user/key/sibling
@endverbatim
*
* @code
keySetName (key, "user/key/folder");
keySetName (check, "user/notsame/folder");
succeed_if (keyRel (key, check) < -2, "key is not below, but same namespace");
* @endcode
*
* @code
* @endcode
*
*
* TODO Below is an idea how it could be extended:
* It could continue the search into the other direction
* if any (grand-)parents are equal.
*
* - If the keys are direct below a key which is next to the key, -2 is returned.
* This is also called nephew. (TODO not implemented)
* @verbatim
user/key/myself
user/key/sibling
@endverbatim
*
* - If the keys are direct below a key which is next to the key, -2 is returned.
* This is also called nephew. (TODO not implemented)
* @verbatim
user/key/myself
user/key/sibling/nephew
@endverbatim
*
* - If the keys are below a key which is next to the key, -3 is returned.
* This is also called grand-nephew. (TODO not implemented)
@verbatim
user/key/myself
user/key/sibling/any/depth/deeper/grand-nephew
@endverbatim
*
* The same holds true for the other direction, but with negative values.
* For no relation INT_MIN is returned.
*
* @note to check if the keys are the same, you must use
* keyCmp() == 0!
* keyRel() does not give you the information if it did not
* find a relation or if it is the same key.
*
* @return depending on the relation
* @retval 2 if below
* @retval 1 if direct below
* @retval 0 if the same
* @retval -1 on null or invalid keys
* @retval -2 if none of any other relation
* @retval -3 if same hierarchy (none of those below)
* @retval -4 if sibling (in same hierarchy)
* @retval -5 if nephew (in same hierarchy)
*
* @param key the key object to work with
* @param check the second key object to check the relation with
* @ingroup keytest
*/
int keyRel (const Key * key, const Key * check)
{
if (!key || !check) return -1;
if (!key->key || !check->key) return -1;

if (!keyCmp (key, check)) return 0;
if (keyIsDirectlyBelow (key, check)) return 1;
if (keyIsBelow (key, check)) return 2;
if (keyIsUser (key) && keyIsUser (check)) return -3;
if (keyIsSystem (key) && keyIsSystem (check)) return -3;
// if (keyIsSibling(key, check)) return -4;
// if (keyIsNephew(key, check)) return -5;

return -2;
}


/**
* Check whether a key is inactive.
*
Expand Down
6 changes: 3 additions & 3 deletions src/libs/elektra/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int mountOpen (KDB * kdb, KeySet * config, KeySet * modules, Key * errorKey)
int ret = 0;
while ((cur = ksNext (config)) != 0)
{
if (keyRel (root, cur) == 1)
if (keyIsDirectBelow (root, cur) == 1)
{
KeySet * cut = ksCut (config, cur);
Backend * backend = backendOpen (cut, modules, kdb->global, errorKey);
Expand Down Expand Up @@ -398,7 +398,7 @@ int mountGlobals (KDB * kdb, KeySet * keys, KeySet * modules, Key * errorKey)
while ((cur = ksNext (global)) != NULL)
{
// the cutpoints for the plugin configs are always directly below the "root", ignore everything else
if (keyRel (root, cur) != 1) continue;
if (keyIsDirectBelow (root, cur) != 1) continue;

char * placement = elektraStrDup (keyBaseName (cur));

Expand Down Expand Up @@ -432,7 +432,7 @@ int mountGlobals (KDB * kdb, KeySet * keys, KeySet * modules, Key * errorKey)
Key * curSubPosition;
while ((curSubPosition = ksNext (subPositions)) != NULL)
{
if (keyRel (placementKey, curSubPosition) != 1) continue;
if (keyIsDirectBelow (placementKey, curSubPosition) != 1) continue;
const char * subPlacement = keyBaseName (curSubPosition);

for (GlobalpluginSubPositions j = 0; j < NR_GLOBAL_SUBPOSITIONS; ++j)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int elektraProcessPlugins (Plugin ** plugins, KeySet * modules, KeySet * referen

while ((cur = ksNext (config)) != 0)
{
if (keyRel (root, cur) == 1)
if (keyIsDirectBelow (root, cur) == 1)
{
char * pluginName = 0;
char * referenceName = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/elektra/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,16 @@ int splitBuildup (Split * split, KDB * kdb, Key * parentKey)
/* Catch all: add all mountpoints */
splitAppend (split, kdb->split->handles[i], keyDup (kdb->split->parents[i]), kdb->split->syncbits[i]);
}
else if (backend == kdb->split->handles[i] && keyRel (kdb->split->parents[i], parentKey) >= 0)
else if (backend == kdb->split->handles[i] &&
(keyCmp (kdb->split->parents[i], parentKey) == 0 || keyIsBelow (kdb->split->parents[i], parentKey) == 1))
{
#if DEBUG && VERBOSE
printf (" exa add %s\n", keyName (kdb->split->parents[i]));
#endif
/* parentKey is exactly in this backend, so add it! */
splitAppend (split, kdb->split->handles[i], keyDup (kdb->split->parents[i]), kdb->split->syncbits[i]);
}
else if (keyRel (parentKey, kdb->split->parents[i]) >= 0)
else if (keyCmp (parentKey, kdb->split->parents[i]) == 0 || keyIsBelow (parentKey, kdb->split->parents[i]) == 1)
{
#if DEBUG && VERBOSE
printf (" rel add %s\n", keyName (kdb->split->parents[i]));
Expand Down
1 change: 0 additions & 1 deletion src/libs/elektra/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ libelektra_0.8 {
keyNeedSync;
keyNew;
keyNextMeta;
keyRel;
keyRewindMeta;
keySetBaseName;
keySetBinary;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/csvstorage/csvstorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ static int csvWrite (KeySet * returned, Key * parentKey, KeySet * exportKS, Key
ksRewind (returned);
while ((cur = ksNext (returned)) != NULL)
{
if (keyRel (parentKey, cur) != 1) continue;
if (keyIsDirectBelow (parentKey, cur) != 1) continue;
colCounter = 0;
if (useHeader)
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dump/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extern "C" {
int elektraDumpGet (ckdb::Plugin *, ckdb::KeySet * returned, ckdb::Key * parentKey)
{
Key * root = ckdb::keyNew ("system/elektra/modules/dump", KEY_END);
if (keyRel (root, parentKey) >= 0)
if (keyCmp (root, parentKey) == 0 || keyIsBelow (root, parentKey) == 1)
{
keyDel (root);
KeySet * n = ksNew (50, keyNew ("system/elektra/modules/dump", KEY_VALUE, "dump plugin waits for your orders", KEY_END),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/hexcode/hexcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ int elektraHexcodeOpen (Plugin * handle, Key * key ELEKTRA_UNUSED)
while ((cur = ksNext (config)) != 0)
{
/* ignore all keys not direct below */
if (keyRel (root, cur) == 1)
if (keyIsDirectBelow (root, cur) == 1)
{
/* ignore invalid size */
if (keyGetBaseNameSize (cur) != 3) continue;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/hosts/hosts-set.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void writeHostsEntry (Key * key, KeySet * returned, FILE * fp)
Key * alias;
while ((alias = ksNext (returned)) != 0)
{
if (keyRel (key, alias) < 1) break;
if (keyIsBelow (key, alias) != 1) break;

fprintf (fp, " %s", (char *) keyBaseName (alias));
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int listParseConfiguration (Placements * placements, KeySet * config)
int rc = 0;
while ((cur = ksNext (cutKS)) != NULL)
{
if (keyRel (key, cur) != 1)
if (keyIsDirectBelow (key, cur) != 1)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mmapstorage/mmapstorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ int ELEKTRA_PLUGIN_FUNCTION (get) (Plugin * handle ELEKTRA_UNUSED, KeySet * ks,
}

Key * root = keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME, KEY_END);
if (keyRel (root, parentKey) >= 0)
if (keyCmp (root, parentKey) == 0 || keyIsBelow (root, parentKey) == 1)
{
keyDel (root);
KeySet * contract =
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/noresolver/noresolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int elektraNoresolverGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEK

Key * root = keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME, KEY_END);

if (keyRel (root, parentKey) >= 0)
if (keyCmp (root, parentKey) == 0 || keyIsBelow (root, parentKey) == 1)
{
keyDel (root);
KeySet * info = elektraNoresolverModules ();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/resolver/resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ int ELEKTRA_PLUGIN_FUNCTION (get) (Plugin * handle, KeySet * returned, Key * par
{
Key * root = keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME, KEY_END);

if (keyRel (root, parentKey) >= 0)
if (keyCmp (root, parentKey) == 0 || keyIsBelow (root, parentKey) == 1)
{
keyDel (root);
KeySet * info =
Expand Down
Loading

0 comments on commit e69ef90

Please sign in to comment.