# # # patch "cmd_merging.cc" # from [d7e161a93969f9c9073093b4943063c0dcf640a8] # to [876118b62e99fda562cea4fc7b7967fde2900861] # # patch "paths.cc" # from [1d28eaaea93d0c9142de1406ce80f542bf86b0cf] # to [82b1253e5365b49a9b273a9ca8f8450f96720d32] # # patch "paths.hh" # from [2d99b30b4c38f21a427376bd2625e65d7e17577a] # to [3d1de2d3c8fa9008734e67e842e4978459dbbca6] # # patch "revision.cc" # from [c2aac33e95ef0d127b27fff00e93331650e442e1] # to [e94bfc97bcab78f24eca3438a9a28634feae5738] # # patch "roster.cc" # from [9faef96737d3e2e46bd1614e5555b01d6f02a8d9] # to [b0be9f64968bba7a9b4bb492959a052911c25614] # ============================================================ --- cmd_merging.cc d7e161a93969f9c9073093b4943063c0dcf640a8 +++ cmd_merging.cc 876118b62e99fda562cea4fc7b7967fde2900861 @@ -539,9 +539,10 @@ CMD(merge_into_dir, "merge_into_dir", "" { dir_t moved_root = left_roster.root(); file_path pth = file_path_external(idx(args, 2)); - file_path dir = pth.dirname(); - path_component base = pth.basename(); + file_path dir; + path_component base; MM(dir); + pth.dirname_basename(dir, base); N(right_roster.has_node(dir), F("Path %s not found in destination tree.") % pth); ============================================================ --- paths.cc 1d28eaaea93d0c9142de1406ce80f542bf86b0cf +++ paths.cc 82b1253e5365b49a9b273a9ca8f8450f96720d32 @@ -436,6 +436,25 @@ file_path::dirname() const return file_path(s, 0, sep); } +// produce dirname and basename at the same time +void +file_path::dirname_basename(file_path & dir, path_component & base) const +{ + string const & s = data(); + string::size_type sep = s.rfind('/'); + if (sep == string::npos) + { + dir = file_path(); + base = path_component(s, 0); + } + else + { + I(sep < s.size() - 1); // last component must have at least one char + dir = file_path(s, 0, sep); + base = path_component(s, sep + 1); + } +} + // count the number of /-separated components of the path. unsigned int file_path::depth() const ============================================================ --- paths.hh 2d99b30b4c38f21a427376bd2625e65d7e17577a +++ paths.hh 3d1de2d3c8fa9008734e67e842e4978459dbbca6 @@ -188,6 +188,10 @@ public: // returns a path with the last component removed. file_path dirname() const; + + // does dirname() and basename() at the same time, for efficiency + void dirname_basename(file_path &, path_component &) const; + // returns the number of /-separated components of the path. // The empty path has depth zero. unsigned int depth() const; ============================================================ --- revision.cc c2aac33e95ef0d127b27fff00e93331650e442e1 +++ revision.cc e94bfc97bcab78f24eca3438a9a28634feae5738 @@ -1183,8 +1183,10 @@ find_old_path_for(mapchildren.find(p.basename()); + dir_map::const_iterator child = pd->children.find(base); if (child == pd->children.end()) return node_t(); @@ -704,8 +708,9 @@ roster_t::detach_node(file_path const & node_id roster_t::detach_node(file_path const & p) { - file_path dirname = p.dirname(); - path_component basename = p.basename(); + file_path dirname; + path_component basename; + p.dirname_basename(dirname, basename); I(has_root()); if (basename.empty()) @@ -818,7 +823,12 @@ roster_t::attach_node(node_id nid, file_ // attaching the root node attach_node(nid, the_null_node, path_component()); else - attach_node(nid, get_node(p.dirname())->self, p.basename()); + { + file_path dir; + path_component base; + p.dirname_basename(dir, base); + attach_node(nid, get_node(dir)->self, base); + } } void