# # # add_dir "tests/locked_workspace" # # add_file "tests/locked_workspace/__driver__.lua" # content [f36e7f6e998f988d2402fe7017b9741294e26c55] # # patch "ChangeLog" # from [712f4bb83602e7af1ce14ed4f8c3d86116861832] # to [169386d1f25a7cc0b6dd22ba473aa51f12c63099] # # patch "file_io.cc" # from [2afeb26b0c958d01732bd57a64fd531381cbe892] # to [db9fdc218edf3af90593b19807f91552d6164bba] # # patch "testsuite.lua" # from [a0ba013fbf8fcdf7ba399d671d1c28c1827d00af] # to [da789c985e95a5d7bc996ad6a5c82217cd75bebf] # # patch "work.cc" # from [b18478ed77c1795975b7f8e35c963faa14bacff3] # to [cf8f95a423c6ba25d545fa216b3a13dbbd7cba48] # ============================================================ --- tests/locked_workspace/__driver__.lua f36e7f6e998f988d2402fe7017b9741294e26c55 +++ tests/locked_workspace/__driver__.lua f36e7f6e998f988d2402fe7017b9741294e26c55 @@ -0,0 +1,21 @@ +mtn_setup() + +addfile("base", "base") +commit() +base = base_revision() + +addfile("next", "next") +commit() + +check(mtn("checkout", "--revision", base, "test")) + +mkdir("test/_MTN/detached") +check(indir("test", mtn("update")), 1, false, true) + +writefile("test/_MTN/detached/123") +check(indir("test", mtn("update")), 1, false, true) + +remove("test/_MTN/detached") +check(indir("test", mtn("update")), 0, false, true) + +check(not exists("test/_MTN/detached")) ============================================================ --- ChangeLog 712f4bb83602e7af1ce14ed4f8c3d86116861832 +++ ChangeLog 169386d1f25a7cc0b6dd22ba473aa51f12c63099 @@ -1,3 +1,23 @@ +2007-02-09 Derek Scherger + + * file_io.cc (write_data): indentation tweak + * tests/locked_workspace/__driver__.lua: new test for locked + workspace + * testsuite.lua: call it + * work.cc (path_for_detached_nids): new function to get the path + for detached workspace nodes + (path_for_nid): rename to ... + (path_for_detached_nid): ... this and use new base path function + (editable_working_tree::detach_node): + (editable_working_tree::drop_detached_node): + (editable_working_tree::create_dir_node): + (editable_working_tree::create_file_node): + (editable_working_tree::attach_node): call function by new name + (workspace::perform_content_update): ensure detached node + directory doesn't exist before starting; if it does consider + the workspace locked and abort; ensure it is removed after + completion + 2007-02-09 Markus Schiltknecht * tests/test_a_merge_8/{parent,left,right,correct}: simplified ============================================================ --- file_io.cc 2afeb26b0c958d01732bd57a64fd531381cbe892 +++ file_io.cc db9fdc218edf3af90593b19807f91552d6164bba @@ -435,7 +435,7 @@ write_data(system_path const & path, system_path const & tmpdir) { write_data_impl(path, data, tmpdir / (FL("data.tmp.%d") % - get_process_id()).str()); + get_process_id()).str()); } tree_walker::~tree_walker() {} ============================================================ --- testsuite.lua a0ba013fbf8fcdf7ba399d671d1c28c1827d00af +++ testsuite.lua da789c985e95a5d7bc996ad6a5c82217cd75bebf @@ -705,3 +705,4 @@ table.insert(tests, "revert_the_middle_o table.insert(tests, "db_kill_rev_and_recommit") table.insert(tests, "pluck_does_not_clobber_workspace") table.insert(tests, "revert_the_middle_of_a_sequence") +table.insert(tests, "locked_workspace") ============================================================ --- work.cc b18478ed77c1795975b7f8e35c963faa14bacff3 +++ work.cc cf8f95a423c6ba25d545fa216b3a13dbbd7cba48 @@ -690,11 +690,17 @@ static inline bookkeeping_path // editable_working_tree implementation static inline bookkeeping_path -path_for_nid(node_id nid) +path_for_detached_nids() { - return bookkeeping_root / "tmp" / lexical_cast(nid); + return bookkeeping_root / "detached"; } +static inline bookkeeping_path +path_for_detached_nid(node_id nid) +{ + return path_for_detached_nids() / lexical_cast(nid); +} + // Attaching/detaching the root directory: // This is tricky, because we don't want to simply move it around, like // other directories. That would require some very snazzy handling of the @@ -719,9 +725,8 @@ editable_working_tree::detach_node(split I(root_dir_attached); node_id nid = next_nid++; file_path src_pth(src); - bookkeeping_path dst_pth = path_for_nid(nid); + bookkeeping_path dst_pth = path_for_detached_nid(nid); safe_insert(rename_add_drop_map, make_pair(dst_pth, src_pth)); - make_dir_for(dst_pth); if (src_pth == file_path()) { // root dir detach, so we move contents, rather than the dir itself @@ -743,7 +748,7 @@ editable_working_tree::drop_detached_nod void editable_working_tree::drop_detached_node(node_id nid) { - bookkeeping_path pth = path_for_nid(nid); + bookkeeping_path pth = path_for_detached_nid(nid); map::const_iterator i = rename_add_drop_map.find(pth); I(i != rename_add_drop_map.end()); @@ -756,7 +761,7 @@ editable_working_tree::create_dir_node() editable_working_tree::create_dir_node() { node_id nid = next_nid++; - bookkeeping_path pth = path_for_nid(nid); + bookkeeping_path pth = path_for_detached_nid(nid); require_path_is_nonexistent(pth, F("path %s already exists") % pth); mkdir_p(pth); @@ -767,7 +772,7 @@ editable_working_tree::create_file_node( editable_working_tree::create_file_node(file_id const & content) { node_id nid = next_nid++; - bookkeeping_path pth = path_for_nid(nid); + bookkeeping_path pth = path_for_detached_nid(nid); require_path_is_nonexistent(pth, F("path %s already exists") % pth); file_data dat; @@ -780,7 +785,7 @@ editable_working_tree::attach_node(node_ void editable_working_tree::attach_node(node_id nid, split_path const & dst) { - bookkeeping_path src_pth = path_for_nid(nid); + bookkeeping_path src_pth = path_for_detached_nid(nid); file_path dst_pth(dst); map::const_iterator i @@ -1539,7 +1544,15 @@ workspace::perform_content_update(cset c split_path root; path_set known; roster_t new_roster; + bookkeeping_path detached = path_for_detached_nids(); + E(!directory_exists(detached), + F("workspace is locked\n" + "you must clean up and remove the %s directory") + % detached); + + mkdir_p(detached); + file_path().split(root); node_id nid = roster.create_dir_node(nis); roster.attach_node(nid, root); @@ -1555,6 +1568,8 @@ workspace::perform_content_update(cset c editable_working_tree ewt(lua, ca); update.apply_to(ewt); + + delete_dir_shallow(detached); } void