# # patch "rcs_import.cc" # from [0b20cfb6281be6eda31c0e861912a2fe57145638] # to [8d37131575081a138c90bacbb26802079ad8be59] # ======================================================================== --- rcs_import.cc 0b20cfb6281be6eda31c0e861912a2fe57145638 +++ rcs_import.cc 8d37131575081a138c90bacbb26802079ad8be59 @@ -285,84 +285,13 @@ } - // piece table stuff +#include "piece_table.hh" -struct piece; - -struct -piece_store -{ - vector< boost::shared_ptr > texts; - void index_deltatext(boost::shared_ptr const & dt, - vector & pieces); - void build_string(vector const & pieces, - string & out); - void reset() { texts.clear(); } -}; - -// FIXME: kludge, I was lazy and did not make this -// a properly scoped variable. - -static piece_store global_pieces; - - -struct -piece -{ - piece(string::size_type p, string::size_type l, unsigned long id) : - pos(p), len(l), string_id(id) {} - string::size_type pos; - string::size_type len; - unsigned long string_id; - string operator*() const - { - return string(global_pieces.texts.at(string_id)->text.data() + pos, len); - } -}; - - -void -piece_store::build_string(vector const & pieces, - string & out) -{ - out.clear(); - out.reserve(pieces.size() * 60); - for(vector::const_iterator i = pieces.begin(); - i != pieces.end(); ++i) - out.append(texts.at(i->string_id)->text, i->pos, i->len); -} - -void -piece_store::index_deltatext(boost::shared_ptr const & dt, - vector & pieces) -{ - pieces.clear(); - pieces.reserve(dt->text.size() / 30); - texts.push_back(dt); - unsigned long id = texts.size() - 1; - string::size_type begin = 0; - string::size_type end = dt->text.find('\n'); - while(end != string::npos) - { - // nb: the piece includes the '\n' - pieces.push_back(piece(begin, (end - begin) + 1, id)); - begin = end + 1; - end = dt->text.find('\n', begin); - } - if (begin != dt->text.size()) - { - // the text didn't end with '\n', so neither does the piece - end = dt->text.size(); - pieces.push_back(piece(begin, end - begin, id)); - } -} - - static void -process_one_hunk(vector< piece > const & source, - vector< piece > & dest, - vector< piece >::const_iterator & i, +process_one_hunk(piece::piece_table const & source, + piece::piece_table & dest, + piece::piece_table::const_iterator & i, int & cursor) { string directive = **i; @@ -409,9 +338,9 @@ } static void -construct_version(vector< piece > const & source_lines, +construct_version(piece::piece_table const & source_lines, string const & dest_version, - vector< piece > & dest_lines, + piece::piece_table & dest_lines, rcs_file const & r) { dest_lines.clear(); @@ -423,11 +352,11 @@ I(r.deltatexts.find(dest_version) != r.deltatexts.end()); shared_ptr deltatext = r.deltatexts.find(dest_version)->second; - vector deltalines; - global_pieces.index_deltatext(deltatext, deltalines); + piece::piece_table deltalines; + piece::index_deltatext(deltatext->text, deltalines); int cursor = 0; - for (vector::const_iterator i = deltalines.begin(); + for (piece::piece_table::const_iterator i = deltalines.begin(); i != deltalines.end(); ) process_one_hunk(source_lines, dest_lines, i, cursor); while (cursor < static_cast(source_lines.size())) @@ -491,7 +420,7 @@ static void insert_into_db(data const & curr_data, hexenc const & curr_id, - vector< piece > const & next_lines, + piece::piece_table const & next_lines, data & next_data, hexenc & next_id, database & db) @@ -502,7 +431,7 @@ // all storage edges go from new -> old. { string tmp; - global_pieces.build_string(next_lines, tmp); + piece::build_string(next_lines, tmp); next_data = tmp; } delta del; @@ -572,7 +501,7 @@ static void process_branch(string const & begin_version, - vector< piece > const & begin_lines, + piece::piece_table const & begin_lines, data const & begin_data, hexenc const & begin_id, rcs_file const & r, @@ -580,8 +509,8 @@ cvs_history & cvs) { string curr_version = begin_version; - scoped_ptr< vector< piece > > next_lines(new vector); - scoped_ptr< vector< piece > > curr_lines(new vector + scoped_ptr< piece::piece_table > next_lines(new piece::piece_table); + scoped_ptr< piece::piece_table > curr_lines(new piece::piece_table (begin_lines.begin(), begin_lines.end())); data curr_data(begin_data), next_data; @@ -639,7 +568,7 @@ string branch; data branch_data; hexenc branch_id; - vector< piece > branch_lines; + piece::piece_table branch_lines; bool priv = false; map::const_iterator be = cvs.branch_first_entries.find(*i); @@ -684,7 +613,7 @@ L(F("parsed RCS file %s OK\n") % filename); { - vector< piece > head_lines; + piece::piece_table head_lines; I(r.deltatexts.find(r.admin.head) != r.deltatexts.end()); I(r.deltas.find(r.admin.head) != r.deltas.end()); @@ -709,10 +638,10 @@ // cvs.find_key_and_state (r, r.admin.head, k, s); } - global_pieces.reset(); - global_pieces.index_deltatext(r.deltatexts.find(r.admin.head)->second, head_lines); + piece::reset(); + piece::index_deltatext(r.deltatexts.find(r.admin.head)->second->text, head_lines); process_branch(r.admin.head, head_lines, dat, id, r, db, cvs); - global_pieces.reset(); + piece::reset(); } ui.set_tick_trailer("");