[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.list_workspaces: 26247c0942
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.list_workspaces: 26247c0942d893d4129e2aeaf52f6a8bd9c6681b |
Date: |
Mon, 10 Jan 2011 00:30:45 GMT |
revision: 26247c0942d893d4129e2aeaf52f6a8bd9c6681b
date: 2011-01-10T00:30:14
author: address@hidden
branch: net.venge.monotone.list_workspaces
changelog:
* lua_hooks.hh|cc, std_hooks.lua: new hook get_default_database_glob,
whose default implementation returns "*.{mtn,db}"
* database.cc, cmd_list.cc: use this hook to determine which files
we look for in list databases and which database aliases we append
an ".mtn" at the end (mtn clone -d :foo.db will no longer auto-create
foo.db.mtn)
* cmd_list.cc: split out the workspace information printing in a separate
function and refactor the code a bit; add a new list workspaces command
which does the same like list databases, except that it works on a single
database (either given by -d or the database from _MTN/options)
* tests/list_databases/__driver__.lua: add a test to ensure "*.db" files
get their workspaces printed as well
manifest:
format_version "1"
new_manifest [0975e1440d190340bc983c3f75192b59da6cbe68]
old_revision [75eb6c8d77f6cb46f66da1bf00af7ad08a7cd138]
patch "cmd_list.cc"
from [b039c7a5f47200b5a0043178d0d3909ce525f892]
to [4699a0a7032e69959f8836195977a67888f30848]
patch "database.cc"
from [c4d5eb755d893255d1be35276e2b12ccbea8372c]
to [9b6b20b6b342f4294e9e9d6cfd42d228db7ad18f]
patch "lua_hooks.cc"
from [a71ded3aabcde9e0ef7281b7c56f2ff1fa6baaec]
to [a4d6c802bf0190bb5e2223219ea29b2830c7f424]
patch "lua_hooks.hh"
from [66b79c7d1dcefed2d3530e71474346b72417fee9]
to [325fd5a4b588ff4d41e3cec69cbf652089a33fa9]
patch "std_hooks.lua"
from [b1a61ba83a6e8c0c9d72393aaf0e86089b75464d]
to [78fd8d92d19d3369b8af5809d4bda43f859e8e5e]
patch "tests/list_databases/__driver__.lua"
from [c63bada5754b3e950bdfb29afdd2cb057c5290b2]
to [d78cd923f7f4950590407127854dcd3467b85625]
============================================================
--- database.cc c4d5eb755d893255d1be35276e2b12ccbea8372c
+++ database.cc 9b6b20b6b342f4294e9e9d6cfd42d228db7ad18f
@@ -5029,8 +5029,11 @@ database_path_helper::validate_and_clean
E(pure_alias.size() > 0, origin::system,
F("invalid database alias '%s': must not be empty") % alias);
- size_t pos = pure_alias.rfind('.');
- if (pos == string::npos || pure_alias.substr(pos + 1) != "mtn")
+ globish matcher;
+ E(lua.hook_get_default_database_glob(matcher),
+ origin::user, F("could not query default database glob"));
+
+ if (!matcher.matches(pure_alias))
pure_alias += ".mtn";
try
============================================================
--- lua_hooks.cc a71ded3aabcde9e0ef7281b7c56f2ff1fa6baaec
+++ lua_hooks.cc a4d6c802bf0190bb5e2223219ea29b2830c7f424
@@ -723,6 +723,20 @@ bool lua_hooks::hook_get_default_databas
return ll.ok();
}
+bool lua_hooks::hook_get_default_database_glob(globish & out)
+{
+ string glob;
+ bool exec_ok
+ = Lua(st)
+ .func("get_default_database_extensions")
+ .call(0, 1)
+ .extract_str(glob)
+ .ok();
+
+ out = globish(glob, origin::user);
+ return exec_ok;
+}
+
bool lua_hooks::hook_hook_wrapper(string const & func_name,
vector<string> const & args,
string & out)
============================================================
--- lua_hooks.hh 66b79c7d1dcefed2d3530e71474346b72417fee9
+++ lua_hooks.hh 325fd5a4b588ff4d41e3cec69cbf652089a33fa9
@@ -136,6 +136,8 @@ public:
bool hook_get_default_database_locations(vector<system_path> & out);
+ bool hook_get_default_database_glob(globish & out);
+
// workspace hooks
bool hook_use_inodeprints();
============================================================
--- std_hooks.lua b1a61ba83a6e8c0c9d72393aaf0e86089b75464d
+++ std_hooks.lua 78fd8d92d19d3369b8af5809d4bda43f859e8e5e
@@ -1120,9 +1120,9 @@ function _get_netsync_read_permitted(bra
end elseif item.name == "continue" then if state["matches"] then
state["cont"] = true
for j, val in pairs(item.values) do
- if val == "false" or val == "no" then
- state["cont"] = false
- end
+ if val == "false" or val == "no" then
+ state["cont"] = false
+ end
end
end elseif item.name ~= "comment" then
io.stderr:write("unknown symbol in read-permissions: " .. item.name .. "\n")
@@ -1143,10 +1143,10 @@ function get_netsync_read_permitted(bran
local files = read_directory(permdirname)
table.sort(files)
for _,f in ipairs(files) do
- pf = permdirname.."/"..f
- if _get_netsync_read_permitted(branch, ident, pf, state) then
- return true
- end
+ pf = permdirname.."/"..f
+ if _get_netsync_read_permitted(branch, ident, pf, state) then
+ return true
+ end
end
end
return false
@@ -1179,8 +1179,8 @@ function get_netsync_write_permitted(ide
local files = read_directory(permdirname)
table.sort(files)
for _,f in ipairs(files) do
- pf = permdirname.."/"..f
- if _get_netsync_write_permitted(ident, pf) then return true end
+ pf = permdirname.."/"..f
+ if _get_netsync_write_permitted(ident, pf) then return true end
end
end
return false
@@ -1304,6 +1304,10 @@ end
return paths
end
+function get_default_database_extensions()
+ return "*.{mtn,db}"
+end
+
hook_wrapper_dump = {}
hook_wrapper_dump.depth = 0
hook_wrapper_dump._string = function(s) return string.format("%q", s) end
============================================================
--- cmd_list.cc b039c7a5f47200b5a0043178d0d3909ce525f892
+++ cmd_list.cc 4699a0a7032e69959f8836195977a67888f30848
@@ -44,6 +44,7 @@ using std::copy;
using std::set;
using std::sort;
using std::copy;
+using std::ostream;
using std::string;
using std::vector;
@@ -614,6 +615,64 @@ CMD(vars, "vars", "", CMD_REF(list), "[D
}
}
+static void
+print_workspace_info(database & db, lua_hooks & lua,
+ ostream & out, string const & indent = string())
+{
+ bool has_valid_workspaces = false;
+
+ vector<system_path> workspaces;
+ db.get_registered_workspaces(workspaces);
+ system_path db_path = db.get_filename();
+
+ database_path_helper helper(lua);
+ for (vector<system_path>::const_iterator k = workspaces.begin();
+ k != workspaces.end(); ++k)
+ {
+ system_path workspace_path(*k);
+ if (!directory_exists(workspace_path / bookkeeping_root_component))
+ {
+ L(FL("ignoring missing workspace '%s'") % workspace_path);
+ continue;
+ }
+
+ options workspace_opts;
+ workspace::get_options(workspace_path, workspace_opts);
+
+ system_path workspace_db_path;
+ helper.get_database_path(workspace_opts, workspace_db_path);
+
+ if (workspace_db_path != db_path)
+ {
+ L(FL("ignoring workspace '%s', expected database %s, "
+ "but has %s configured in _MTN/options")
+ % workspace_path % db_path % workspace_db_path);
+ continue;
+ }
+
+ has_valid_workspaces = true;
+
+ string workspace_branch = workspace_opts.branch();
+ if (!workspace_opts.branch_given)
+ workspace_branch = _("<no branch set>");
+
+ out << indent << F("%s (in %s)") % workspace_branch % workspace_path << '\n';
+ }
+
+ if (!has_valid_workspaces)
+ out << indent << F("no known valid workspaces") << '\n';
+}
+
+CMD(workspaces, "workspaces", "", CMD_REF(list), "",
+ N_("Lists known workspaces of a specified database"),
+ "",
+ options::opts::none)
+{
+ database db(app.opts, app.lua);
+ db.ensure_open();
+ print_workspace_info(db, app.lua, cout);
+}
+
CMD(databases, "databases", "dbs", CMD_REF(list), "",
N_("Lists managed databases and their known workspaces"),
"",
@@ -621,10 +680,12 @@ CMD(databases, "databases", "dbs", CMD_R
{
vector<system_path> search_paths, files, dirs;
- E(app.lua.hook_get_default_database_locations(search_paths), origin::database,
+ E(app.lua.hook_get_default_database_locations(search_paths), origin::user,
F("could not query default database locations"));
- database_path_helper helper(app.lua);
+ globish file_matcher;
+ E(app.lua.hook_get_default_database_glob(file_matcher), origin::user,
+ F("could not query default database glob"));
for (vector<system_path>::const_iterator i = search_paths.begin();
i != search_paths.end(); ++i)
@@ -642,19 +703,22 @@ CMD(databases, "databases", "dbs", CMD_R
// a little optimization, so we don't scan and open every file
string p = db_path.as_internal();
- if (p.size() < 4 || p.substr(p.size() - 4) != ".mtn")
+ if (!file_matcher.matches(p))
{
L(FL("ignoring file '%s'") % db_path);
continue;
}
- options opts;
- opts.dbname_type = unmanaged_db;
- opts.dbname = db_path;
- opts.dbname_given = true;
+ string db_alias = ":" + db_path.as_internal().substr(
+ search_path.as_internal().size() + 1
+ );
- database db(opts, app.lua);
+ options db_opts;
+ db_opts.dbname_type = managed_db;
+ db_opts.dbname_alias = db_alias;
+ db_opts.dbname_given = true;
+ database db(db_opts, app.lua);
try
{
db.ensure_open();
@@ -672,51 +736,8 @@ CMD(databases, "databases", "dbs", CMD_R
continue;
}
- string managed_path = db_path.as_internal().substr(
- search_path.as_internal().size() + 1
- );
- cout << F(":%s (in %s):") % managed_path % search_path << '\n';
-
- bool has_valid_workspaces = false;
-
- vector<system_path> workspaces;
- db.get_registered_workspaces(workspaces);
-
- for (vector<system_path>::const_iterator k = workspaces.begin();
- k != workspaces.end(); ++k)
- {
- system_path workspace_path(*k);
- if (!directory_exists(workspace_path / bookkeeping_root_component))
- {
- L(FL("ignoring missing workspace '%s'") % workspace_path);
- continue;
- }
-
- options workspace_opts;
- workspace::get_options(workspace_path, workspace_opts);
-
- system_path workspace_db_path;
- helper.get_database_path(workspace_opts, workspace_db_path);
-
- if (workspace_db_path != db_path)
- {
- L(FL("ignoring workspace '%s', expected database %s, "
- "but has %s configured in _MTN/options")
- % workspace_path % db_path % workspace_db_path);
- continue;
- }
-
- has_valid_workspaces = true;
-
- string workspace_branch = workspace_opts.branch();
- if (!workspace_opts.branch_given)
- workspace_branch = _("<no branch set>");
-
- cout << F("\t%s (in %s)") % workspace_branch % workspace_path << '\n';
- }
-
- if (!has_valid_workspaces)
- cout << F("\tno known valid workspaces") << '\n';
+ cout << F("%s (in %s):") % db_alias % search_path << "\n";
+ print_workspace_info(db, app.lua, cout, "\t");
}
}
}
============================================================
--- tests/list_databases/__driver__.lua c63bada5754b3e950bdfb29afdd2cb057c5290b2
+++ tests/list_databases/__driver__.lua d78cd923f7f4950590407127854dcd3467b85625
@@ -34,3 +34,6 @@ check(qgrep("\ttest.foo.branch.+in.+list
check(not qgrep("\tno known valid workspaces", "stdout"))
check(qgrep("\ttest.foo.branch.+in.+list_databases\/test_foo", "stdout"))
+check(rename("managed_databases/bar.mtn", "managed_databases/bar.db"))
+check(mt("ls", "dbs"), 0, true, false)
+check(qgrep(":bar.db.+in.+list_databases\/managed_databases", "stdout"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.list_workspaces: 26247c0942d893d4129e2aeaf52f6a8bd9c6681b,
code <=