# # # add_dir "tests/revert_attrs" # # add_file "tests/revert_attrs/__driver__.lua" # content [ba6ed36f84bd482570b8e5ca8b03041663f83e1a] # # patch "cmd_ws_commit.cc" # from [edbf7e543d9a4dc31a3f4815acd1a9c2a83ee651] # to [0ab8f9138081d781fe1e341c7e7e9ff61c3ce0a6] # # patch "tests/clobbered_attrs/__driver__.lua" # from [13108b8034266888fb78ad445ee78847efcdf635] # to [a409435e97aeea77ee9adaddf567e15101d44493] # ============================================================ --- tests/revert_attrs/__driver__.lua ba6ed36f84bd482570b8e5ca8b03041663f83e1a +++ tests/revert_attrs/__driver__.lua ba6ed36f84bd482570b8e5ca8b03041663f83e1a @@ -0,0 +1,45 @@ +skip_if(ostype=="Windows") +skip_if(not existsonpath("chmod")) + +mtn_setup() + +writefile("foo", "some data") +writefile("bar", "other data") + +check(mtn("add", "foo", "bar"), 0, false, false) +check(mtn("attr", "set", "foo", "mtn:execute", "true"), 0, false, false) + +check({"test", "-x","foo"}, 0, false, false) +check({"test", "!", "-x","bar"}, 0, false, false) + +commit() + +-- now flip the attributes so that for has a dormant mtn:execute + +check(mtn("attr", "drop", "foo", "mtn:execute"), 0, false, false) +check(mtn("attr", "set", "bar", "mtn:execute", "true"), 0, false, false) + +check({"test", "!", "-x","foo"}, 0, false, false) +check({"test", "-x","bar"}, 0, false, false) + +commit() + +-- set execute on foo and clear on bar + +check({"chmod", "+x", "foo"}, 0, false, false) +check({"chmod", "-x", "bar"}, 0, false, false) + +check({"test", "-x","foo"}, 0, false, false) +check({"test", "!", "-x","bar"}, 0, false, false) + +-- revert foo clears the execute bits + +check(mtn("revert", "foo"), 0, false, false) +check({"test", "!", "-x","foo"}, 0, false, false) +check({"test", "!", "-x","bar"}, 0, false, false) + +-- revert bar sets the execute bits + +check(mtn("revert", "bar"), 0, false, false) +check({"test", "!", "-x","foo"}, 0, false, false) +check({"test", "-x","bar"}, 0, false, false) ============================================================ --- cmd_ws_commit.cc edbf7e543d9a4dc31a3f4815acd1a9c2a83ee651 +++ cmd_ws_commit.cc 0ab8f9138081d781fe1e341c7e7e9ff61c3ce0a6 @@ -286,30 +286,37 @@ CMD(revert, "revert", "", CMD_REF(worksp if (is_file_t(node)) { file_t f = downcast_to_file_t(node); + + bool changed = true; + if (file_exists(new_path)) { file_id ident; calculate_ident(new_path, ident); // don't touch unchanged files if (ident == f->content) - continue; - else - L(FL("skipping unchanged %s") % new_path); + { + L(FL("skipping unchanged %s") % new_path); + changed = false;; + } } - P(F("reverting %s") % new_path); - L(FL("reverting %s to [%s]") % new_path - % f->content); + if (changed) + { + P(F("reverting %s") % new_path); + L(FL("reverting %s to [%s]") % new_path + % f->content); - E(db.file_version_exists(f->content), origin::user, - F("no file version %s found in database for %s") - % f->content % new_path); + E(db.file_version_exists(f->content), origin::user, + F("no file version %s found in database for %s") + % f->content % new_path); - file_data dat; - L(FL("writing file %s to %s") - % f->content % new_path); - db.get_file_version(f->content, dat); - write_data(new_path, dat.inner()); + file_data dat; + L(FL("writing file %s to %s") + % f->content % new_path); + db.get_file_version(f->content, dat); + write_data(new_path, dat.inner()); + } } else { @@ -325,6 +332,22 @@ CMD(revert, "revert", "", CMD_REF(worksp L(FL("skipping existing %s/") % new_path); } } + + // revert attributes on this node -- this doesn't quite catch all cases: + // if the execute bits are manually set on some path that doesn't have + // a dormant mtn:execute the execute bits will not be cleared + // FIXME: check execute bits against mtn:execute explicitly? + + for (attr_map_t::const_iterator a = node->attrs.begin(); + a != node->attrs.end(); ++a) + { + P(F("reverting %s on %s") % a->first() % new_path); + if (a->second.first) + app.lua.hook_set_attribute(a->first(), new_path, + a->second.second()); + else + app.lua.hook_clear_attribute(a->first(), new_path); + } } // Included_work is thrown away which effectively reverts any adds, @@ -337,7 +360,6 @@ CMD(revert, "revert", "", CMD_REF(worksp // Race. work.put_work_rev(remaining); - work.update_any_attrs(db); work.maybe_update_inodeprints(db); } ============================================================ --- tests/clobbered_attrs/__driver__.lua 13108b8034266888fb78ad445ee78847efcdf635 +++ tests/clobbered_attrs/__driver__.lua a409435e97aeea77ee9adaddf567e15101d44493 @@ -39,4 +39,4 @@ check({"test", "!", "-x","foo"}, 0, fals -- this should not touch bar check(mtn("revert", "foo"), 0, false, false) check({"test", "!", "-x","foo"}, 0, false, false) -xfail({"test", "!", "-x","bar"}, 0, false, false) +check({"test", "!", "-x","bar"}, 0, false, false)