mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 04:38:13 -05:00
Improve encapsulation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <text/case.h>
|
||||
#include <text/format.h>
|
||||
#include <text/tokenize.h>
|
||||
#include <io/path.h>
|
||||
#include <oak/oak.h>
|
||||
|
||||
static std::string find_executable (std::string const& name, std::string const& variable)
|
||||
@@ -45,6 +46,24 @@ namespace scm
|
||||
{
|
||||
}
|
||||
|
||||
bool driver_t::has_info_for_directory (std::string const& path)
|
||||
{
|
||||
bool res = path::exists(text::format(_wc_root_format_string.c_str(), path.c_str()));
|
||||
if(res)
|
||||
setup();
|
||||
return res;
|
||||
}
|
||||
|
||||
void driver_t::setup ()
|
||||
{
|
||||
if(_resolved_executable == NULL_STR && _required_executable != NULL_STR)
|
||||
{
|
||||
_resolved_executable = find_executable(_required_executable, "TM_" + text::uppercase(_name));
|
||||
if(_resolved_executable == NULL_STR)
|
||||
fprintf(stderr, "scm: unable to find ‘%s’ executable (set %s or PATH in ~/.tm_properties)\n", _required_executable.c_str(), ("TM_" + text::uppercase(_name)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
driver_t* git_driver ();
|
||||
driver_t* hg_driver ();
|
||||
driver_t* p4_driver ();
|
||||
@@ -60,16 +79,10 @@ namespace scm
|
||||
{
|
||||
iterate(driver, drivers)
|
||||
{
|
||||
if(*driver && path::exists(text::format((*driver)->_wc_root_format_string.c_str(), cwd.c_str())))
|
||||
if(*driver && (*driver)->has_info_for_directory(cwd))
|
||||
{
|
||||
if(wcPath)
|
||||
*wcPath = cwd;
|
||||
if((*driver)->_resolved_executable == NULL_STR && (*driver)->_required_executable != NULL_STR)
|
||||
{
|
||||
(*driver)->_resolved_executable = find_executable((*driver)->_required_executable, "TM_" + text::uppercase((*driver)->_name));
|
||||
if((*driver)->_resolved_executable == NULL_STR)
|
||||
fprintf(stderr, "scm: unable to find ‘%s’ executable (set %s or PATH in ~/.tm_properties)\n", (*driver)->_required_executable.c_str(), ("TM_" + text::uppercase((*driver)->_name)).c_str());
|
||||
}
|
||||
return *driver;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@ namespace scm
|
||||
virtual bool tracks_directories () const { return false; }
|
||||
virtual bool may_touch_filesystem () const { return false; }
|
||||
|
||||
bool has_info_for_directory (std::string const& path);
|
||||
|
||||
protected:
|
||||
std::string const& executable () const { return _resolved_executable; }
|
||||
void setup ();
|
||||
|
||||
private:
|
||||
friend driver_t const* driver_for_path (std::string const& path, std::string* wcPath);
|
||||
|
||||
std::string _name;
|
||||
std::string _wc_root_format_string;
|
||||
std::string _required_executable;
|
||||
|
||||
Reference in New Issue
Block a user