From 2b8696130d60f594c7029293ec7a2f58d113ddab Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 10 Jun 2022 14:57:39 +0200 Subject: [PATCH] Added CLANGUML_GIT_TOPLEVEL_DIR env var for adjusting diagram link paths --- src/util/util.cc | 15 +++++++++++++++ src/util/util.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/util/util.cc b/src/util/util.cc index 7a4c2165..bd163c80 100644 --- a/src/util/util.cc +++ b/src/util/util.cc @@ -56,6 +56,16 @@ std::string get_process_output(const std::string &command) return result; } +std::string get_env(const std::string &name) +{ + const char *value = std::getenv(name.c_str()); + + if (value == nullptr) + return {}; + + return std::string{value}; +} + bool is_git_repository() { #if defined(_WIN32) || defined(_WIN64) @@ -84,6 +94,11 @@ std::string get_git_commit() std::string get_git_toplevel_dir() { + const auto env_toplevel_dir = get_env("CLANGUML_GIT_TOPLEVEL_DIR"); + + if (!env_toplevel_dir.empty()) + return env_toplevel_dir; + return trim(get_process_output("git rev-parse --show-toplevel")); } diff --git a/src/util/util.h b/src/util/util.h index abf1a84e..b01e17f8 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -62,6 +62,8 @@ void setup_logging(bool verbose); std::string get_process_output(const std::string &command); +std::string get_env(const std::string &name); + bool is_git_repository(); std::string get_git_branch();