# # patch "ChangeLog" # from [e3991b964f3eba0e8e10c001bc9c4dbec0dd9fb9] # to [6bab66b8552bb212be3d0ef97a96b403a46782bc] # # patch "basic_io.cc" # from [ba25d4a49aa0e24421049e530556797881134051] # to [08fb82e004b12795e66bf122762729c1bb5e5209] # # patch "basic_io.hh" # from [baf5570f0a8bf91af447396c49cee0acda484c5b] # to [b61d8da0f80ba7017e11e68e91809c95f4415b43] # # patch "cycle_detector.hh" # from [0d1f8c8dd180411fbe28add794898a8baed682f9] # to [624eaa84d3bc3281a0d6280cbecb1e654f0bc723] # # patch "database.cc" # from [8bd9d2d49322d496a8cd4ed3e3a8f802eb0d9ed2] # to [591ac0be0c3855db8b3817c9f1b049a070c3ea55] # # patch "diff_patch.hh" # from [1613098d280746b4c77d70600a0576281e3cae86] # to [8045a7d688a9494585eab247815ef9573687039f] # # patch "interner.hh" # from [54202e534648dd7b0e6b622f6cc413253810f64c] # to [57c97faa357c9664fa8c3e457f12a97db9852ed7] # # patch "lcs.cc" # from [21272ff8f2b22d276c671a34eb2d0ecdd94f96ca] # to [fd29f8174a6718842724caece25b5ea753da1a04] # # patch "mkstemp.cc" # from [b49b3d62bed1cf26fe36bfcb36c842d70b755081] # to [2c848957aac13cb3bfb414d89a71a1d3269b6538] # # patch "netio.hh" # from [2d374c1a00dc50c0be103d04449cc204534c8636] # to [6d9731e34a43726d756fdc9e2724bd962ed46942] # # patch "netsync.hh" # from [d98dd3961f34c034e8e05ef9e4c1d6c1b9a9fda4] # to [f1b6305e6b8247f28b646d7b859a8475ef8ed39b] # # patch "randomfile.hh" # from [e6405d71cded56a1955d95c090ee4a680e550cfd] # to [b1f6e5652eaa4a22cef5061e97930ad6ecb0ade7] # # patch "rcs_file.cc" # from [dd1b1700a5b3e19112a4c3ba98ad6b3d52b5688e] # to [888ba309a3a161cddb6f63f510e1e9bfb7b7da63] # # patch "selectors.cc" # from [e0fe016aca3d1fcc1c64d3f7543b4e2bc7419e64] # to [6e04d827ad6cdcd45bf4a9b2b703a32d36cdca1c] # # patch "selectors.hh" # from [0a31a5fa5e4adaf3e65f8c0935fb58e88cee0aac] # to [4c1242970da2473e28d859f407a05e0792ff5a20] # # patch "unix/get_system_flavour.cc" # from [288aafb6c8d8006b96b81f2222665c70110258b0] # to [e75e9a4586becb842532cd9abfb8d9b4107c0131] # # patch "unix/process.cc" # from [0cfa3c05d2dc345fedae7351557b46a502d14c05] # to [c30edf9e74742079e4229bc8cfb0d44054e8c5c3] # # patch "win32/get_system_flavour.cc" # from [9d6c2be53f75ba9e8d3728e1672c721a1af34d79] # to [ba19695250bdb6421c29aec529773b1748760691] # # patch "win32/process.cc" # from [abb7fc90da902839ceb22ec4c59e41a5b8bec05c] # to [7df8490bfa7e478eecba328f22895853da1cb3e5] # # patch "xdelta.cc" # from [4f26515e58c49f2015fafd6076a265772b7548ac] # to [f6ca886b245cd540d6b8a0dc24b285a0d6530592] # # patch "xdelta.hh" # from [68d15dc01398c7bb375b1a90fbb420bebef1bac7] # to [16bbaaed2e75018ccc76fa6ed421b38556f30e61] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,7 @@ +2005-05-12 Timothy Brownawell + + * (20 files): Do not indent with both tabs and spaces in the same file. + 2005-05-13 Ulrich Drepper * rcs_import.cc (process_one_hunk): Improve handling of corrupt --- basic_io.cc +++ basic_io.cc @@ -25,7 +25,7 @@ { L(F("error in %s:%d:%d:E: %s") % name % line % col % s); throw informative_failure((F("%s:%d:%d:E: %s") - % name % line % col % s).str()); + % name % line % col % s).str()); } @@ -44,13 +44,13 @@ for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) { switch (*i) - { - case '\\': - case '"': - escaped += '\\'; - default: - escaped += *i; - } + { + case '\\': + case '"': + escaped += '\\'; + default: + escaped += *i; + } } escaped += "\""; @@ -100,7 +100,7 @@ i != st.entries.end(); ++i) { for (size_t k = i->first.size(); k < st.indent; ++k) - out.put(' '); + out.put(' '); out.write(i->first.data(), i->first.size()); out.put(' '); out.write(i->second.data(), i->second.size()); --- basic_io.hh +++ basic_io.hh @@ -102,7 +102,7 @@ if (static_cast(in.lookahead) != '"') in.err("string did not end with '\"'"); in.eat(); - + return basic_io::TOK_STRING; } @@ -122,8 +122,8 @@ if (static_cast(in.lookahead) != ']') in.err("hex string did not end with ']'"); in.eat(); - - return basic_io::TOK_HEX; + + return basic_io::TOK_HEX; } default: if (std::isalpha(in.lookahead)) --- cycle_detector.hh +++ cycle_detector.hh @@ -20,7 +20,7 @@ typedef std::vector< T > edge_vec; typedef std::vector edge_map; typedef std::pair state; + typename edge_vec::const_iterator> state; typedef std::stack edge_stack; edge_map edges; @@ -33,9 +33,9 @@ edges.resize(src + 1); edge_vec & src_edges = edges.at(src); for (typename edge_vec::const_iterator i = src_edges.begin(); - i != src_edges.end(); ++i) + i != src_edges.end(); ++i) if (*i == dst) - return; + return; src_edges.push_back(dst); global_in_edges.insert(dst); } @@ -44,42 +44,42 @@ bool edge_makes_cycle(T const & src, T const & dst) { if (src == dst) - return true; + return true; if (dst >= edges.size() || edges.at(dst).empty()) - return false; + return false; if (global_in_edges.find(src) == global_in_edges.end()) - return false; + return false; while (!stk.empty()) stk.pop(); stk.push(make_pair(edges.at(dst).begin(), - edges.at(dst).end())); + edges.at(dst).end())); std::set visited; while (!stk.empty()) { - bool pushed = false; - for (state & curr = stk.top(); curr.first != curr.second && !pushed; ++curr.first) - { - T val = *(curr.first); - if (val == src) - { - return true; - } - if (val < edges.size() && ! edges.at(val).empty() - && visited.find(val) == visited.end()) - { - visited.insert(val); - stk.push(make_pair(edges.at(val).begin(), - edges.at(val).end())); - pushed = true; - } - } - if (!pushed) - stk.pop(); + bool pushed = false; + for (state & curr = stk.top(); curr.first != curr.second && !pushed; ++curr.first) + { + T val = *(curr.first); + if (val == src) + { + return true; + } + if (val < edges.size() && ! edges.at(val).empty() + && visited.find(val) == visited.end()) + { + visited.insert(val); + stk.push(make_pair(edges.at(val).begin(), + edges.at(val).end())); + pushed = true; + } + } + if (!pushed) + stk.pop(); } return false; } --- database.cc +++ database.cc @@ -2198,7 +2198,7 @@ lim += (F("WHERE id GLOB '%s*'") % i->second).str(); } - else if (i->first == selectors::sel_cert) + else if (i->first == selectors::sel_cert) { if (i->second.length() > 0) { --- diff_patch.hh +++ diff_patch.hh @@ -35,9 +35,9 @@ diff_type type); bool merge3(std::vector const & ancestor, - std::vector const & left, - std::vector const & right, - std::vector & merged); + std::vector const & left, + std::vector const & right, + std::vector & merged); struct merge_provider { @@ -46,40 +46,40 @@ manifest_map const & left_man; manifest_map const & right_man; merge_provider(app_state & app, - manifest_map const & anc_man, - manifest_map const & left_man, - manifest_map const & right_man); + manifest_map const & anc_man, + manifest_map const & left_man, + manifest_map const & right_man); // merge3 on a file (line by line) virtual bool try_to_merge_files(file_path const & anc_path, - file_path const & left_path, - file_path const & right_path, - file_path const & merged_path, - file_id const & ancestor_id, - file_id const & left_id, - file_id const & right, - file_id & merged_id); + file_path const & left_path, + file_path const & right_path, + file_path const & merged_path, + file_id const & ancestor_id, + file_id const & left_id, + file_id const & right, + file_id & merged_id); // merge2 on a file (line by line) virtual bool try_to_merge_files(file_path const & left_path, file_path const & right_path, file_path const & merged_path, - file_id const & left_id, - file_id const & right_id, - file_id & merged); + file_id const & left_id, + file_id const & right_id, + file_id & merged); virtual void record_merge(file_id const & left_ident, - file_id const & right_ident, - file_id const & merged_ident, - file_data const & left_data, - file_data const & merged_data); + file_id const & right_ident, + file_id const & merged_ident, + file_data const & left_data, + file_data const & merged_data); virtual void get_version(file_path const & path, - file_id const & ident, - file_data & dat); + file_id const & ident, + file_data & dat); virtual std::string get_file_encoding(file_path const & path, - manifest_map const & man); + manifest_map const & man); virtual ~merge_provider() {} }; @@ -88,22 +88,22 @@ { std::map temporary_store; update_merge_provider(app_state & app, - manifest_map const & anc_man, - manifest_map const & left_man, - manifest_map const & right_man); + manifest_map const & anc_man, + manifest_map const & left_man, + manifest_map const & right_man); virtual void record_merge(file_id const & left_ident, - file_id const & right_ident, - file_id const & merged_ident, - file_data const & left_data, - file_data const & merged_data); + file_id const & right_ident, + file_id const & merged_ident, + file_data const & left_data, + file_data const & merged_data); virtual void get_version(file_path const & path, - file_id const & ident, - file_data & dat); + file_id const & ident, + file_data & dat); virtual std::string get_file_encoding(file_path const & path, - manifest_map const & man); + manifest_map const & man); virtual ~update_merge_provider() {} }; --- interner.hh +++ interner.hh @@ -58,9 +58,9 @@ { is_new = true; T t = rev.size(); - fwd.insert(make_pair(s, t)); + fwd.insert(make_pair(s, t)); rev.push_back(s); - return t; + return t; } else return i->second; --- lcs.cc +++ lcs.cc @@ -69,8 +69,8 @@ std::vector work_vec::vec; template + typename B, + typename LCS> struct jaffer_edit_calculator { @@ -92,9 +92,9 @@ inline long size() const { if (end < start) - return start - end; + return start - end; else - return end - start; + return end - start; } inline subarray subset(long s, long e) const @@ -105,16 +105,16 @@ inline vt const & operator[](size_t idx) const { if (end < start) - return *(base + (start - (idx + 1))); + return *(base + (start - (idx + 1))); else - return *(base + (start + idx)); + return *(base + (start + idx)); } }; static long run(work_vec & fp, long k, - subarray const & a, long m, - subarray const & b, long n, - cost_vec & CC, long p) + subarray const & a, long m, + subarray const & b, long n, + cost_vec & CC, long p) { long cost = k + 2*p; @@ -126,19 +126,19 @@ I(x >= 0); while (true) - { - // record costs along the way - long xcst = m - x; - if (y < static_cast(CC.size()) && xcst >= 0) - { - CC[y] = std::min(xcst + cost, CC[y]); - } - if (x < m && y < n && a[x] == b[y]) - { - ++x; ++y; - } - else - break; + { + // record costs along the way + long xcst = m - x; + if (y < static_cast(CC.size()) && xcst >= 0) + { + CC[y] = std::min(xcst + cost, CC[y]); + } + if (x < m && y < n && a[x] == b[y]) + { + ++x; ++y; + } + else + break; } fp[k] = y; @@ -147,16 +147,16 @@ // 'compare' here is the core myers, manber and miller algorithm. static long compare(cost_vec & costs, - subarray const & a, long m, - subarray const & b, long n, - long p_lim, - bool full_scan = true) + subarray const & a, long m, + subarray const & b, long n, + long p_lim, + bool full_scan = true) { long lo = -(m+1), hi = (1+n); if (full_scan) { - lo = -(p_lim + 1); - hi = p_lim + 1 + (n-m); + lo = -(p_lim + 1); + hi = p_lim + 1 + (n-m); } work_vec fp(lo, hi); @@ -166,31 +166,31 @@ for (; p <= p_lim; ++p) { - // lower sweep - for (long k = -p; k < delta; ++k) - run(fp, k, a, m, b, n, costs, p); + // lower sweep + for (long k = -p; k < delta; ++k) + run(fp, k, a, m, b, n, costs, p); - // upper sweep - for (long k = delta + p; k > delta; --k) - run(fp, k, a, m, b, n, costs, p); + // upper sweep + for (long k = delta + p; k > delta; --k) + run(fp, k, a, m, b, n, costs, p); - // middle - long fpval = run(fp, delta, a, m, b, n, costs, p); + // middle + long fpval = run(fp, delta, a, m, b, n, costs, p); - // we can bail early if not doing a full scan - if (!full_scan && n <= fpval) - break; + // we can bail early if not doing a full scan + if (!full_scan && n <= fpval) + break; } return delta + 2*p; } static long divide_and_conquer(subarray const & a, long start_a, long end_a, - subarray const & b, long start_b, long end_b, - edit_vec & edits, - unsigned long edx, - long polarity, - long p_lim) + subarray const & b, long start_b, long end_b, + edit_vec & edits, + unsigned long edx, + long polarity, + long p_lim) { long mid_a = (start_a + end_a) / 2; long len_b = end_b - start_b; @@ -210,12 +210,12 @@ cost_vec rr(len_b + 1, len_a + len_b); compare (cc, - a.subset(start_a, mid_a), (mid_a - start_a), - b.subset(start_b, end_b), len_b, std::min(p_lim, len_a)); + a.subset(start_a, mid_a), (mid_a - start_a), + b.subset(start_b, end_b), len_b, std::min(p_lim, len_a)); compare (rr, - a.subset(end_a, mid_a), (end_a - mid_a), - b.subset(end_b, start_b), len_b, std::min(p_lim, len_a)); + a.subset(end_a, mid_a), (end_a - mid_a), + b.subset(end_b, start_b), len_b, std::min(p_lim, len_a)); long b_split = mid_split(len_a, len_b, rr, cc, tcst); @@ -223,16 +223,16 @@ long est_r = rr[len_b - b_split]; long cost_c = diff_to_et (a, start_a, mid_a, - b, start_b, start_b + b_split, - edits, edx, polarity, - (est_c - (b_split - (mid_a - start_a))) / 2); + b, start_b, start_b + b_split, + edits, edx, polarity, + (est_c - (b_split - (mid_a - start_a))) / 2); I(cost_c == est_c); long cost_r = diff_to_et (a, mid_a, end_a, - b, start_b + b_split, end_b, - edits, est_c + edx, polarity, - (est_r - ((len_b - b_split) - (end_a - mid_a))) / 2); + b, start_b + b_split, end_b, + edits, est_c + edx, polarity, + (est_r - ((len_b - b_split) - (end_a - mid_a))) / 2); I(cost_r == est_r); @@ -240,29 +240,29 @@ } static long mid_split(long m, long n, - cost_vec const & rr, - cost_vec const & cc, - long cost) + cost_vec const & rr, + cost_vec const & cc, + long cost) { long cdx = 1 + n/2; long rdx = n/2; while (true) { - I (rdx >= 0); + I (rdx >= 0); - if (cost == (cc[rdx] + rr[n-rdx])) - return rdx; - if (cost == (cc[cdx] + rr[n-cdx])) - return cdx; - --rdx; - ++cdx; + if (cost == (cc[rdx] + rr[n-rdx])) + return rdx; + if (cost == (cc[cdx] + rr[n-cdx])) + return cdx; + --rdx; + ++cdx; } } static void order_edits(edit_vec const & edits, - long sign, - edit_vec & nedits) + long sign, + edit_vec & nedits) { nedits.clear(); nedits.resize(edits.size()); @@ -270,8 +270,8 @@ if (cost == 0) { - nedits = edits; - return; + nedits = edits; + return; } edit_vec sedits = edits; @@ -291,40 +291,40 @@ while (bdx < len_b || adx < len_a) { - long del = (ddx < 0) ? 0 : sedits[ddx]; - long ins = (idx >= cost) ? 0 : sedits[idx]; - - if (del < 0 && adx >= (-1 - del) && - ins > 0 && bdx >= (-1 + ins)) - { - nedits[ndx] = del; - nedits[ndx+1] = ins; - --ddx; ++idx; ndx += 2; ++adx; ++bdx; - } - else if (del < 0 && adx >= (-1 - del)) - { - nedits[ndx] = del; - --ddx; ++ndx; ++adx; - } - else if (ins > 0 && bdx >= (-1 + ins)) - { - nedits[ndx] = ins; - ++idx; ++ndx; ++bdx; - } - else - { - ++adx; ++bdx; - } + long del = (ddx < 0) ? 0 : sedits[ddx]; + long ins = (idx >= cost) ? 0 : sedits[idx]; + + if (del < 0 && adx >= (-1 - del) && + ins > 0 && bdx >= (-1 + ins)) + { + nedits[ndx] = del; + nedits[ndx+1] = ins; + --ddx; ++idx; ndx += 2; ++adx; ++bdx; + } + else if (del < 0 && adx >= (-1 - del)) + { + nedits[ndx] = del; + --ddx; ++ndx; ++adx; + } + else if (ins > 0 && bdx >= (-1 + ins)) + { + nedits[ndx] = ins; + ++idx; ++ndx; ++bdx; + } + else + { + ++adx; ++bdx; + } } } // trims and calls diff_to_ez static long diff_to_et(subarray const & a, long start_a, long end_a, - subarray const & b, long start_b, long end_b, - std::vector & edits, - long edx, - long polarity, - long p_lim) + subarray const & b, long start_b, long end_b, + std::vector & edits, + long edx, + long polarity, + long p_lim) { I(start_a >= 0); @@ -341,32 +341,32 @@ long bsx, bdx, asx, adx; for (bdx = end_b - 1, adx = end_a - 1; - (start_b <= bdx) && (start_a <= adx) && (a[adx] == b[bdx]); - --bdx, --adx); + (start_b <= bdx) && (start_a <= adx) && (a[adx] == b[bdx]); + --bdx, --adx); for (bsx = start_b, asx = start_a; - (bsx < bdx) && (asx < adx) && (a[asx] == b[bsx]); - ++bsx, ++asx); + (bsx < bdx) && (asx < adx) && (a[asx] == b[bsx]); + ++bsx, ++asx); // we've trimmed; now call diff_to_ez. long delta = (bdx - bsx) - (adx - asx); if (delta < 0) return diff_to_ez (b, bsx, bdx+1, - a, asx, adx+1, - edits, edx, -polarity, delta + p_lim); + a, asx, adx+1, + edits, edx, -polarity, delta + p_lim); else return diff_to_ez (a, asx, adx+1, - b, bsx, bdx+1, - edits, edx, polarity, p_lim); + b, bsx, bdx+1, + edits, edx, polarity, p_lim); } static long diff_to_ez(subarray const & a, long start_a, long end_a, - subarray const & b, long start_b, long end_b, - std::vector & edits, - long edx1, - long polarity, - long p_lim) + subarray const & b, long start_b, long end_b, + std::vector & edits, + long edx1, + long polarity, + long p_lim) { I(start_a >= 0); @@ -386,69 +386,69 @@ // easy case #1: B inserts only if (p_lim == 0) { - // A == B, no edits - if (len_a == len_b) - return 0; - - long adx = start_a; - long bdx = start_b; - long edx0 = edx1; - - while (true) - { - if (bdx >= end_b) - return len_b - len_a; - - if (adx >= end_a) - { - for (long idx = bdx, edx = edx0; - idx < end_b; - ++idx, ++edx) - edits[edx] = polarity * (idx+1); - - return len_b - len_a; - } - - if (a[adx] == b[bdx]) - { - ++adx; ++bdx; - } - else - { - edits[edx0] = polarity * (bdx+1); - ++bdx; ++edx0; - } - } + // A == B, no edits + if (len_a == len_b) + return 0; + + long adx = start_a; + long bdx = start_b; + long edx0 = edx1; + + while (true) + { + if (bdx >= end_b) + return len_b - len_a; + + if (adx >= end_a) + { + for (long idx = bdx, edx = edx0; + idx < end_b; + ++idx, ++edx) + edits[edx] = polarity * (idx+1); + + return len_b - len_a; + } + + if (a[adx] == b[bdx]) + { + ++adx; ++bdx; + } + else + { + edits[edx0] = polarity * (bdx+1); + ++bdx; ++edx0; + } + } } // easy case #2: delete all A, insert all B else if (len_a <= p_lim) { - I(len_a == p_lim); + I(len_a == p_lim); - long edx0 = edx1; - for (long idx = start_a; idx < end_a; ++idx, ++edx0) - edits[edx0] = polarity * (-1 - idx); - - for (long jdx = start_b; jdx < end_b; ++jdx, ++edx0) - edits[edx0] = polarity * (jdx + 1); - - return len_a + len_b; + long edx0 = edx1; + for (long idx = start_a; idx < end_a; ++idx, ++edx0) + edits[edx0] = polarity * (-1 - idx); + + for (long jdx = start_b; jdx < end_b; ++jdx, ++edx0) + edits[edx0] = polarity * (jdx + 1); + + return len_a + len_b; } // hard case: recurse on subproblems else { - return divide_and_conquer (a, start_a, end_a, - b, start_b, end_b, - edits, edx1, polarity, p_lim); + return divide_and_conquer (a, start_a, end_a, + b, start_b, end_b, + edits, edx1, polarity, p_lim); } } static void diff_to_edits(subarray const & a, long m, - subarray const & b, long n, - std::vector & edits, - long p_lim) + subarray const & b, long n, + std::vector & edits, + long p_lim) { I(m <= n); cost_vec costs(m+n); // scratch array, ignored @@ -457,32 +457,32 @@ edits.clear(); edits.resize(edit_distance, 0); long cost = diff_to_et(a, 0, m, - b, 0, n, - edits, 0, 1, (edit_distance - (n-m)) / 2); + b, 0, n, + edits, 0, 1, (edit_distance - (n-m)) / 2); I(cost == edit_distance); } static void edits_to_lcs (std::vector const & edits, - subarray const a, long m, long n, - LCS output) + subarray const a, long m, long n, + LCS output) { long edx = 0, sdx = 0, adx = 0; typedef typename std::iterator_traits::value_type vt; std::vector lcs(((m + n) - edits.size()) / 2); while (true) { - long edit = (edx < static_cast(edits.size())) ? edits[edx] : 0; - - if (adx >= m) - break; - else if (edit > 0) - { ++edx; } - else if (edit == 0) - { lcs[sdx++] = a[adx++]; } - else if (adx >= (-1 - edit)) - { ++edx; ++adx; } - else - { lcs[sdx++] = a[adx++]; } + long edit = (edx < static_cast(edits.size())) ? edits[edx] : 0; + + if (adx >= m) + break; + else if (edit > 0) + { ++edx; } + else if (edit == 0) + { lcs[sdx++] = a[adx++]; } + else if (adx >= (-1 - edit)) + { ++edx; ++adx; } + else + { lcs[sdx++] = a[adx++]; } } std::copy(lcs.begin(), lcs.end(), output); @@ -491,13 +491,13 @@ template + typename B, + typename LCS> void _edit_script(A begin_a, A end_a, - B begin_b, B end_b, - long p_lim, - std::vector & edits_out, - LCS ignored_out) + B begin_b, B end_b, + long p_lim, + std::vector & edits_out, + LCS ignored_out) { typedef jaffer_edit_calculator calc_t; long len_a = end_a - begin_a; @@ -512,7 +512,7 @@ calc_t::diff_to_edits (b, len_b, a, len_a, edits, p_lim); calc_t::order_edits (edits, -1, ordered); for (size_t i = 0; i < ordered.size(); ++i) - ordered[i] *= -1; + ordered[i] *= -1; } else { @@ -527,12 +527,12 @@ template + typename B, + typename LCS> void _longest_common_subsequence(A begin_a, A end_a, - B begin_b, B end_b, - long p_lim, - LCS out) + B begin_b, B end_b, + long p_lim, + LCS out) { typedef jaffer_edit_calculator calc_t; long len_a = end_a - begin_a; @@ -559,28 +559,28 @@ void longest_common_subsequence(std::vector::const_iterator begin_a, - std::vector::const_iterator end_a, - std::vector::const_iterator begin_b, - std::vector::const_iterator end_b, - long p_lim, - std::back_insert_iterator< std::vector > lcs) + std::vector::const_iterator end_a, + std::vector::const_iterator begin_b, + std::vector::const_iterator end_b, + long p_lim, + std::back_insert_iterator< std::vector > lcs) { _longest_common_subsequence(begin_a, end_a, - begin_b, end_b, - p_lim, lcs); + begin_b, end_b, + p_lim, lcs); } void edit_script(std::vector::const_iterator begin_a, - std::vector::const_iterator end_a, - std::vector::const_iterator begin_b, - std::vector::const_iterator end_b, - long p_lim, - std::vector & edits_out) + std::vector::const_iterator end_a, + std::vector::const_iterator begin_b, + std::vector::const_iterator end_b, + long p_lim, + std::vector & edits_out) { std::vector lcs; _edit_script(begin_a, end_a, - begin_b, end_b, - p_lim, edits_out, - back_inserter(lcs)); + begin_b, end_b, + p_lim, edits_out, + back_inserter(lcs)); } --- mkstemp.cc +++ mkstemp.cc @@ -49,13 +49,13 @@ fd = open(tmp.c_str(), O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); if (fd >= 0) { - fs::path path; - path = mkpath(tmp); - tmpl = path.native_directory_string(); - return fd; + fs::path path; + path = mkpath(tmp); + tmpl = path.native_directory_string(); + return fd; } else if (errno != EEXIST) - break; + break; } return -1; } --- netio.hh +++ netio.hh @@ -22,9 +22,9 @@ inline void require_bytes(std::string const & str, - size_t pos, - size_t len, - std::string const & name) + size_t pos, + size_t len, + std::string const & name) { // if you've gone past the end of the buffer, there's a logic error, // and this program is not safe to keep running. shut down. @@ -35,15 +35,15 @@ return; if (str.size() < pos + len) throw bad_decode(F("need %d bytes to decode %s at %d, only have %d") - % len % name % pos % (str.size() - pos)); + % len % name % pos % (str.size() - pos)); } template inline bool try_extract_datum_uleb128(std::string const & in, - size_t & pos, - std::string const & name, - T & out) + size_t & pos, + std::string const & name, + T & out) { BOOST_STATIC_ASSERT(std::numeric_limits::is_signed == false); size_t shift = 0; @@ -52,23 +52,23 @@ while (maxbytes > 0) { if (pos >= in.size()) - return false; + return false; T curr = widen(in[pos]); ++pos; out |= ((static_cast(curr) - & static_cast(0x7f)) << shift); + & static_cast(0x7f)) << shift); bool finished = ! static_cast(static_cast(curr) - & static_cast(0x80)); + & static_cast(0x80)); if (finished) - break; + break; else if (maxbytes == 1) - throw bad_decode(F("uleb128 decode for '%s' into %d-byte datum overflowed") - % name % maxbytes); + throw bad_decode(F("uleb128 decode for '%s' into %d-byte datum overflowed") + % name % maxbytes); else - { - --maxbytes; - shift += 7; - } + { + --maxbytes; + shift += 7; + } } return true; } @@ -76,14 +76,14 @@ template inline T extract_datum_uleb128(std::string const & in, - size_t & pos, - std::string const & name) + size_t & pos, + std::string const & name) { T out; size_t tpos = pos; if (! try_extract_datum_uleb128(in, tpos, name, out)) throw bad_decode(F("ran out of bytes reading uleb128 value for '%s' at pos %d") - % name % pos); + % name % pos); pos = tpos; return out; } @@ -100,24 +100,24 @@ T remainder = in >> 7; bool finished = ! static_cast(remainder); if (finished) - { - out += item; - break; - } + { + out += item; + break; + } else - { - out += (item | static_cast(0x80)); - --maxbytes; - in = remainder; - } + { + out += (item | static_cast(0x80)); + --maxbytes; + in = remainder; + } } } template inline T extract_datum_lsb(std::string const & in, - size_t & pos, - std::string const & name) + size_t & pos, + std::string const & name) { size_t nbytes = sizeof(T); T out = 0; @@ -150,16 +150,16 @@ inline void extract_variable_length_string(std::string const & buf, - std::string & out, - size_t & pos, - std::string const & name, - size_t maxlen = std::numeric_limits::max()) + std::string & out, + size_t & pos, + std::string const & name, + size_t maxlen = std::numeric_limits::max()) { BOOST_STATIC_ASSERT(sizeof(std::string::size_type) == sizeof(size_t)); size_t len = extract_datum_uleb128(buf, pos, name); if (len > maxlen) throw bad_decode(F("decoding variable length string of %d bytes for '%s', maximum is %d") - % len % name % maxlen); + % len % name % maxlen); require_bytes(buf, pos, len, name); out.assign(buf, pos, len); pos += len; @@ -167,7 +167,7 @@ inline void insert_variable_length_string(std::string const & in, - std::string & buf) + std::string & buf) { size_t len = in.size(); insert_datum_uleb128(len, buf); @@ -177,9 +177,9 @@ inline std::string extract_substring(std::string const & buf, - size_t & pos, - size_t len, - std::string const & name) + size_t & pos, + size_t len, + std::string const & name) { require_bytes(buf, pos, len, name); std::string tmp = buf.substr(pos, len); @@ -189,12 +189,12 @@ inline void assert_end_of_buffer(std::string const & str, - size_t pos, - std::string const & name) + size_t pos, + std::string const & name) { if (str.size() != pos) throw bad_decode(F("expected %s to end at %d, have %d bytes") - % name % pos % str.size()); + % name % pos % str.size()); } #endif // __NETIO_HH__ --- netsync.hh +++ netsync.hh @@ -20,9 +20,9 @@ protocol_voice; void run_netsync_protocol(protocol_voice voice, - protocol_role role, - utf8 const & addr, - std::vector collections, - app_state & app); + protocol_role role, + utf8 const & addr, + std::vector collections, + app_state & app); #endif // __NETSYNC_H__ --- randomfile.hh +++ randomfile.hh @@ -28,10 +28,10 @@ return static_cast(rand() % lines.size()); else { - if (lines.size() == 0) - return 0; - else - return static_cast(rand() % (lines.size() - 1)); + if (lines.size() == 0) + return 0; + else + return static_cast(rand() % (lines.size() - 1)); } } @@ -48,7 +48,7 @@ void append_to(std::vector & other) { for (std::vector::const_iterator i = lines.begin(); - i != lines.end(); ++i) + i != lines.end(); ++i) other.push_back(prefix + *i); } @@ -56,7 +56,7 @@ lines.clear(); for (int i = 0; i < num_lines; ++i) { - lines.push_back(std::string("initial ") + boost::lexical_cast(i)); + lines.push_back(std::string("initial ") + boost::lexical_cast(i)); } } @@ -64,7 +64,7 @@ lines.clear(); for (int i = 0; i < num_lines; ++i) { - lines.push_back(std::string("append ") + boost::lexical_cast(i)); + lines.push_back(std::string("append ") + boost::lexical_cast(i)); } } @@ -72,7 +72,7 @@ lines.clear(); for (int i = 0; i < num_lines; ++i) { - lines.push_back(std::string("prepend ") + boost::lexical_cast(i)); + lines.push_back(std::string("prepend ") + boost::lexical_cast(i)); } } @@ -90,17 +90,17 @@ int nlines = static_cast(nlines_d); for (int i = 0; i < nlines; ++i) { - lines.insert(lines.begin() + random_index(), - std::string("insert ") + boost::lexical_cast(i)); + lines.insert(lines.begin() + random_index(), + std::string("insert ") + boost::lexical_cast(i)); } } static void build_random_fork(std::vector & ancestor, - std::vector & left, - std::vector & right, - std::vector & merged, - int seed, - int n_hunks = 10) + std::vector & left, + std::vector & right, + std::vector & merged, + int seed, + int n_hunks = 10) { file_randomizer fr; @@ -108,71 +108,71 @@ // maybe prepend something to one side or the other if (fr.random_bool()) { - fr.prepend_sequential_lines(); - if (fr.random_bool()) - fr.append_to(left); - else - fr.append_to(right); - fr.append_to(merged); + fr.prepend_sequential_lines(); + if (fr.random_bool()) + fr.append_to(left); + else + fr.append_to(right); + fr.append_to(merged); } fr.lines.clear(); for (int h = 0; h < n_hunks; ++h) { - file_randomizer hr; - hr.seed(seed + h); - hr.set_prefix(std::string("hunk ") + boost::lexical_cast(h) + " -- "); - hr.initial_sequential_lines(10); - hr.append_to(ancestor); - if (hr.random_bool()) - { - // doing an insert - if (hr.random_bool()) - { - // inserting in left - hr.append_to(right); - hr.insert_sequential_percent_of_lines_randomly(); - hr.append_to(left); - } - else - { - // inserting in right - hr.append_to(left); - hr.insert_sequential_percent_of_lines_randomly(); - hr.append_to(right); - } - hr.append_to(merged); - } - else - { - // doing a delete - if (hr.random_bool()) - { - // deleting in left - hr.append_to(right); - hr.delete_percent_of_lines_randomly(); - hr.append_to(left); - } - else - { - // deleting in right - hr.append_to(left); - hr.delete_percent_of_lines_randomly(); - hr.append_to(right); - } - hr.append_to(merged); - } + file_randomizer hr; + hr.seed(seed + h); + hr.set_prefix(std::string("hunk ") + boost::lexical_cast(h) + " -- "); + hr.initial_sequential_lines(10); + hr.append_to(ancestor); + if (hr.random_bool()) + { + // doing an insert + if (hr.random_bool()) + { + // inserting in left + hr.append_to(right); + hr.insert_sequential_percent_of_lines_randomly(); + hr.append_to(left); + } + else + { + // inserting in right + hr.append_to(left); + hr.insert_sequential_percent_of_lines_randomly(); + hr.append_to(right); + } + hr.append_to(merged); + } + else + { + // doing a delete + if (hr.random_bool()) + { + // deleting in left + hr.append_to(right); + hr.delete_percent_of_lines_randomly(); + hr.append_to(left); + } + else + { + // deleting in right + hr.append_to(left); + hr.delete_percent_of_lines_randomly(); + hr.append_to(right); + } + hr.append_to(merged); + } } // maybe append something to one side or the other if (fr.random_bool()) { - fr.append_sequential_lines(); - if (fr.random_bool()) - fr.append_to(left); - else - fr.append_to(right); - fr.append_to(merged); + fr.append_sequential_lines(); + if (fr.random_bool()) + fr.append_to(left); + else + fr.append_to(right); + fr.append_to(merged); } } }; --- rcs_file.cc +++ rcs_file.cc @@ -43,16 +43,16 @@ { struct stat st; if (stat(fn.c_str(), &st) == -1) - throw oops("stat of " + filename + " failed"); + throw oops("stat of " + filename + " failed"); length = st.st_size; fd = open(filename.c_str(), O_RDONLY); if (fd == -1) - throw oops("open of " + filename + " failed"); + throw oops("open of " + filename + " failed"); } ~file_handle() { if (close(fd) == -1) - throw oops("close of " + filename + " failed"); + throw oops("close of " + filename + " failed"); } }; struct file_source @@ -81,8 +81,8 @@ return good(); } file_source(std::string const & fn, - int f, - off_t len) : + int f, + off_t len) : filename(fn), fd(f), length(len), @@ -113,20 +113,20 @@ { struct stat st; if (stat(fn.c_str(), &st) == -1) - throw oops("stat of " + filename + " failed"); + throw oops("stat of " + filename + " failed"); length = st.st_size; fd = CreateFile(fn.c_str(), - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, 0, NULL); + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, 0, NULL); if (fd == NULL) - throw oops("open of " + filename + " failed"); + throw oops("open of " + filename + " failed"); } ~file_handle() { if (CloseHandle(fd)==0) - throw oops("close of " + filename + " failed"); + throw oops("close of " + filename + " failed"); } }; @@ -157,8 +157,8 @@ return good(); } file_source(std::string const & fn, - HANDLE f, - off_t len) : + HANDLE f, + off_t len) : filename(fn), fd(f), length(len), @@ -198,7 +198,7 @@ static token_type get_token(file_source & ist, - std::string & str) + std::string & str) { bool saw_idchar = false; int i = ist.peek(); @@ -209,9 +209,9 @@ while (true) { if (i == EOF) - return TOK_NONE; + return TOK_NONE; if (!isspace(i)) - break; + break; ist.get(c); i = ist.peek(); } @@ -231,32 +231,32 @@ case '@': ist.get(c); while (ist.get(c)) - { - if (c == '@') - { - if (ist.peek() == '@') - { ist.get(c); str += c; } - else - break; - } - else - str += c; - } + { + if (c == '@') + { + if (ist.peek() == '@') + { ist.get(c); str += c; } + else + break; + } + else + str += c; + } return TOK_STRING; break; default: while (ist.good() - && i != ';' - && i != ':' - && !isspace(i)) - { - ist.get(c); - if (! isdigit(c) && c != '.') - saw_idchar = true; - str += c; - i = ist.peek(); - } + && i != ';' + && i != ':' + && !isspace(i)) + { + ist.get(c); + if (! isdigit(c) && c != '.') + saw_idchar = true; + str += c; + i = ist.peek(); + } break; } @@ -276,7 +276,7 @@ token_type ttype; parser(file_source & s, - rcs_file & r) + rcs_file & r) : ist(s), r(r) {} @@ -285,17 +285,17 @@ switch (tt) { case TOK_STRING: - return "TOK_STRING"; + return "TOK_STRING"; case TOK_SYMBOL: - return "TOK_SYMBOL"; + return "TOK_SYMBOL"; case TOK_NUM: - return "TOK_NUM"; + return "TOK_NUM"; case TOK_SEMI: - return "TOK_SEMI"; + return "TOK_SEMI"; case TOK_COLON: - return "TOK_COLON"; + return "TOK_COLON"; case TOK_NONE: - return "TOK_NONE"; + return "TOK_NONE"; } return "TOK_UNKNOWN"; } @@ -317,11 +317,11 @@ { if (ttype != want) throw oops("parse failure: expecting " - + tt2str(want) - + " got " - + tt2str(ttype) - + " with value: " - + token); + + tt2str(want) + + " got " + + tt2str(ttype) + + " with value: " + + token); advance(); } @@ -340,18 +340,18 @@ std::string tmp; if (!symp(expected)) throw oops(std::string("parse failure: ") - + "expecting word '" - + expected - + "'"); + + "expecting word '" + + expected + + "'"); advance(); } bool wordp() { return (ttype == TOK_STRING - || ttype == TOK_SYMBOL - || ttype == TOK_NUM - || ttype == TOK_COLON); + || ttype == TOK_SYMBOL + || ttype == TOK_NUM + || ttype == TOK_COLON); } void word() { @@ -364,9 +364,9 @@ { while(symp() && !symp(terminator)) { - sym(); - while (wordp()) word(); - semi(); + sym(); + while (wordp()) word(); + semi(); } } @@ -378,9 +378,9 @@ expect("symbols"); while(symp()) { - std::string stmp, ntmp; - sym(stmp); colon(); num(ntmp); - r.admin.symbols.insert(make_pair(ntmp, stmp)); + std::string stmp, ntmp; + sym(stmp); colon(); num(ntmp); + r.admin.symbols.insert(make_pair(ntmp, stmp)); } semi(); expect("locks"); while(symp()) { sym(); colon(); num(); } semi(); @@ -394,22 +394,22 @@ { while (nump()) { - rcs_delta d; - num(d.num); - expect("date"); num(d.date); semi(); - expect("author"); sym(d.author); semi(); - expect("state"); if (symp()) sym(d.state); semi(); - expect("branches"); - while(nump()) - { - std::string tmp; - num(tmp); - d.branches.push_back(tmp); - } - semi(); - expect("next"); if (nump()) num(d.next); semi(); - parse_newphrases("desc"); - r.push_delta(d); + rcs_delta d; + num(d.num); + expect("date"); num(d.date); semi(); + expect("author"); sym(d.author); semi(); + expect("state"); if (symp()) sym(d.state); semi(); + expect("branches"); + while(nump()) + { + std::string tmp; + num(tmp); + d.branches.push_back(tmp); + } + semi(); + expect("next"); if (nump()) num(d.next); semi(); + parse_newphrases("desc"); + r.push_delta(d); } } @@ -422,12 +422,12 @@ { while(nump()) { - rcs_deltatext d; - num(d.num); - expect("log"); str(d.log); - parse_newphrases("text"); - expect("text"); str(d.text); - r.push_deltatext(d); + rcs_deltatext d; + num(d.num); + expect("log"); str(d.log); + parse_newphrases("text"); + expect("text"); str(d.text); + r.push_deltatext(d); } } --- selectors.cc +++ selectors.cc @@ -14,9 +14,9 @@ static void decode_selector(std::string const & orig_sel, - selector_type & type, - std::string & sel, - app_state & app) + selector_type & type, + std::string & sel, + app_state & app) { sel = orig_sel; @@ -24,54 +24,54 @@ if (sel.size() < 2 || sel[1] != ':') { - std::string tmp; - if (!app.lua.hook_expand_selector(sel, tmp)) - { - L(F("expansion of selector '%s' failed\n") % sel); - } - else - { - P(F("expanded selector '%s' -> '%s'\n") % sel % tmp); - sel = tmp; - } + std::string tmp; + if (!app.lua.hook_expand_selector(sel, tmp)) + { + L(F("expansion of selector '%s' failed\n") % sel); + } + else + { + P(F("expanded selector '%s' -> '%s'\n") % sel % tmp); + sel = tmp; + } } if (sel.size() >= 2 && sel[1] == ':') { - switch (sel[0]) - { - case 'a': - type = sel_author; - break; - case 'b': - type = sel_branch; - break; - case 'd': - type = sel_date; - break; - case 'i': - type = sel_ident; - break; - case 't': - type = sel_tag; - break; - case 'c': - type = sel_cert; - break; - default: - W(F("unknown selector type: %c\n") % sel[0]); - break; - } - sel.erase(0,2); + switch (sel[0]) + { + case 'a': + type = sel_author; + break; + case 'b': + type = sel_branch; + break; + case 'd': + type = sel_date; + break; + case 'i': + type = sel_ident; + break; + case 't': + type = sel_tag; + break; + case 'c': + type = sel_cert; + break; + default: + W(F("unknown selector type: %c\n") % sel[0]); + break; + } + sel.erase(0,2); } } void complete_selector(std::string const & orig_sel, - std::vector > const & limit, - selector_type & type, - std::set & completions, - app_state & app) + std::vector > const & limit, + selector_type & type, + std::set & completions, + app_state & app) { std::string sel; decode_selector(orig_sel, type, sel, app); @@ -80,35 +80,35 @@ std::vector > parse_selector(std::string const & str, - app_state & app) + app_state & app) { std::vector > sels; // this rule should always be enabled, even if the user specifies // --norc: if you provide a revision id, you get a revision id. if (str.find_first_not_of(constants::legal_id_bytes) == std::string::npos - && str.size() == constants::idlen) + && str.size() == constants::idlen) { - sels.push_back(std::make_pair(sel_ident, str)); + sels.push_back(std::make_pair(sel_ident, str)); } else { - typedef boost::tokenizer > tokenizer; - boost::char_separator slash("/"); - tokenizer tokens(str, slash); + typedef boost::tokenizer > tokenizer; + boost::char_separator slash("/"); + tokenizer tokens(str, slash); - std::vector selector_strings; - copy(tokens.begin(), tokens.end(), back_inserter(selector_strings)); + std::vector selector_strings; + copy(tokens.begin(), tokens.end(), back_inserter(selector_strings)); - for (std::vector::const_iterator i = selector_strings.begin(); - i != selector_strings.end(); ++i) - { - std::string sel; - selector_type type = sel_unknown; + for (std::vector::const_iterator i = selector_strings.begin(); + i != selector_strings.end(); ++i) + { + std::string sel; + selector_type type = sel_unknown; - decode_selector(*i, type, sel, app); - sels.push_back(std::make_pair(type, sel)); - } + decode_selector(*i, type, sel, app); + sels.push_back(std::make_pair(type, sel)); + } } return sels; --- selectors.hh +++ selectors.hh @@ -31,13 +31,13 @@ void complete_selector(std::string const & orig_sel, - std::vector > const & limit, - selector_type & type, - std::set & completions, - app_state & app); + std::vector > const & limit, + selector_type & type, + std::set & completions, + app_state & app); std::vector > parse_selector(std::string const & str, - app_state & app); + app_state & app); }; // namespace selectors --- unix/get_system_flavour.cc +++ unix/get_system_flavour.cc @@ -13,9 +13,9 @@ Linux only knows 0 - as >0 is not an error condition there, relax a bit */ I(uname(&n) >= 0); - ident = (F("%s %s %s %s") - % n.sysname - % n.release - % n.version - % n.machine).str(); + ident = (F("%s %s %s %s") + % n.sysname + % n.release + % n.version + % n.machine).str(); } --- unix/process.cc +++ unix/process.cc @@ -99,5 +99,5 @@ pid_t get_process_id() { - return getpid(); + return getpid(); } --- win32/get_system_flavour.cc +++ win32/get_system_flavour.cc @@ -15,15 +15,15 @@ }; void key_to_string(unsigned long key, - table_entry *table, - std::string & str, - std::string const & def) + table_entry *table, + std::string & str, + std::string const & def) { while (table->val != NULL) { if (table->key == key) { - str = std::string(table->val); - return; + str = std::string(table->val); + return; } ++table; } @@ -147,16 +147,16 @@ else { key_to_string(si.wProcessorArchitecture, processors, processor, "unknown"); - processor = (F("%s (level %d, rev %d)") - % processor - % si.wProcessorLevel - % si.wProcessorRevision).str(); + processor = (F("%s (level %d, rev %d)") + % processor + % si.wProcessorLevel + % si.wProcessorRevision).str(); } ident = (F("Windows %s (%d.%d, build %d) on %s") - % family - % vi.dwMajorVersion - % vi.dwMinorVersion - % vi.dwBuildNumber - % processor).str(); + % family + % vi.dwMajorVersion + % vi.dwMinorVersion + % vi.dwBuildNumber + % processor).str(); } --- win32/process.cc +++ win32/process.cc @@ -54,7 +54,7 @@ for (const char *const *i = argv+1; *i; ++i) { if (i) - cmdline_ss << ", "; + cmdline_ss << ", "; cmdline_ss << "'" << *i << "'"; } L(F("spawning command: %s\n") % cmdline_ss.str()); --- xdelta.cc +++ xdelta.cc @@ -69,8 +69,8 @@ static inline void init_match_table(string const & a, - string::size_type blocksz, - match_table & tab) + string::size_type blocksz, + match_table & tab) { string::size_type sz = a.size(); for (string::size_type i = 0; i < sz; i += blocksz) @@ -78,7 +78,7 @@ string::size_type step = ((i + blocksz) >= sz) ? (sz - i) : blocksz; u32 sum = adler32(reinterpret_cast(a.data() + i), step).sum(); if (tab.find(sum) == tab.end()) - tab.insert(make_pair(sum, make_pair(i, step))); + tab.insert(make_pair(sum, make_pair(i, step))); } return; } @@ -86,14 +86,14 @@ static inline bool find_match(match_table const & matches, - vector & delta, - adler32 const & rolling, - string const & a, - string const & b, - string::size_type bpos, - string::size_type & apos, - string::size_type & alen, - string::size_type & badvance) + vector & delta, + adler32 const & rolling, + string const & a, + string const & b, + string::size_type bpos, + string::size_type & apos, + string::size_type & alen, + string::size_type & badvance) { u32 sum = rolling.sum(); match_table::const_iterator e = matches.find(sum); @@ -118,10 +118,10 @@ // see if we can extend our match forwards while((apos + alen >= 0) - && (bpos + badvance >= 0) - && (apos + alen < a.size()) - && (bpos + badvance < b.size()) - && (a[apos + alen] == b[bpos + badvance])) + && (bpos + badvance >= 0) + && (apos + alen < a.size()) + && (bpos + badvance < b.size()) + && (a[apos + alen] == b[bpos + badvance])) { ++alen; ++badvance; @@ -131,26 +131,26 @@ if (! delta.empty() && delta.back().code == insn::insert) { while(apos > 0 - && bpos > 0 - && a[apos - 1] == b[bpos - 1] - && !delta.back().payload.empty()) - { - I(a[apos - 1] == *(delta.back().payload.rbegin())); - I(delta.back().payload.size() > 0); - delta.back().payload.resize(delta.back().payload.size() - 1); - --apos; - --bpos; - ++alen; - // the significant thing here is that we do not move - // 'badvance' forward, just alen. - } + && bpos > 0 + && a[apos - 1] == b[bpos - 1] + && !delta.back().payload.empty()) + { + I(a[apos - 1] == *(delta.back().payload.rbegin())); + I(delta.back().payload.size() > 0); + delta.back().payload.resize(delta.back().payload.size() - 1); + --apos; + --bpos; + ++alen; + // the significant thing here is that we do not move + // 'badvance' forward, just alen. + } // if we've extended back to consume the *entire* insert, // let's do away with it altogether. if (delta.back().payload.empty()) - { - delta.pop_back(); - } + { + delta.pop_back(); + } } I(memcmp(a.data() + apos, b.data() + bpos, alen) == 0); @@ -172,12 +172,12 @@ { delta.push_back(insn(i, matchlen)); } - + static void compute_delta_insns(string const & a, - string const & b, - vector & delta) + string const & b, + vector & delta) { string::size_type blocksz = 64; match_table matches ((a.size() / blocksz) * 2); @@ -186,16 +186,16 @@ if (b.size() < blocksz) { for (string::size_type i = 0; i < b.size(); ++i) - insert_insn(delta, b[i]); + insert_insn(delta, b[i]); return; } adler32 rolling(reinterpret_cast(b.data()), blocksz); for (string::size_type - sz = b.size(), - lo = 0, - hi = blocksz; + sz = b.size(), + lo = 0, + hi = blocksz; lo < sz; ) { string::size_type apos = 0, alen = 1, badvance = 1; @@ -204,27 +204,27 @@ if (found_match) { - copy_insn(delta, apos, alen); + copy_insn(delta, apos, alen); } else - { + { I(apos + alen <= a.size()); I(alen == 1); I(alen < blocksz); I(lo >= 0); I(lo < b.size()); - insert_insn(delta, b[lo]); - } + insert_insn(delta, b[lo]); + } string::size_type next = lo; for (; next < lo + badvance; ++next) - { - I(next >= 0); - I(next < b.size()); - rolling.out(static_cast(b[next])); - if (next + blocksz < b.size()) - rolling.in(static_cast(b[next + blocksz])); - } + { + I(next >= 0); + I(next < b.size()); + rolling.out(static_cast(b[next])); + if (next + blocksz < b.size()) + rolling.in(static_cast(b[next + blocksz])); + } lo = next; hi = lo + blocksz; } @@ -248,8 +248,8 @@ void compute_delta(manifest_map const & a, - manifest_map const & b, - string & delta) + manifest_map const & b, + string & delta) { delta.clear(); ostringstream oss; @@ -264,50 +264,50 @@ size_t isz = 0; if (i != a.end()) - isz = i->first().size() + 2 + i->second.inner()().size() + 1; + isz = i->first().size() + 2 + i->second.inner()().size() + 1; if (i != a.end() && i->first == j->first) - { - if (i->second == j->second) - { - // this line was copied - len += isz; - } - else - { - // this line was changed, but the *entry* remained, so we - // treat it as a simultaneous delete + insert. that means - // advance pos over what used to be here, set len to 0, and - // copy the new data. - flush_copy(oss, pos, len); - pos += isz; - ostringstream ss; - ss << *j; - oss << insn(ss.str()); - } - ++i; ++j; - } - else - { + { + if (i->second == j->second) + { + // this line was copied + len += isz; + } + else + { + // this line was changed, but the *entry* remained, so we + // treat it as a simultaneous delete + insert. that means + // advance pos over what used to be here, set len to 0, and + // copy the new data. + flush_copy(oss, pos, len); + pos += isz; + ostringstream ss; + ss << *j; + oss << insn(ss.str()); + } + ++i; ++j; + } + else + { - flush_copy(oss, pos, len); - - if (i != a.end() && i->first < j->first) - { - // this line was deleted - ++i; - pos += isz; - } - - else - { - // this line was added - ostringstream ss; - ss << *j; - oss << insn(ss.str()); - ++j; - } - } + flush_copy(oss, pos, len); + + if (i != a.end() && i->first < j->first) + { + // this line was deleted + ++i; + pos += isz; + } + + else + { + // this line was added + ostringstream ss; + ss << *j; + oss << insn(ss.str()); + ++j; + } + } } flush_copy(oss,pos,len); @@ -317,8 +317,8 @@ void compute_delta(string const & a, - string const & b, - string & delta) + string const & b, + string & delta) { vector delta_insns; @@ -391,49 +391,49 @@ void apply_delta(boost::shared_ptr da, - std::string const & delta) + std::string const & delta) { istringstream del(delta); for (char c = del.get(); c == 'I' || c == 'C'; c = del.get()) { I(del.good()); if (c == 'I') - { - string::size_type len = string::npos; - del >> len; - I(del.good()); - I(len != string::npos); - string tmp; - tmp.reserve(len); - I(del.get(c).good()); - I(c == '\n'); - while(len--) - { - I(del.get(c).good()); - tmp += c; - } - I(del.get(c).good()); - I(c == '\n'); - da->insert(tmp); - } + { + string::size_type len = string::npos; + del >> len; + I(del.good()); + I(len != string::npos); + string tmp; + tmp.reserve(len); + I(del.get(c).good()); + I(c == '\n'); + while(len--) + { + I(del.get(c).good()); + tmp += c; + } + I(del.get(c).good()); + I(c == '\n'); + da->insert(tmp); + } else - { - string::size_type pos = string::npos, len = string::npos; - del >> pos >> len; - I(del.good()); - I(len != string::npos); - I(del.get(c).good()); - I(c == '\n'); - da->copy(pos, len); - } + { + string::size_type pos = string::npos, len = string::npos; + del >> pos >> len; + I(del.good()); + I(len != string::npos); + I(del.get(c).good()); + I(c == '\n'); + da->copy(pos, len); + } } I(del.eof()); } void apply_delta(string const & a, - string const & delta, - string & b) + string const & delta, + string & b) { boost::shared_ptr da(new simple_applicator()); da->begin(a); @@ -453,7 +453,7 @@ virtual void finish(std::string & out) {} virtual void copy(std::string::size_type pos, - std::string::size_type len) + std::string::size_type len) { sz += len; } virtual void insert(std::string const & str) { sz += str.size(); } @@ -490,8 +490,8 @@ {} chunk subchunk(version_pos vp, - length ln, - length offset) const + length ln, + length offset) const { I(ppos + offset >= ppos); I(ppos + offset + ln <= ppos + len); @@ -533,9 +533,9 @@ { out.clear(); for (version_spec::const_iterator i = in.begin(); - i != in.end(); ++i) - { - append(out, i->piece, i->ppos, i->len); + i != in.end(); ++i) + { + append(out, i->piece, i->ppos, i->len); } } }; @@ -564,7 +564,7 @@ static void apply_copy(version_spec const & in, version_spec & out, - version_pos src_vpos, length src_len) + version_pos src_vpos, length src_len) { // // this is a little tricky because there's *4* different extents @@ -593,9 +593,9 @@ dst_vpos = out.back().vpos + out.back().len; version_pos dst_final = dst_vpos + src_len; version_spec::const_iterator lo = lower_bound(in.begin(), - in.end(), - src_vpos, - chunk_less_than()); + in.end(), + src_vpos, + chunk_less_than()); for ( ; src_len > 0; ++lo) { I(lo != in.end()); @@ -747,12 +747,12 @@ size_t pos = xdelta_sizegen(PRNG) % str.size(); size_t len = xdelta_lengen(PRNG); if (pos+len >= str.size()) - continue; + continue; string tmp; tmp.reserve(len); for (size_t i = 0; i < len; ++i) - tmp += xdelta_chargen(PRNG); - str.insert(pos, tmp); + tmp += xdelta_chargen(PRNG); + str.insert(pos, tmp); nedits--; } } @@ -766,9 +766,9 @@ size_t pos = xdelta_sizegen(PRNG) % str.size(); size_t len = xdelta_lengen(PRNG); if (pos+len >= str.size()) - continue; + continue; for (size_t i = 0; i < len; ++i) - str[pos+i] = xdelta_chargen(PRNG); + str[pos+i] = xdelta_chargen(PRNG); nedits--; } } @@ -782,7 +782,7 @@ size_t pos = xdelta_sizegen(PRNG) % str.size(); size_t len = xdelta_lengen(PRNG); if (pos+len >= str.size()) - continue; + continue; str.erase(pos, len); --nedits; } @@ -802,21 +802,21 @@ compute_delta(a, b, fdel); compute_delta(b, a, rdel); L(F("src %d, dst %d, fdel %d, rdel %d\n") - % a.size() % b.size()% fdel.size() % rdel.size()) ; + % a.size() % b.size()% fdel.size() % rdel.size()) ; if (fdel.size() == 0) - { - L(F("confirming src == dst and rdel == 0\n")); - BOOST_CHECK(a == b); - BOOST_CHECK(rdel.size() == 0); - } + { + L(F("confirming src == dst and rdel == 0\n")); + BOOST_CHECK(a == b); + BOOST_CHECK(rdel.size() == 0); + } else - { - apply_delta(a, fdel, c); - apply_delta(b, rdel, d); - L(F("confirming dst1 %d, dst2 %d\n") % c.size() % d.size()); - BOOST_CHECK(b == c); - BOOST_CHECK(a == d); - } + { + apply_delta(a, fdel, c); + apply_delta(b, rdel, d); + L(F("confirming dst1 %d, dst2 %d\n") % c.size() % d.size()); + BOOST_CHECK(b == c); + BOOST_CHECK(a == d); + } } } --- xdelta.hh +++ xdelta.hh @@ -13,18 +13,18 @@ void compute_delta(std::string const & a, - std::string const & b, - std::string & delta); + std::string const & b, + std::string & delta); void compute_delta(manifest_map const & a, - manifest_map const & b, - std::string & delta); + manifest_map const & b, + std::string & delta); void apply_delta(std::string const & a, - std::string const & delta, - std::string & b); + std::string const & delta, + std::string & b); struct delta_applicator @@ -42,7 +42,7 @@ boost::shared_ptr new_piecewise_applicator(); void apply_delta(boost::shared_ptr da, - std::string const & delta); + std::string const & delta); u64 measure_delta_target_size(std::string const & delta);