mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 04:38:13 -05:00
SCM drivers can return arbitrary variables
These variables are mainly for use in the window title. Not all variables make sense across SCM drivers, hence why it is now completely up to the driver, what variables it provides.
This commit is contained in:
@@ -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<std::string, std::string> 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; }
|
||||
|
||||
@@ -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<std::string, std::string> 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<std::string, std::string> res = { { "TM_SCM_NAME", name() } };
|
||||
if(executable() != NULL_STR)
|
||||
{
|
||||
std::map<std::string, std::string> env = oak::basic_environment();
|
||||
env["GIT_WORK_TREE"] = wcPath;
|
||||
env["GIT_DIR"] = path::join(wcPath, ".git");
|
||||
|
||||
std::map<std::string, std::string> 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
|
||||
|
||||
@@ -58,13 +58,15 @@ namespace scm
|
||||
|
||||
bool may_touch_filesystem () const { return true; }
|
||||
|
||||
std::string branch_name (std::string const& wcPath) const
|
||||
std::map<std::string, std::string> 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<std::string, std::string> 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
|
||||
|
||||
@@ -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<std::string, std::string> variables (std::string const& wcPath) const
|
||||
{
|
||||
return NULL_STR;
|
||||
D(DBF_SCM_Perforce, bug("%s\n", wcPath.c_str()););
|
||||
return std::map<std::string, std::string>{ { "TM_SCM_NAME", name() } };
|
||||
}
|
||||
|
||||
status_map_t status (std::string const& wcPath) const
|
||||
|
||||
@@ -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<std::string, std::string> 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<std::string, std::string> 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
|
||||
|
||||
@@ -191,12 +191,9 @@ namespace scm
|
||||
{
|
||||
if(!info->_driver->may_touch_filesystem() || info->_fs_snapshot != fs::snapshot_t(info->_root_path))
|
||||
{
|
||||
std::map<std::string, std::string> 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);
|
||||
|
||||
Reference in New Issue
Block a user