tree_schema REFACTOR latest_revision as bit option
diff --git a/src/context.c b/src/context.c
index 8ed79db..f45be51 100644
--- a/src/context.c
+++ b/src/context.c
@@ -761,7 +761,7 @@
     uint32_t index = 0;
 
     while ((mod = ly_ctx_get_module_by_iter(ctx, key, 0, key_offset, &index))) {
-        if (mod->latest_revision) {
+        if (mod->latest_revision & (LYS_MOD_LATEST_REV | LYS_MOD_LATEST_SEARCHDIRS)) {
             return mod;
         }
     }
@@ -928,13 +928,15 @@
 
     for (uint32_t v = 0; v < ctx->list.count; ++v) {
         mod = ctx->list.objs[v];
-        if (mod->latest_revision == 2) {
-            mod->latest_revision = 1;
+        if (mod->latest_revision & LYS_MOD_LATEST_SEARCHDIRS) {
+            mod->latest_revision &= ~LYS_MOD_LATEST_SEARCHDIRS;
+            mod->latest_revision |= LYS_MOD_LATEST_REV;
         }
         if (mod->parsed && mod->parsed->includes) {
             for (LY_ARRAY_COUNT_TYPE u = 0; u < LY_ARRAY_COUNT(mod->parsed->includes); ++u) {
-                if (mod->parsed->includes[u].submodule->latest_revision == 2) {
-                    mod->parsed->includes[u].submodule->latest_revision = 1;
+                if (mod->parsed->includes[u].submodule->latest_revision & LYS_MOD_LATEST_SEARCHDIRS) {
+                    mod->parsed->includes[u].submodule->latest_revision &= ~LYS_MOD_LATEST_SEARCHDIRS;
+                    mod->parsed->includes[u].submodule->latest_revision |= LYS_MOD_LATEST_REV;
                 }
             }
         }
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 791cd5a..2a399cd 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -1564,10 +1564,10 @@
         if (mod->revision) {
             if (!latest->revision) {
                 /* latest has no revision, so mod is anyway newer */
-                mod->latest_revision = latest->latest_revision;
+                mod->latest_revision = latest->latest_revision & (LYS_MOD_LATEST_REV | LYS_MOD_LATEST_SEARCHDIRS);
                 /* the latest is zeroed later when the new module is being inserted into the context */
             } else if (strcmp(mod->revision, latest->revision) > 0) {
-                mod->latest_revision = latest->latest_revision;
+                mod->latest_revision = latest->latest_revision & (LYS_MOD_LATEST_REV | LYS_MOD_LATEST_SEARCHDIRS);
                 /* the latest is zeroed later when the new module is being inserted into the context */
             } else {
                 latest = NULL;
@@ -1576,7 +1576,7 @@
             latest = NULL;
         }
     } else {
-        mod->latest_revision = 1;
+        mod->latest_revision = LYS_MOD_LATEST_REV;
     }
 
     if (custom_check) {
@@ -1632,7 +1632,7 @@
     lys_parser_fill_filepath(ctx, in, &mod->filepath);
 
     if (latest) {
-        latest->latest_revision = 0;
+        latest->latest_revision &= ~(LYS_MOD_LATEST_REV | LYS_MOD_LATEST_SEARCHDIRS);
     }
 
     /* add internal data in case specific modules were parsed */
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 0c413e0..40fd706 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -2321,13 +2321,22 @@
     ly_bool implemented;             /**< flag if the module is implemented, not just imported */
     ly_bool to_compile;              /**< flag marking a module that was changed but not (re)compiled, see
                                           ::LY_CTX_EXPLICIT_COMPILE. */
-    uint8_t latest_revision;         /**< flag to mark the latest available revision:
-                                          1 - the latest revision in searchdirs was not searched yet and this is the
-                                          latest revision in the current context
-                                          2 - searchdirs were searched and this is the latest available revision */
+    uint8_t latest_revision;         /**< Flag to mark the latest available revision, see [latest_revision options](@ref latestrevflags). */
 };
 
 /**
+ * @defgroup latestrevflags Options for ::lys_module.latest_revision.
+ *
+ * Various information bits of ::lys_module.latest_revision.
+ *
+ * @{
+ */
+#define LYS_MOD_LATEST_REV          0x01 /**< The latest revision in searchdirs was not searched yet
+                                              and this is the latest revision in the current context. */
+#define LYS_MOD_LATEST_SEARCHDIRS   0x02 /**< Searchdirs were searched and this is the latest available revision. */
+/** @} latestrevflags */
+
+/**
  * @brief Get the current real status of the specified feature in the module.
  *
  * If the feature is enabled, but some of its if-features are false, the feature is considered
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 53b552a..785d187 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -828,7 +828,7 @@
         } else {
             /* get the requested module of the latest revision in the context */
             *mod = ly_ctx_get_module_latest(ctx, name);
-            if (*mod && ((*mod)->latest_revision == 1)) {
+            if (*mod && ((*mod)->latest_revision & LYS_MOD_LATEST_REV)) {
                 /* let us now search with callback and searchpaths to check if there is newer revision outside the context */
                 ctx_latest = *mod;
                 *mod = NULL;
@@ -880,10 +880,12 @@
         if (!*mod && ctx_latest) {
             LOGVRB("Newer revision than \"%s@%s\" not found, using this as the latest revision.", ctx_latest->name,
                     ctx_latest->revision);
-            ctx_latest->latest_revision = 2;
+            ctx_latest->latest_revision &= ~LYS_MOD_LATEST_REV;
+            ctx_latest->latest_revision |= LYS_MOD_LATEST_SEARCHDIRS;
             *mod = ctx_latest;
-        } else if (*mod && !revision && ((*mod)->latest_revision == 1)) {
-            (*mod)->latest_revision = 2;
+        } else if (*mod && !revision && ((*mod)->latest_revision & LYS_MOD_LATEST_REV)) {
+            (*mod)->latest_revision &= ~LYS_MOD_LATEST_REV;
+            (*mod)->latest_revision |= LYS_MOD_LATEST_SEARCHDIRS;
         }
 
         if (!*mod) {