# # patch "ChangeLog" # from [c58ed9418443cc972728ab7c5757911fb9460028] # to [9d262eb7915ece188de5f0d5a85b00599fcdb4c6] # # patch "paths.cc" # from [65e0f4d000bc1eb76582d0b07213094b5746d564] # to [27678f9f31e4df2114c8741936bcb0a0da18e8be] # # patch "paths.hh" # from [0c935d21c18770ef295b3580e53b9171e124c80a] # to [62c42e07a3d83608626a02cf57f7148c5c66b5a2] # ======================================================================== --- ChangeLog c58ed9418443cc972728ab7c5757911fb9460028 +++ ChangeLog 9d262eb7915ece188de5f0d5a85b00599fcdb4c6 @@ -1,3 +1,7 @@ +2005-09-02 Nathaniel Smith + + * paths.{hh,cc}: Add split_path typedef. Use it. + 2005-09-02 Matt Johnston * lua.cc (monotone_guess_binary_file_contents_for_lua): use a temporary ======================================================================== --- paths.cc 65e0f4d000bc1eb76582d0b07213094b5746d564 +++ paths.cc 27678f9f31e4df2114c8741936bcb0a0da18e8be @@ -231,15 +231,15 @@ // - [] // - ["foo", ""] // - ["", "bar"] -file_path::file_path(std::vector const & pieces) +file_path::file_path(split_path const & sp) { - std::vector::const_iterator i = pieces.begin(); - I(i != pieces.end()); - if (pieces.size() > 1) + split_path::const_iterator i = sp.begin(); + I(i != sp.end()); + if (sp.size() > 1) I(!null_name(*i)); std::string tmp = pc_interner.lookup(*i); I(tmp != bookkeeping_root.as_internal()); - for (++i; i != pieces.end(); ++i) + for (++i; i != sp.end(); ++i) { I(!null_name(*i)); tmp += "/"; @@ -269,9 +269,9 @@ // change_set.cc is rewritten, however, you should revisit the semantics of // this function. void -file_path::split(std::vector & pieces) const +file_path::split(split_path & sp) const { - pieces.clear(); + sp.clear(); if (empty()) return; std::string::size_type start, stop; @@ -282,10 +282,10 @@ stop = s.find('/', start); if (stop < 0 || stop > s.length()) { - pieces.push_back(pc_interner.intern(s.substr(start))); + sp.push_back(pc_interner.intern(s.substr(start))); break; } - pieces.push_back(pc_interner.intern(s.substr(start, stop - start))); + sp.push_back(pc_interner.intern(s.substr(start, stop - start))); start = stop + 1; } } ======================================================================== --- paths.hh 0c935d21c18770ef295b3580e53b9171e124c80a +++ paths.hh 62c42e07a3d83608626a02cf57f7148c5c66b5a2 @@ -96,6 +96,12 @@ // F("my path is %s") % my_path // i.e., nothing fancy necessary, for purposes of F() just treat it like // it were a string +// +// +// There is also one "not really a path" type, 'split_path'. This is a vector +// of path_component's, and semantically equivalent to a file_path -- +// file_path's can be split into split_path's, and split_path's can be joined +// into file_path's. #include @@ -107,6 +113,8 @@ typedef u32 path_component; +typedef std::vector split_path; + const path_component the_null_component = 0; inline bool @@ -145,12 +153,12 @@ public: file_path() {} // join a file_path out of pieces - file_path(std::vector const & pieces); + file_path(split_path const & sp); // this currently doesn't do any normalization or anything. file_path operator /(std::string const & to_append) const; - void split(std::vector & pieces) const; + void split(split_path & sp) const; bool operator ==(const file_path & other) const { return data == other.data; }