# # add_file "contrib/monotone-cvs-ignore.lua" # # patch "ChangeLog" # from [be429de2dd6c1f86b821c69cca1f0e77ab51bfd9] # to [98ab791434cf841224d9900a8775cee9d8af33aa] # # patch "contrib/monotone-cvs-ignore.lua" # from [] # to [9d8fe793ab5c6f3a5c21f534ceedea2796ee58eb] # # patch "lua.cc" # from [fcdcae0e83a277631f00f445a292b970ce6e76c5] # to [77945b8871b4a592a44df77fc436773db7e72f38] # # patch "std_hooks.lua" # from [89589561d3ab649c6505af849467566154b2769e] # to [6374fb70133efbd8c51a1ba6a65e3de67d28ae42] # # patch "tests/t_mt_ignore.at" # from [c2de21ee55150088d8767e659abfd41055bcb6f9] # to [363081d16393e1244dd4d4347c1c63f19ba54e36] # ======================================================================== --- ChangeLog be429de2dd6c1f86b821c69cca1f0e77ab51bfd9 +++ ChangeLog 98ab791434cf841224d9900a8775cee9d8af33aa @@ -1,5 +1,14 @@ 2005-09-01 Timothy Brownawell + * lua.cc, std_hooks.lua: use proper regexes for .mt-ignore + taken from a patch from Martin Dvorak + * contrib/monotone-cvs-ignore.lua: New file, from the same patch. + supports .cvsignore files + * tests/t_mt_ignore.at: check that a missing .mt-ignore + doesn't cause problems + +2005-09-01 Timothy Brownawell + * tests/t_mt_ignore.at: use RAW_MONOTONE instead of ugly --rcfile Also actually do "mtn add" this time. ======================================================================== --- contrib/monotone-cvs-ignore.lua +++ contrib/monotone-cvs-ignore.lua 9d8fe793ab5c6f3a5c21f534ceedea2796ee58eb @@ -0,0 +1,27 @@ +function glob_to_pattern(glob) + local pattern + + -- escape all special characters: + pattern = string.gsub(glob, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") + + -- convert the glob's ones to pattern's: + pattern = string.gsub(pattern, "%%%*", "[^/]*") + pattern = string.gsub(pattern, "%%%?", ".") + + return pattern +end + +function ignore_file(name) + local dir, pat1, pat2 + + dir = string.gsub(name, "/[^/]+$", "/") + if (dir == name) then dir = "" end + pat1 = "^" .. glob_to_pattern(dir) + + for line in io.lines(dir .. ".cvsignore") do + pat2 = glob_to_pattern(line) .. "$" + if (string.find(name, pat1 .. pat2)) then return true end + end + + return false +end ======================================================================== --- lua.cc fcdcae0e83a277631f00f445a292b970ce6e76c5 +++ lua.cc 77945b8871b4a592a44df77fc436773db7e72f38 @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -596,6 +597,17 @@ lua_pushboolean(L, true); return 1; } + + static int + monotone_regex_search_for_lua(lua_State *L) + { + const char *re = lua_tostring(L, -2); + const char *str = lua_tostring(L, -1); + boost::cmatch what; + + lua_pushboolean(L, boost::regex_search(str, what, boost::regex(re))); + return 1; + } } @@ -625,6 +637,18 @@ lua_register(st, "guess_binary_file_contents", monotone_guess_binary_file_contents_for_lua); lua_register(st, "include", monotone_include_for_lua); lua_register(st, "includedir", monotone_includedir_for_lua); + + // add regex functions: + lua_newtable(st); + lua_pushstring(st, "regex"); + lua_pushvalue(st, -2); + lua_settable(st, LUA_GLOBALSINDEX); + + lua_pushstring(st, "search"); + lua_pushcfunction(st, monotone_regex_search_for_lua); + lua_settable(st, -3); + + lua_pop(st, 1); } lua_hooks::~lua_hooks() ======================================================================== --- std_hooks.lua 89589561d3ab649c6505af849467566154b2769e +++ std_hooks.lua 6374fb70133efbd8c51a1ba6a65e3de67d28ae42 @@ -73,16 +73,23 @@ function ignore_file(name) -- project specific - local ignfile = io.open(".mt-ignore", "r") - if (ignfile ~= nil) then - local line = ignfile:read() - while (line ~= nil) - do - if (string.find(name, line)) then return true end - line = ignfile:read() + if (ignored_files == nil) then + ignored_files = {} + local ignfile = io.open(".mt-ignore", "r") + if (ignfile ~= nil) then + local line = ignfile:read() + while (line ~= nil) + do + table.insert(ignored_files, line) + line = ignfile:read() + end + io.close(ignfile) end - io.close(ignfile) end + for i, line in pairs(ignored_files) + do + if (regex.search(line, name)) then return true end + end -- c/c++ if (string.find(name, "%.a$")) then return true end if (string.find(name, "%.so$")) then return true end ======================================================================== --- tests/t_mt_ignore.at c2de21ee55150088d8767e659abfd41055bcb6f9 +++ tests/t_mt_ignore.at 363081d16393e1244dd4d4347c1c63f19ba54e36 @@ -26,4 +26,7 @@ AT_CHECK(grep bar ignored, [], [ignore]) AT_CHECK(grep xyzzy ignored, [], [ignore]) +AT_CHECK(rm .mt-ignore) +AT_CHECK(RAW_MONOTONE ls ignored, [], [], []) + AT_CLEANUP