From bb6cc8584e658918e696c3bcb9b9eeb73c305c49 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Fri, 7 Jun 2019 14:14:03 +0300
Subject: [PATCH] Allow branch change on exit

---
 applications/vision/src/main.cpp                    |  3 +++
 components/common/cpp/include/ftl/configuration.hpp |  1 +
 components/common/cpp/src/configuration.cpp         | 10 ++++++++++
 3 files changed, 14 insertions(+)

diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp
index aba47f6cd..4190a90d0 100644
--- a/applications/vision/src/main.cpp
+++ b/applications/vision/src/main.cpp
@@ -96,6 +96,8 @@ static void run(ftl::Configurable *root) {
 	stream->add(source);
 	stream->run();
 
+	LOG(INFO) << "Running...";
+
 	while (ftl::running && display->active()) {
 		cv::Mat rgb, depth;
 		source->getRGBD(rgb, depth);
@@ -130,6 +132,7 @@ int main(int argc, char **argv) {
 
 	delete root;
 	LOG(INFO) << "Terminating with code " << ftl::exit_code;
+	LOG(INFO) << "Branch: " << ftl::branch_name;
 	return ftl::exit_code;
 }
 
diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp
index d38472746..3938b29b7 100644
--- a/components/common/cpp/include/ftl/configuration.hpp
+++ b/components/common/cpp/include/ftl/configuration.hpp
@@ -14,6 +14,7 @@ namespace ftl {
 
 extern bool running;
 extern int exit_code;
+extern std::string branch_name;
 
 class Configurable;
 
diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp
index f8bf95aec..52e8998f8 100644
--- a/components/common/cpp/src/configuration.cpp
+++ b/components/common/cpp/src/configuration.cpp
@@ -49,6 +49,7 @@ static Configurable *rootCFG = nullptr;
 
 bool ftl::running = true;
 int ftl::exit_code = 0;
+std::string ftl::branch_name = "";
 
 bool ftl::is_directory(const std::string &path) {
 #ifdef WIN32
@@ -466,6 +467,15 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r
 	rootcfg->set("paths", paths);
 	process_options(rootcfg, options);
 
+	if (rootcfg->get<std::string>("branch")) {
+		ftl::branch_name = *rootcfg->get<std::string>("branch");
+	}
+	rootcfg->on("branch", [](const ftl::config::Event &e) {
+		if (e.entity->get<std::string>("branch")) {
+			ftl::branch_name = *e.entity->get<std::string>("branch");
+		}
+	});
+
 	//LOG(INFO) << "CONFIG: " << config["vision_default"];
 	//CHECK_EQ( &config, config_index["ftl://utu.fi"] );
 
-- 
GitLab