diff --git a/Frameworks/scm/src/drivers/api.h b/Frameworks/scm/src/drivers/api.h index 146da8c9..c51428fb 100644 --- a/Frameworks/scm/src/drivers/api.h +++ b/Frameworks/scm/src/drivers/api.h @@ -10,7 +10,7 @@ namespace scm { driver_t (std::string const& name, std::string const& wcRootFormatString, std::string const& requiredExecutable = NULL_STR); - virtual std::string branch_name (std::string const& wcPath) const = 0; + virtual std::map variables (std::string const& wcPath) const = 0; virtual status_map_t status (std::string const& wcPath) const = 0; std::string const& name () const { return _name; } diff --git a/Frameworks/scm/src/drivers/git.cc b/Frameworks/scm/src/drivers/git.cc index d061096d..9b368e88 100644 --- a/Frameworks/scm/src/drivers/git.cc +++ b/Frameworks/scm/src/drivers/git.cc @@ -219,24 +219,27 @@ namespace scm { git_driver_t () : driver_t("git", "%s/.git", "git") { } - std::string branch_name (std::string const& wcPath) const + std::map variables (std::string const& wcPath) const { - if(executable() == NULL_STR) - return NULL_STR; + D(DBF_SCM_Git, bug("%s\n", wcPath.c_str());); + std::map res = { { "TM_SCM_NAME", name() } }; + if(executable() != NULL_STR) + { + std::map env = oak::basic_environment(); + env["GIT_WORK_TREE"] = wcPath; + env["GIT_DIR"] = path::join(wcPath, ".git"); - std::map env = oak::basic_environment(); - env["GIT_WORK_TREE"] = wcPath; - env["GIT_DIR"] = path::join(wcPath, ".git"); - - bool haveHead = io::exec(env, executable(), "show-ref", "-qh", NULL) != NULL_STR; - if(!haveHead) - return NULL_STR; - - std::string branchName = io::exec(env, executable(), "symbolic-ref", "HEAD", NULL); - branchName = branchName.substr(0, branchName.find("\n")); - if(branchName.find("refs/heads/") == 0) - branchName = branchName.substr(11); - return branchName; + bool haveHead = io::exec(env, executable(), "show-ref", "-qh", NULL) != NULL_STR; + if(haveHead) + { + std::string branchName = io::exec(env, executable(), "symbolic-ref", "HEAD", NULL); + branchName = branchName.substr(0, branchName.find("\n")); + if(branchName.find("refs/heads/") == 0) + branchName = branchName.substr(11); + res.insert(std::make_pair("TM_SCM_BRANCH", branchName)); + } + } + return res; } status_map_t status (std::string const& wcPath) const diff --git a/Frameworks/scm/src/drivers/hg.cc b/Frameworks/scm/src/drivers/hg.cc index df0725a3..57522b8a 100644 --- a/Frameworks/scm/src/drivers/hg.cc +++ b/Frameworks/scm/src/drivers/hg.cc @@ -58,13 +58,15 @@ namespace scm bool may_touch_filesystem () const { return true; } - std::string branch_name (std::string const& wcPath) const + std::map variables (std::string const& wcPath) const { - if(executable() == NULL_STR) - return NULL_STR; - - std::string branchName = io::exec(executable(), "branch", "--cwd", wcPath.c_str(), NULL); - return branchName.substr(0, branchName.find("\n")); + std::map res = { { "TM_SCM_NAME", name() } }; + if(executable() != NULL_STR) + { + std::string branchName = io::exec(executable(), "branch", "--cwd", wcPath.c_str(), NULL); + res.insert(std::make_pair("TM_SCM_BRANCH", branchName.substr(0, branchName.find("\n")))); + } + return res; } status_map_t status (std::string const& wcPath) const diff --git a/Frameworks/scm/src/drivers/p4.cc b/Frameworks/scm/src/drivers/p4.cc index 36e45271..d33833bd 100644 --- a/Frameworks/scm/src/drivers/p4.cc +++ b/Frameworks/scm/src/drivers/p4.cc @@ -9,9 +9,10 @@ namespace scm { p4_driver_t () : driver_t("p4", "%s/.p4config") { } - std::string branch_name (std::string const& wcPath) const + std::map variables (std::string const& wcPath) const { - return NULL_STR; + D(DBF_SCM_Perforce, bug("%s\n", wcPath.c_str());); + return std::map{ { "TM_SCM_NAME", name() } }; } status_map_t status (std::string const& wcPath) const diff --git a/Frameworks/scm/src/drivers/svn.cc b/Frameworks/scm/src/drivers/svn.cc index 4b894274..c7c2ca7a 100644 --- a/Frameworks/scm/src/drivers/svn.cc +++ b/Frameworks/scm/src/drivers/svn.cc @@ -111,14 +111,18 @@ namespace scm fprintf(stderr, "%s: Unable to locate ‘svn_status.xslt’.\n", getprogname()); } - std::string branch_name (std::string const& wcPath) const + std::map variables (std::string const& wcPath) const { - if(executable() == NULL_STR) - return NULL_STR; - - auto info = parse_info_output(io::exec(executable(), "info", wcPath.c_str(), NULL)); - auto urlInfo = info.find("URL"); - return urlInfo != info.end() ? urlInfo->second : NULL_STR; + D(DBF_SCM_Svn, bug("%s\n", wcPath.c_str());); + std::map res = { { "TM_SCM_NAME", name() } }; + if(executable() != NULL_STR) + { + auto info = parse_info_output(io::exec(executable(), "info", wcPath.c_str(), NULL)); + auto urlInfo = info.find("URL"); + if(urlInfo != info.end()) + res.insert(std::make_pair("TM_SCM_BRANCH", urlInfo->second)); + } + return res; } status_map_t status (std::string const& wcPath) const diff --git a/Frameworks/scm/src/scm.cc b/Frameworks/scm/src/scm.cc index 1d733499..6cc38295 100644 --- a/Frameworks/scm/src/scm.cc +++ b/Frameworks/scm/src/scm.cc @@ -191,12 +191,9 @@ namespace scm { if(!info->_driver->may_touch_filesystem() || info->_fs_snapshot != fs::snapshot_t(info->_root_path)) { - std::map variables{ { "TM_SCM_NAME", info->_driver->name() } }; - std::string const branch = info->_driver->branch_name(info->_root_path); - if(branch != NULL_STR) - variables.insert(std::make_pair("TM_SCM_BRANCH", branch)); - scm::status_map_t const status = info->_driver->status(info->_root_path); - fs::snapshot_t const snapshot = info->_driver->may_touch_filesystem() ? fs::snapshot_t(info->_root_path) : fs::snapshot_t(); + auto const status = info->_driver->status(info->_root_path); + auto const variables = info->_driver->variables(info->_root_path); + auto const snapshot = info->_driver->may_touch_filesystem() ? fs::snapshot_t(info->_root_path) : fs::snapshot_t(); dispatch_async(dispatch_get_main_queue(), ^{ if(shared_info_ptr info = weakThis.lock()) info->update(variables, status, snapshot);