# # # patch "roster.cc" # from [6c1f08a21617cc9c626e06beffe52c5dbfe48430] # to [fd381ef1c78d29509d150aab9229c86609266abe] # ============================================================ --- roster.cc 6c1f08a21617cc9c626e06beffe52c5dbfe48430 +++ roster.cc fd381ef1c78d29509d150aab9229c86609266abe @@ -319,12 +319,14 @@ dfs_iter { dir_t root; + string curr_path; bool return_root; + bool track_path; stack< pair > stk; - dfs_iter(dir_t r) - : root(r), return_root(root) + dfs_iter(dir_t r, bool t = false) + : root(r), return_root(root), track_path(t) { if (root && !root->children.empty()) stk.push(make_pair(root, root->children.begin())); @@ -337,6 +339,13 @@ dfs_iter } + string const & path() const + { + I(track_path); + return curr_path; + } + + node_t operator*() const { I(!finished()); @@ -349,7 +358,34 @@ dfs_iter } } +private: + void advance_top() + { + int prevsize = 0; + int nextsize = 0; + if (track_path) + { + prevsize = stk.top().second->first().size(); + } + ++stk.top().second; + + if (track_path) + { + if (stk.top().second != stk.top().first->children.end()) + nextsize = stk.top().second->first().size(); + + int tmpsize = curr_path.size()-prevsize; + I(tmpsize >= 0); + curr_path.resize(tmpsize); + if (nextsize != 0) + curr_path.insert(curr_path.end(), + stk.top().second->first().begin(), + stk.top().second->first().end()); + } + } +public: + void operator++() { I(!finished()); @@ -357,6 +393,8 @@ dfs_iter if (return_root) { return_root = false; + if (!stk.empty()) + curr_path = stk.top().second->first(); return; } @@ -367,16 +405,32 @@ dfs_iter { dir_t dtmp = downcast_to_dir_t(ntmp); stk.push(make_pair(dtmp, dtmp->children.begin())); + + if (track_path) + { + if (!curr_path.empty()) + curr_path += "/"; + if (!dtmp->children.empty()) + curr_path += dtmp->children.begin()->first(); + } } else - ++(stk.top().second); + { + advance_top(); + } while (!stk.empty() && stk.top().second == stk.top().first->children.end()) { stk.pop(); if (!stk.empty()) - ++stk.top().second; + { + if (track_path) + { + curr_path.resize(curr_path.size()-1); + } + advance_top(); + } } } }; @@ -2351,11 +2405,12 @@ roster_t::extract_path_set(path_set & pa paths.clear(); if (has_root()) { - for (dfs_iter i(root_dir); !i.finished(); ++i) + for (dfs_iter i(root_dir, true); !i.finished(); ++i) { node_t curr = *i; split_path pth; - get_name(curr->self, pth); + //get_name(curr->self, pth); + internal_string_to_split_path(i.path(), pth); if (!workspace_root(pth)) paths.insert(pth); } @@ -2470,27 +2525,31 @@ roster_t::print_to(basic_io::printer & p st.push_str_pair(basic_io::syms::format_version, "1"); pr.print_stanza(st); } - for (dfs_iter i(root_dir); !i.finished(); ++i) + for (dfs_iter i(root_dir, true); !i.finished(); ++i) { node_t curr = *i; - split_path pth; - get_name(curr->self, pth); + basic_io::stanza st; - file_path fp = file_path(pth); + { + //split_path pth; + //get_name(curr->self, pth); + //file_path fp = file_path(pth); - basic_io::stanza st; - if (is_dir_t(curr)) - { - // L(FL("printing dir %s") % fp); - st.push_file_pair(basic_io::syms::dir, fp); - } - else - { - file_t ftmp = downcast_to_file_t(curr); - st.push_file_pair(basic_io::syms::file, fp); - st.push_hex_pair(basic_io::syms::content, ftmp->content.inner()); - // L(FL("printing file %s") % fp); - } + if (is_dir_t(curr)) + { + // L(FL("printing dir %s") % fp); + //st.push_file_pair(basic_io::syms::dir, fp); + st.push_str_pair(basic_io::syms::dir, i.path()); + } + else + { + file_t ftmp = downcast_to_file_t(curr); + //st.push_file_pair(basic_io::syms::file, fp); + st.push_str_pair(basic_io::syms::file, i.path()); + st.push_hex_pair(basic_io::syms::content, ftmp->content.inner()); + // L(FL("printing file %s") % fp); + } + } if (print_local_parts) {