# # # patch "database.cc" # from [dd9e4ede72cfad9baaa9a66b9a8452502eb703cb] # to [a4a8ac204d750aa31eb5a45196ed6ba770e626f9] # # patch "database.hh" # from [7dfab82fad19276b981ad2abdad2c839335672a6] # to [8a1debf42e1ccc4263c755cb2c12b6a683dd563c] # # patch "work.cc" # from [75fec4fd6692c35eeefeae5b96738b7ad767bfd0] # to [939366f93f579840c44ed3979057f7a00bd92b07] # ============================================================ --- database.cc dd9e4ede72cfad9baaa9a66b9a8452502eb703cb +++ database.cc a4a8ac204d750aa31eb5a45196ed6ba770e626f9 @@ -49,6 +49,7 @@ #include "safe_map.hh" #include "sanity.hh" #include "migration.hh" +#include "simplestring_xform.hh" #include "transforms.hh" #include "ui.hh" // tickers #include "vocab.hh" @@ -4390,6 +4391,62 @@ database::clear_var(var_key const & key) % blob(key.second())); } +void +database::register_workspace(system_path const & path) +{ + var_domain domain("database", origin::internal); + var_name name("known-workspaces", origin::internal); + var_key key(make_pair(domain, name)); + + var_value val; + if (var_exists(key)) + get_var(key, val); + + vector workspaces; + split_into_lines(val(), workspaces); + + vector::iterator pos = + find(workspaces.begin(), + workspaces.end(), + path.as_internal()); + if (pos == workspaces.end()) + workspaces.push_back(path.as_internal()); + + string ws; + join_lines(workspaces, ws); + + set_var(key, var_value(ws, origin::internal)); +} + +void +database::unregister_workspace(system_path const & path) +{ + var_domain domain("database", origin::internal); + var_name name("known-workspaces", origin::internal); + var_key key(make_pair(domain, name)); + + if (var_exists(key)) + { + var_value val; + get_var(key, val); + + vector workspaces; + split_into_lines(val(), workspaces); + + vector::iterator pos = + find(workspaces.begin(), + workspaces.end(), + path.as_internal()); + if (pos != workspaces.end()) + workspaces.erase(pos); + + string ws; + join_lines(workspaces, ws); + + set_var(key, var_value(ws, origin::internal)); + } +} + // branches outdated_indicator ============================================================ --- database.hh 7dfab82fad19276b981ad2abdad2c839335672a6 +++ database.hh 8a1debf42e1ccc4263c755cb2c12b6a683dd563c @@ -375,6 +375,10 @@ public: void clear_var(var_key const & key); + void register_workspace(system_path const & path); + + void unregister_workspace(system_path const & path); + // // --== Completion ==-- // ============================================================ --- work.cc 75fec4fd6692c35eeefeae5b96738b7ad767bfd0 +++ work.cc 939366f93f579840c44ed3979057f7a00bd92b07 @@ -25,7 +25,6 @@ #include "restrictions.hh" #include "sanity.hh" #include "safe_map.hh" -#include "simplestring_xform.hh" #include "revision.hh" #include "inodeprint.hh" #include "merge_content.hh" @@ -638,55 +637,15 @@ workspace::set_options(options const & o { // remove the currently registered workspace from the old // database and add it to the new one - var_domain domain("database", origin::internal); - var_name name("known-workspaces", origin::internal); - var_key key(make_pair(domain, name)); - system_path current_workspace; get_current_workspace(current_workspace); database old_db(cur_opts, lua); - if (old_db.var_exists(key)) - { - var_value val; - old_db.get_var(key, val); + old_db.unregister_workspace(current_workspace); - vector workspaces; - split_into_lines(val(), workspaces); - - vector::iterator pos = - find(workspaces.begin(), - workspaces.end(), - current_workspace.as_internal()); - if (pos != workspaces.end()) - workspaces.erase(pos); - - string ws; - join_lines(workspaces, ws); - - old_db.set_var(key, var_value(ws, origin::internal)); - } - database new_db(opts, lua); - var_value val; - if (new_db.var_exists(key)) - new_db.get_var(key, val); + new_db.register_workspace(current_workspace); - vector workspaces; - split_into_lines(val(), workspaces); - - vector::iterator pos = - find(workspaces.begin(), - workspaces.end(), - current_workspace.as_internal()); - if (pos == workspaces.end()) - workspaces.push_back(current_workspace.as_internal()); - - string ws; - join_lines(workspaces, ws); - - new_db.set_var(key, var_value(ws, origin::internal)); - cur_opts.dbname_type = opts.dbname_type; cur_opts.dbname_alias = opts.dbname_alias; cur_opts.dbname = dbpath;