Update SCM variables with status

This commit is contained in:
Allan Odgaard
2013-01-19 14:14:13 +01:00
parent 55b6415339
commit 340782dbc9
2 changed files with 17 additions and 10 deletions

View File

@@ -88,9 +88,9 @@ namespace scm
ASSERTF(path::is_directory(_wc_path) || !path::exists(_wc_path) || _wc_path == NULL_STR, "Path: %s\n", _wc_path.c_str());
}
std::string info_t::scm_name () const { return _driver->name(); }
std::string info_t::scm_name () const { auto vars = variables(); auto iter = vars.find("TM_SCM_NAME"); return iter != vars.end() ? iter->second : NULL_STR; }
std::string info_t::path () const { return _wc_path; }
std::string info_t::branch () const { return _driver->branch_name(_wc_path); }
std::string info_t::branch () const { auto vars = variables(); auto iter = vars.find("TM_SCM_BRANCH"); return iter != vars.end() ? iter->second : NULL_STR; }
bool info_t::tracks_directories () const { return _driver->tracks_directories(); }
void info_t::setup ()
@@ -99,6 +99,10 @@ namespace scm
return;
_file_status = _driver->status(_wc_path);
_variables = std::map<std::string, std::string>{
{ "TM_SCM_NAME", _driver->name() },
{ "TM_SCM_BRANCH", _driver->branch_name(_wc_path) }
};
_watcher.reset(new scm::watcher_t(_wc_path, this));
_did_setup = true;
}
@@ -113,11 +117,8 @@ namespace scm
std::map<std::string, std::string> info_t::variables () const
{
auto res = std::map<std::string, std::string>{ { "TM_SCM_NAME", scm_name() } };
std::string const branchName = branch();
if(branchName != NULL_STR)
res.insert(std::make_pair("TM_SCM_BRANCH", branchName));
return res;
const_cast<info_t*>(this)->setup();
return _variables;
}
status_map_t info_t::files_with_status (int mask)
@@ -183,15 +184,19 @@ namespace scm
if(shouldCheck)
{
scm::status_map_t const status = _driver->status(_wc_path);
std::map<std::string, std::string> const variables{
{ "TM_SCM_NAME", _driver->name() },
{ "TM_SCM_BRANCH", _driver->branch_name(_wc_path) }
};
fs::snapshot_t const snapshot = _driver->may_touch_filesystem() ? fs::snapshot_t(_wc_path) : fs::snapshot_t();
dispatch_async(dispatch_get_main_queue(), ^{
update_status(_wc_path, snapshot, status);
update_status(_wc_path, snapshot, status, variables);
});
}
});
}
void info_t::update_status (std::string const& path, fs::snapshot_t const& snapshot, scm::status_map_t const& newStatus)
void info_t::update_status (std::string const& path, fs::snapshot_t const& snapshot, scm::status_map_t const& newStatus, std::map<std::string, std::string> const& newVariables)
{
auto it = cache().find(path);
if(it != cache().end())
@@ -228,6 +233,7 @@ namespace scm
it->second->_updated = oak::date_t::now();
it->second->_snapshot = snapshot;
it->second->_file_status = newStatus;
it->second->_variables = newVariables;
it->second->_callbacks(&callback_t::status_changed, *it->second, changedPaths);
}

View File

@@ -45,6 +45,7 @@ namespace scm
std::string _wc_path;
driver_t const* _driver;
status_map_t _file_status;
std::map<std::string, std::string> _variables;
oak::date_t _updated;
fs::snapshot_t _snapshot;
@@ -53,7 +54,7 @@ namespace scm
void callback (std::set<std::string> const& pathsChangedOnDisk);
oak::callbacks_t<callback_t> _callbacks;
static void update_status (std::string const& path, fs::snapshot_t const& snapshot, scm::status_map_t const& status);
static void update_status (std::string const& path, fs::snapshot_t const& snapshot, scm::status_map_t const& status, std::map<std::string, std::string> const& variables);
};
PUBLIC info_ptr info (std::string const& dir);