#
#
# rename "tests/include()_and_includedir()_lua_functions"
# to "tests/include()_includedir()_and_includedirpattern()_lua_functions"
#
# patch "ChangeLog"
# from [819fb41dff43895081434441292fcb1e47df6fea]
# to [7d1211b293f94886ad3e3a3c732980ad4cc94807]
#
# patch "lua.cc"
# from [1b0fd38dcda942611fa69662e2eeb845dd4ec809]
# to [c7733c6c4d1d3c216e2bd55c64a5bce10e0a23d5]
#
# patch "monotone.texi"
# from [7212dc67eee89e3f633aaf15f44ef3e265010a92]
# to [eaccab90e2221d495d0a3356d1f8048499bff211]
#
# patch "tests/include()_includedir()_and_includedirpattern()_lua_functions/__driver__.lua"
# from [77e616c0df779522047c18bdc011204ac9844331]
# to [9d0df9b28dc88e4ede507dabe7864595afd8b7d1]
#
# patch "testsuite.lua"
# from [ee3dadaa84390b8be6919ce41c9c5e6c4e3b4881]
# to [4b40bda9247378af242f0a58be0e6489ee51126d]
#
============================================================
--- ChangeLog 819fb41dff43895081434441292fcb1e47df6fea
+++ ChangeLog 7d1211b293f94886ad3e3a3c732980ad4cc94807
@@ -1,5 +1,16 @@ 2006-11-15 Richard Levitte
+ * lua.cc (LUAEXT): Implement includedirpattern(), which is like
+ includedir() but also takes a glob pattern for the files to load.
+ * monotone.texi (Additional Lua Functions): Document
+ includedirpattern().
+ * testsuite.lua,
+ tests/include()_and_includedir()_lua_functions/:
+ Renamed to include()_includedir()_and_includedirpattern()_lua_functions
+ __driver__.lua: Test includedirpattern().
+
+2006-11-15 Richard Levitte
+
* debian/monotone-server.postinst: Add a note that a db migration
may take a while.
============================================================
--- lua.cc 1b0fd38dcda942611fa69662e2eeb845dd4ec809
+++ lua.cc c7733c6c4d1d3c216e2bd55c64a5bce10e0a23d5
@@ -1,8 +1,9 @@
#include "config.h"
#include "lua.hh"
+#include "globish.hh"
#include "sanity.hh"
#include
@@ -503,6 +504,44 @@ LUAEXT(includedir, )
return 1;
}
+LUAEXT(includedirpattern, )
+{
+ const char *pathstr = luaL_checkstring(L, -2);
+ const char *pattern = luaL_checkstring(L, -1);
+ N(pathstr && pattern,
+ F("%s called with an invalid parameter") % "IncludeDirPattern");
+
+ fs::path locpath(pathstr, fs::native);
+ N(fs::exists(locpath), F("Directory '%s' does not exist") % pathstr);
+ N(fs::is_directory(locpath), F("'%s' is not a directory") % pathstr);
+
+ // directory, iterate over it, skipping subdirs, taking every filename
+ // matching the pattern, sorting them and loading in sorted order
+ fs::directory_iterator it(locpath);
+ string r(pattern);
+ string n;
+ globish_matcher glob(r, n);
+ vector arr;
+ while (it != fs::directory_iterator())
+ {
+ if (!fs::is_directory(*it) && glob(it->string()))
+ arr.push_back(*it);
+ ++it;
+ }
+ sort(arr.begin(), arr.end());
+ for (vector::iterator i= arr.begin(); i != arr.end(); ++i)
+ {
+ bool res =Lua(L)
+ .loadfile(i->string())
+ .call(0,1)
+ .ok();
+ N(res, F("lua error while loading rcfile '%s'") % i->string());
+ }
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
LUAEXT(search, regex)
{
const char *re = luaL_checkstring(L, -2);
============================================================
--- monotone.texi 7212dc67eee89e3f633aaf15f44ef3e265010a92
+++ monotone.texi eaccab90e2221d495d0a3356d1f8048499bff211
@@ -8191,6 +8191,13 @@ @section Additional Lua Functions
If one of the scripts has an error, the functions doesn't process the
remaining scripts and immediately returns false.
address@hidden includedirpattern(@var{scriptpath}, @var{pattern})
+
+This function loads and executes in alphabetical order all the scripts
+contained into the directory scriptpath that match the given pattern.
+If one of the scripts has an error, the functions doesn't process the
+remaining scripts and immediately returns false.
+
@item is_executable(@var{filespec})
This function returns true if the file is executable, false
============================================================
--- tests/include()_includedir()_and_includedirpattern()_lua_functions/__driver__.lua 77e616c0df779522047c18bdc011204ac9844331
+++ tests/include()_includedir()_and_includedirpattern()_lua_functions/__driver__.lua 9d0df9b28dc88e4ede507dabe7864595afd8b7d1
@@ -7,6 +7,8 @@ writefile("includedir.lua", 'includedir(
writefile("includedir.lua", 'includedir("../gongolo")')
+writefile("includedirpattern.lua", 'includedirpattern("../gongolo","*.rc")')
+
-- write two files and check that they will be invoked in alphabetic order
check(get("aaa.rc", "gongolo/aaa.rc"))
check(get("bbb.zz", "gongolo/bbb.zz"))
@@ -18,11 +20,18 @@ check(qgrep("BOOGA BOOGA", "stdout"))
check(indir("alt_wrk", mtn("--root=.", "--rcfile=../include.lua", "status")), 0, true, false)
check(qgrep("BOOGA BOOGA", "stdout"))
--- include dirs
+-- include dir
check(indir("alt_wrk", mtn("--root=.", "--rcfile=../includedir.lua", "status")), 0, true, false)
check(qgrep("BOOGA BOOGACICCA CICCA", "stdout"))
+-- include dir with patterns
+check(indir("alt_wrk", mtn("--root=.", "--rcfile=../includedirpattern.lua", "status")), 0, true, false)
+check(qgrep("BOOGA BOOGA", "stdout"))
+
-- write a third file: should be read between the two previous ones
check(get("aba.rc", "gongolo/aba.rc"))
check(indir("alt_wrk", mtn("--root=.", "--rcfile=../includedir.lua", "status")), 0, true, false)
check(qgrep("BOOGA BOOGAhu huCICCA CICCA", "stdout"))
+
+check(indir("alt_wrk", mtn("--root=.", "--rcfile=../includedirpattern.lua", "status")), 0, true, false)
+check(qgrep("BOOGA BOOGAhu hu", "stdout"))
============================================================
--- testsuite.lua ee3dadaa84390b8be6919ce41c9c5e6c4e3b4881
+++ testsuite.lua 4b40bda9247378af242f0a58be0e6489ee51126d
@@ -552,7 +552,7 @@ table.insert(tests, "_--rcfile=directory
table.insert(tests, "status")
table.insert(tests, "a_tricky_cvs_repository_with_tags")
table.insert(tests, "_--rcfile=directory")
-table.insert(tests, "include()_and_includedir()_lua_functions")
+table.insert(tests, "include()_includedir()_and_includedirpattern()_lua_functions")
table.insert(tests, "lua_function_existsonpath")
table.insert(tests, "db_kill_branch_certs_locally_command")
table.insert(tests, "netsync_with_globs")