#
#
# patch "ChangeLog"
# from [fe92b0cd78a55cd515e61b11530928be0f2082e9]
# to [051d4b2f6cb99a62c49b6df397ef4c8ad33f6d2e]
#
# patch "restrictions.cc"
# from [bb5efc2766f768004afd8a505e122b6b912e1898]
# to [8f1f2aaf3d309c1521e5dec3db4e9f7a7cac8b98]
#
# patch "sanity.hh"
# from [c812da629224b2ebf80e0f576f6dee8aeb7afd2c]
# to [354a74c1228db18be58112f48aeedb1594c5f764]
#
============================================================
--- ChangeLog fe92b0cd78a55cd515e61b11530928be0f2082e9
+++ ChangeLog 051d4b2f6cb99a62c49b6df397ef4c8ad33f6d2e
@@ -1,3 +1,14 @@
+2006-07-10 Derek Scherger
+
+ * restrictions.cc (node_restriction::includes,
+ path_restriction::includes): handle --depth with empty restriction
+ (test_include_depth_0_empty_restriction): new test for depth with
+ empty restriction
+ * restrictions.cc (add_restrictions_tests): add it to the testsuite
+ * sanity.hh (dump): new template function for dumping variables
+ when fiddling around or debugging
+ (DUMP): macro wrapper for new dump function
+
2006-07-10 Zack Weinberg
* tests/database_is_closed_on_signal_exit/__driver__.lua: Invert
============================================================
--- restrictions.cc bb5efc2766f768004afd8a505e122b6b912e1898
+++ restrictions.cc 8f1f2aaf3d309c1521e5dec3db4e9f7a7cac8b98
@@ -222,11 +222,27 @@
split_path sp;
roster.get_name(nid, sp);
- // empty restriction includes everything
if (empty())
{
- L(FL("empty include of nid %d path '%s'") % nid % file_path(sp));
- return true;
+ if (app.depth != -1)
+ {
+ int depth = sp.size() - 1; // -1 to not count root path_component
+ if (depth <= app.depth + 1)
+ {
+ L(FL("depth includes nid %d path '%s'") % nid % file_path(sp));
+ return true;
+ }
+ else
+ {
+ L(FL("depth excludes nid %d path '%s'") % nid % file_path(sp));
+ return false;
+ }
+ }
+ else
+ {
+ L(FL("empty include of nid %d path '%s'") % nid % file_path(sp));
+ return true;
+ }
}
node_id current = nid;
@@ -281,11 +297,27 @@
bool
path_restriction::includes(split_path const & sp) const
{
- // empty restriction includes everything
if (empty())
{
- L(FL("empty include of path '%s'") % file_path(sp));
- return true;
+ if (app.depth != -1)
+ {
+ int depth = sp.size() - 1; // -1 to not count root path_component
+ if (depth <= app.depth + 1)
+ {
+ L(FL("depth includes path '%s'") % file_path(sp));
+ return true;
+ }
+ else
+ {
+ L(FL("depth excludes path '%s'") % file_path(sp));
+ return false;
+ }
+ }
+ else
+ {
+ L(FL("empty include of path '%s'") % file_path(sp));
+ return true;
+ }
}
split_path current(sp);
@@ -980,6 +1012,81 @@
}
static void
+test_include_depth_0_empty_restriction()
+{
+ roster_t roster;
+ setup(roster);
+
+ vector includes, excludes;
+
+ app_state app;
+ // FIXME: depth == 0 currently means directory + immediate children
+ // this should be changed to mean just the named directory but for
+ // compatibility with old restrictions this behaviour has been preserved
+ app.set_depth(0);
+
+ // check restricted nodes
+
+ node_restriction nmask(includes, excludes, roster, app);
+
+ BOOST_CHECK( nmask.empty());
+
+ BOOST_CHECK( nmask.includes(roster, nid_root));
+ BOOST_CHECK( nmask.includes(roster, nid_f));
+ BOOST_CHECK( nmask.includes(roster, nid_g));
+
+ BOOST_CHECK( nmask.includes(roster, nid_x));
+ BOOST_CHECK(!nmask.includes(roster, nid_xf));
+ BOOST_CHECK(!nmask.includes(roster, nid_xg));
+ BOOST_CHECK(!nmask.includes(roster, nid_xx));
+ BOOST_CHECK(!nmask.includes(roster, nid_xxf));
+ BOOST_CHECK(!nmask.includes(roster, nid_xxg));
+ BOOST_CHECK(!nmask.includes(roster, nid_xy));
+ BOOST_CHECK(!nmask.includes(roster, nid_xyf));
+ BOOST_CHECK(!nmask.includes(roster, nid_xyg));
+
+ BOOST_CHECK( nmask.includes(roster, nid_y));
+ BOOST_CHECK(!nmask.includes(roster, nid_yf));
+ BOOST_CHECK(!nmask.includes(roster, nid_yg));
+ BOOST_CHECK(!nmask.includes(roster, nid_yx));
+ BOOST_CHECK(!nmask.includes(roster, nid_yxf));
+ BOOST_CHECK(!nmask.includes(roster, nid_yxg));
+ BOOST_CHECK(!nmask.includes(roster, nid_yy));
+ BOOST_CHECK(!nmask.includes(roster, nid_yyf));
+ BOOST_CHECK(!nmask.includes(roster, nid_yyg));
+
+ // check restricted paths
+
+ path_restriction pmask(includes, excludes, app);
+
+ BOOST_CHECK( pmask.empty());
+
+ BOOST_CHECK( pmask.includes(sp_root));
+ BOOST_CHECK( pmask.includes(sp_f));
+ BOOST_CHECK( pmask.includes(sp_g));
+
+ BOOST_CHECK( pmask.includes(sp_x));
+ BOOST_CHECK(!pmask.includes(sp_xf));
+ BOOST_CHECK(!pmask.includes(sp_xg));
+ BOOST_CHECK(!pmask.includes(sp_xx));
+ BOOST_CHECK(!pmask.includes(sp_xxf));
+ BOOST_CHECK(!pmask.includes(sp_xxg));
+ BOOST_CHECK(!pmask.includes(sp_xy));
+ BOOST_CHECK(!pmask.includes(sp_xyf));
+ BOOST_CHECK(!pmask.includes(sp_xyg));
+
+ BOOST_CHECK( pmask.includes(sp_y));
+ BOOST_CHECK(!pmask.includes(sp_yf));
+ BOOST_CHECK(!pmask.includes(sp_yg));
+ BOOST_CHECK(!pmask.includes(sp_yx));
+ BOOST_CHECK(!pmask.includes(sp_yxf));
+ BOOST_CHECK(!pmask.includes(sp_yxg));
+ BOOST_CHECK(!pmask.includes(sp_yy));
+ BOOST_CHECK(!pmask.includes(sp_yyf));
+ BOOST_CHECK(!pmask.includes(sp_yyg));
+}
+
+static void
test_include_depth_1()
{
roster_t roster;
@@ -1068,6 +1175,7 @@
suite->add(BOOST_TEST_CASE(&test_invalid_roster_paths));
suite->add(BOOST_TEST_CASE(&test_invalid_workspace_paths));
suite->add(BOOST_TEST_CASE(&test_include_depth_0));
+ suite->add(BOOST_TEST_CASE(&test_include_depth_0_empty_restriction));
suite->add(BOOST_TEST_CASE(&test_include_depth_1));
}
============================================================
--- sanity.hh c812da629224b2ebf80e0f576f6dee8aeb7afd2c
+++ sanity.hh 354a74c1228db18be58112f48aeedb1594c5f764
@@ -13,6 +13,7 @@
#include "config.h" // Required for ENABLE_NLS
#include
+#include
#include
#include
#include
@@ -484,6 +485,23 @@
template <> void dump(std::string const & obj, std::string & out);
+// debugging utility to dump out vars like MM but without requiring a crash
+
+template void
+dump(T const & t, std::string var,
+ std::string const & file, int const line, std::string const & func)
+{
+ std::string out;
+ dump(t, out);
+ std::cout << (FL("----- begin '%s' (in %s, at %s:%d)")
+ % var % func % file % line) << std::endl
+ << out << std::endl
+ << (FL("----- end '%s' (in %s, at %s:%d)")
+ % var % func % file % line) << std::endl << std::endl;
+};
+
+#define DUMP(foo) dump(foo, #foo, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
+
//////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: C++