# # patch "ChangeLog" # from [395776a7bab856a184a690a042895ea90144f8a5] # to [552a799c84e8a2f7f20f9a76610f732a93e73f55] # # patch "rcs_import.cc" # from [9e5dd5fa2b935387d0504e2dcbc97a6ac6b0a415] # to [3e5ca94d659400cda4b3858261ed966cec3d9687] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,8 @@ +2005-05-11 Matt Johnston + + * rcs_import.cc (find_branchpoint): if a branch is derived from two + differing parent branches, take the one closest to the trunk. + 2005-05-09 Matt Johnston * commands.cc (pid_file): use fs::path .empty() rather than ==, since --- rcs_import.cc +++ rcs_import.cc @@ -189,6 +189,19 @@ map< cvs_key, shared_ptr > substates; }; +struct +branch_point +{ + branch_point() {} + branch_point(cvs_key const & k, + shared_ptr const & s, + size_t l) + : key(k), state(s), rev_comp_len(l) {} + cvs_key key; + shared_ptr state; + size_t rev_comp_len; +}; + struct cvs_history { @@ -209,9 +222,7 @@ typedef stack< shared_ptr > state_stack; - map > > branchpoints; + map branchpoints; state_stack stk; file_path curr_file; @@ -235,7 +246,7 @@ void find_branchpoint(rcs_file const & r, string const & branchpoint_version, string const & first_branch_version, - shared_ptr & branchpoint); + shared_ptr & bp_state); void pop_branch(); }; @@ -662,21 +673,29 @@ { } +static void +version_to_components(string const & version, + vector & components) +{ + typedef boost::tokenizer > tokenizer; + boost::char_separator sep("."); + tokenizer tokens(version, sep); + components.clear(); + copy(tokens.begin(), tokens.end(), back_inserter(components)); +} + static string find_branch_for_version(multimap const & symbols, string const & version, string const & base) { typedef multimap::const_iterator ity; - typedef boost::tokenizer > tokenizer; L(F("looking up branch name for %s\n") % version); - boost::char_separator sep("."); - tokenizer tokens(version, sep); vector components; - copy(tokens.begin(), tokens.end(), back_inserter(components)); + version_to_components(version, components); if (components.size() < 4) { @@ -844,10 +863,10 @@ cvs_history::find_branchpoint(rcs_file const & r, string const & branchpoint_version, string const & first_branch_version, - shared_ptr & branchpoint) + shared_ptr & bp_state) { cvs_key k; - I(find_key_and_state(r, branchpoint_version, k, branchpoint)); + I(find_key_and_state(r, branchpoint_version, k, bp_state)); string branch_name = find_branch_for_version(r.admin.symbols, first_branch_version, @@ -855,33 +874,44 @@ unsigned long branch = branch_interner.intern(branch_name); - map > >::const_iterator i + map::const_iterator i = branchpoints.find(branch); + vector new_components; + version_to_components(branchpoint_version, new_components); + size_t newlen = new_components.size(); + + if (i == branchpoints.end()) { ++n_tree_branches; L(F("beginning branch %s at %s : %s\n") % branch_name % curr_file % branchpoint_version); branchpoints.insert(make_pair(branch, - make_pair(k, branchpoint))); + branch_point(k, bp_state, newlen))); } else { + // if this version comes off the main trunk, but the previous branchpoint + // version comes off a branch (such as an import 1.1.1.1), then we want + // to take the one closest to the trunk. + // TODO perhaps we need to reconsider branching in general for cvs_import, + // this is pretty much just a workaround for 1.1<->1.1.1.1 equivalence + // take the earlier of the new key and the existing branchpoint - if (k.time < i->second.first.time) + if ((k.time < i->second.key.time && newlen <= i->second.rev_comp_len) + || newlen < i->second.rev_comp_len) { L(F("moving branch %s back to %s : %s\n") % branch_name % curr_file % branchpoint_version); - shared_ptr old = i->second.second; + shared_ptr old = i->second.state; set moved; for (map< cvs_key, shared_ptr >::const_iterator j = old->substates.begin(); j != old->substates.end(); ++j) { if (j->first.branch == branch) { - branchpoint->substates.insert(*j); + bp_state->substates.insert(*j); moved.insert(j->first); } } @@ -890,13 +920,13 @@ { old->substates.erase(*j); } - branchpoints[branch] = make_pair(k, branchpoint); + branchpoints[branch] = branch_point(k, bp_state, newlen); } else { L(F("using existing branchpoint for %s at %s : %s\n") % branch_name % curr_file % branchpoint_version); - branchpoint = i->second.second; + bp_state = i->second.state; } } } @@ -906,11 +936,11 @@ string const & branchpoint_version, string const & first_branch_version) { - shared_ptr branchpoint; + shared_ptr bp_state; I(stk.size() > 0); find_branchpoint(r, branchpoint_version, - first_branch_version, branchpoint); - stk.push(branchpoint); + first_branch_version, bp_state); + stk.push(bp_state); } void