# # # patch "database.cc" # from [a65fbb52f8ad90194b9c195ee5e3c16e2113e5e9] # to [cac4ab9d4b50bd45c5888e84619bc6f342570367] # # patch "project.cc" # from [106438500b4c6e9b1c2a742180557ca6c8f14840] # to [3a69d5eebcacb3ab5625a49dc98edf9979e7b46c] # # patch "project.hh" # from [a37c5c9c535fdf22e8a41c3c4ef1cb8b8d8a12e0] # to [3a2f56c73b1467f8c3b8c6be8800f741d3a7430e] # # patch "rev_height.cc" # from [82e46ae37bc2d01fa172d30bdf262e2479b8c185] # to [4c461f499aa31bdb99de01284ef879055eae47b4] # # patch "rev_height.hh" # from [1317c1deae79d292e794943a64a604c22e008122] # to [cd31dbcb051c6a2181c971654f34ededb32a70c5] # # patch "revision.hh" # from [13ef420b76868de35dca3208102304daa2d4593e] # to [b11a0ac769526e664b296e1ac9e71f1dd0ff01c8] # # patch "schema_migration.cc" # from [703c3ecf0e220921ef5165203a1f561fb71ac875] # to [9ae3618fcf9b145df665c4a8e1bbb1d09e85d7b0] # ============================================================ --- database.cc a65fbb52f8ad90194b9c195ee5e3c16e2113e5e9 +++ database.cc cac4ab9d4b50bd45c5888e84619bc6f342570367 @@ -1736,7 +1736,7 @@ database::get_rev_height(revision_id con { if (null_id(id)) { - rev_height::root_height(height); + height = rev_height::root_height(); return; } @@ -1747,7 +1747,8 @@ database::get_rev_height(revision_id con I(res.size() == 1); - height.from_string(res[0][0]); + height = rev_height(res[0][0]); + I(height.valid()); } void @@ -1756,6 +1757,7 @@ database::put_rev_height(revision_id con { I(!null_id(id)); I(revision_exists(id)); + !(height.valid()); execute(query("INSERT INTO heights VALUES(?, ?)") % text(id.inner()()) @@ -1890,7 +1892,7 @@ database::put_height_for_revision(revisi while(!found) { - parent.child_height(candidate, childnr); + candidate = parent.child_height(childnr); if (!has_rev_height(candidate)) { found = true; ============================================================ --- project.cc 106438500b4c6e9b1c2a742180557ca6c8f14840 +++ project.cc 3a69d5eebcacb3ab5625a49dc98edf9979e7b46c @@ -12,7 +12,7 @@ #include - +using std::string; using std::set; using std::vector; ============================================================ --- project.hh a37c5c9c535fdf22e8a41c3c4ef1cb8b8d8a12e0 +++ project.hh 3a2f56c73b1467f8c3b8c6be8800f741d3a7430e @@ -6,6 +6,7 @@ #include #include +#include #include "cert.hh" #include "outdated_indicator.hh" @@ -49,7 +50,7 @@ public: void get_branch_heads(utf8 const & name, std::set & heads); outdated_indicator get_tags(std::set & tags); - void put_tag(revision_id const & id, string const & name, packet_consumer & pc); + void put_tag(revision_id const & id, std::string const & name, packet_consumer & pc); bool revision_is_in_branch(revision_id const & id, utf8 const & branch); void put_revision_in_branch(revision_id const & id, ============================================================ --- rev_height.cc 82e46ae37bc2d01fa172d30bdf262e2479b8c185 +++ rev_height.cc 4c461f499aa31bdb99de01284ef879055eae47b4 @@ -7,12 +7,9 @@ // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. -#include -#include #include #include -#include "numeric_vocab.hh" #include "sanity.hh" #include "rev_height.hh" @@ -35,18 +32,7 @@ using std::memcmp; * */ -rev_height::rev_height() {} - -rev_height::rev_height(rev_height const & other) -{ - d = other.d; -} - -void rev_height::from_string(string const & s) -{ - d = s; -} - +// Comparisons bool rev_height::operator==(rev_height const & other) const { if (d.size() != other.d.size()) @@ -58,22 +44,18 @@ bool rev_height::operator<(rev_height co bool rev_height::operator<(rev_height const & other) const { - if (d.size() == other.d.size()) - return (memcmp(d.data(), other.d.data(), d.size()) < 0); - - if (d.size() < other.d.size()) - return (memcmp(d.data(), other.d.data(), d.size()) <= 0); - - // d.size() > other.d.size() - return (memcmp(d.data(), other.d.data(), other.d.size()) < 0); + int o = memcmp(d.data(), other.d.data(), + std::min(d.size(), other.d.size())); + if (o != 0) + return o < 0; + else + return d.size() < other.d.size(); } -string const & rev_height::operator()() const -{ - return d; -} +// Internal manipulations +size_t const width = sizeof(u32); -u32 rev_height::read_at(size_t pos) const +static u32 read_at(string const & d, size_t pos) { u32 value = 0; size_t first = width * pos; @@ -87,7 +69,7 @@ u32 rev_height::read_at(size_t pos) cons return value; } -void rev_height::write_at(size_t pos, u32 value) +static void write_at(string & d, size_t pos, u32 value) { size_t first = width * pos; for (size_t i = first + width ; i > first;) @@ -97,55 +79,50 @@ void rev_height::write_at(size_t pos, u3 } } -void rev_height::append(u32 value) +static void append(string & d, u32 value) { d.resize(d.size() + width); // make room - write_at(size() - 1, value); + write_at(d, d.size() - width, value); } -void rev_height::clear() +// Creating derived heights +rev_height rev_height::child_height(u32 nr) const { - d.clear(); -} + string child = d; -size_t rev_height::size() const -{ - return d.size() / width; -} - -void rev_height::child_height(rev_height & child, u32 nr) const -{ - child.from_string(d); - if (nr == 0) { - size_t pos = size() - 1; - u32 tmp = read_at(pos); + size_t pos = child.size() / width - 1; + u32 tmp = read_at(child, pos); I(tmp < std::numeric_limits::max()); - child.write_at(pos, tmp + 1); + write_at(child, pos, tmp + 1); } else { - child.append(nr - 1); - child.append(0); + append(child, nr - 1); + append(child, 0); } + return rev_height(child); } -void rev_height::root_height(rev_height & root) +rev_height rev_height::root_height() { - root.clear(); - root.append(0); + string root; + append(root, 0); + return rev_height(root); } +// Human-readable output ostream & operator <<(ostream & os, rev_height const & h) { bool first(true); + string const & d(h()); - for (size_t i = 0; i < h.size(); ++i) + for (size_t i = 0; i < d.size() / width; ++i) { if (!first) os << '.'; - os << h.read_at(i); + os << read_at(d, i); first = false; } return os; @@ -166,4 +143,3 @@ void dump(rev_height const & h, string & // indent-tabs-mode: nil // End: // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: - ============================================================ --- rev_height.hh 1317c1deae79d292e794943a64a604c22e008122 +++ rev_height.hh cd31dbcb051c6a2181c971654f34ededb32a70c5 @@ -10,58 +10,51 @@ // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. -#include +#include #include #include "numeric_vocab.hh" -using std::ostream; -using std::string; - - class rev_height { - string d; - static size_t const width = sizeof(u32); - u32 read_at(size_t pos) const; - void write_at(size_t pos, u32 val); - void append(u32 val); - size_t size() const; - void clear(); + std::string d; + public: - rev_height(); - rev_height(rev_height const & other); - void from_string(string const & s); - string const & operator()() const; - void child_height(rev_height & child, u32 nr) const; - static void root_height(rev_height & root); + rev_height() : d() {} + rev_height(rev_height const & other) : d(other.d) {} + explicit rev_height(std::string const & s) : d(s) {} + std::string const & operator()() const { return d; } + rev_height child_height(u32 nr) const; + static rev_height root_height(); + + bool valid() const { return d.size() > 0; } + bool operator ==(rev_height const & other) const; bool operator < (rev_height const & other) const; - inline bool operator !=(rev_height const & other) const + bool operator !=(rev_height const & other) const { return !(*this == other); } - inline bool operator > (rev_height const & other) const + bool operator > (rev_height const & other) const { return other < *this; } - inline bool operator <=(rev_height const & other) const + bool operator <=(rev_height const & other) const { return !(other < *this); } - inline bool operator >=(rev_height const & other) const + bool operator >=(rev_height const & other) const { return !(*this < other); } - friend ostream & operator <<(ostream & os, rev_height const & h); }; -void dump(rev_height const & h, string & out); +std::ostream & operator <<(std::ostream & os, rev_height const & h); +void dump(rev_height const & h, std::string & out); #endif // __REV_HEIGHT_HH_ - // Local Variables: // mode: C++ // fill-column: 76 @@ -69,4 +62,3 @@ void dump(rev_height const & h, string & // indent-tabs-mode: nil // End: // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: - ============================================================ --- revision.hh 13ef420b76868de35dca3208102304daa2d4593e +++ revision.hh b11a0ac769526e664b296e1ac9e71f1dd0ff01c8 @@ -214,7 +214,7 @@ make_restricted_revision(parent_map cons node_restriction const & mask, revision_t & rev, cset & excluded, - string const & cmd_name); + std::string const & cmd_name); void build_changesets_from_manifest_ancestry(app_state & app); ============================================================ --- schema_migration.cc 703c3ecf0e220921ef5165203a1f561fb71ac875 +++ schema_migration.cc 9ae3618fcf9b145df665c4a8e1bbb1d09e85d7b0 @@ -18,6 +18,8 @@ #include "transforms.hh" #include "ui.hh" +using std::string; + // this file knows how to migrate schema databases. the general strategy is // to hash each schema we ever use, and make a list of the SQL commands // required to get from one hash value to the next. when you do a