monotone

monotone Mtn Source Tree

Root/src/revision.hh

1// Copyright (C) 2004 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __REVISION_HH__
11#define __REVISION_HH__
12
13#include <set>
14#include "vector.hh"
15#include "rev_types.hh"
16
17class key_store;
18class node_restriction;
19class path_restriction;
20
21// a revision is a text object. It has a precise, normalizable serial form
22// as UTF-8 text. it also has some sub-components. not all of these
23// sub-components are separately serialized (they could be but there is no
24// call for it). a grammar (aside from the parsing code) for the serialized
25// form will show up here eventually. until then, here is an example.
26//
27// new_manifest [16afa28e8783987223993d67f54700f0ecfedfaa]
28//
29// old_revision [d023242b16cbdfd46686a5d217af14e3c339f2b4]
30//
31// delete "deleted-file.cc"
32//
33// rename "old-file.cc"
34// to "new-file.cc"
35//
36// add_file "added-file.cc"
37// content [da39a3ee5e6b4b0d3255bfef95601890afd80709]
38//
39// patch "changed-file.cc"
40// from [588fd8a7bcde43a46f0bde1dd1d13e9e77cf25a1]
41// to [559133b166c3154c864f912e9f9452bfc452dfdd]
42//
43// patch "new-file.cc"
44// from [95b50ede90037557fd0fbbfad6a9fdd67b0bf413]
45// to [bd39086b9da776fc22abd45734836e8afb59c8c0]
46
47enum made_for { made_for_nobody, made_for_workspace, made_for_database };
48
49struct
50revision_t : public origin_aware
51{
52 void check_sane() const;
53 bool is_merge_node() const;
54 // trivial revisions are ones that have no effect -- e.g., commit should
55 // refuse to commit them, saying that there are no changes to commit.
56 bool is_nontrivial() const;
57 revision_t() : made_for(made_for_nobody) {}
58 revision_t(revision_t const & other);
59 revision_t const & operator=(revision_t const & other);
60 manifest_id new_manifest;
61 edge_map edges;
62 // workspace::put_work_rev refuses to apply a rev that doesn't have this
63 // set to "workspace", and database::put_revision refuses to apply a rev
64 // that doesn't have it set to "database". the default constructor sets
65 // it to "nobody".
66 enum made_for made_for;
67};
68
69class graph_loader
70{
71 public:
72 graph_loader(database & db) : db(db) {}
73
74 void load_parents(revision_id const rid, std::set<revision_id> & parents);
75 void load_children(revision_id const rid, std::set<revision_id> & children);
76 void load_ancestors(std::set<revision_id> & revs);
77 void load_descendants(std::set<revision_id> & revs);
78
79 private:
80 database & db;
81 enum load_direction { ancestors, descendants };
82
83 void load_revs(load_direction const direction,
84 std::set<revision_id> & revs);
85};
86
87inline revision_id const &
88edge_old_revision(edge_entry const & e)
89{
90 return e.first;
91}
92
93inline revision_id const &
94edge_old_revision(edge_map::const_iterator i)
95{
96 return i->first;
97}
98
99inline cset const &
100edge_changes(edge_entry const & e)
101{
102 return *(e.second);
103}
104
105inline cset const &
106edge_changes(edge_map::const_iterator i)
107{
108 return *(i->second);
109}
110
111template <> void
112dump(revision_t const & rev, std::string & out);
113
114void
115read_revision(data const & dat,
116 revision_t & rev);
117
118void
119read_revision(revision_data const & dat,
120 revision_t & rev);
121
122void
123write_revision(revision_t const & rev,
124 data & dat);
125
126void
127write_revision(revision_t const & rev,
128 revision_data & dat);
129
130void calculate_ident(revision_t const & cs,
131 revision_id & ident);
132
133// sanity checking
134
135void
136find_common_ancestor_for_merge(database & db,
137 revision_id const & left,
138 revision_id const & right,
139 revision_id & anc);
140
141bool
142is_ancestor(database & db, revision_id const & ancestor,
143 revision_id const & descendent);
144
145void
146toposort(database & db,
147 std::set<revision_id> const & revisions,
148 std::vector<revision_id> & sorted);
149
150void
151erase_ancestors(database & db, std::set<revision_id> & revisions);
152
153struct is_failure
154{
155 virtual bool operator()(revision_id const & rid) = 0;
156 virtual ~is_failure() {};
157};
158void
159erase_ancestors_and_failures(database & db,
160 std::set<revision_id> & revisions,
161 is_failure & p,
162 std::multimap<revision_id, revision_id> *inverse_graph_cache_ptr = NULL);
163
164void
165erase_descendants(database & db, std::set<revision_id> & revisions);
166
167void
168erase_descendants_and_failures(database & db,
169 std::set<revision_id> & revisions,
170 is_failure & p,
171 std::multimap<revision_id, revision_id> *inverse_graph_cache_ptr = NULL);
172
173void
174ancestry_difference(database & db, revision_id const & a,
175 std::set<revision_id> const & bs,
176 std::set<revision_id> & new_stuff);
177
178
179// FIXME: can probably optimize this passing a lookaside cache of the active
180// frontier set of shared_ptr<roster_t>s, while traversing history.
181void
182select_nodes_modified_by_rev(database & db,
183 revision_t const & rev,
184 roster_t const roster,
185 std::set<node_id> & nodes_modified);
186
187void
188make_revision(revision_id const & old_rev_id,
189 roster_t const & old_roster,
190 roster_t const & new_roster,
191 revision_t & rev);
192
193void
194make_revision(parent_map const & old_rosters,
195 roster_t const & new_roster,
196 revision_t & rev);
197
198// This overload takes a base roster and a changeset instead.
199void
200make_revision(revision_id const & old_rev_id,
201 roster_t const & old_roster,
202 cset const & changes,
203 revision_t & rev);
204
205// These functions produce a faked "new_manifest" id and discard all
206// content-only changes from the cset. They are only to be used to
207// construct a revision that will be written to the workspace. Don't use
208// them for revisions written to the database or presented to the user.
209void
210make_revision_for_workspace(revision_id const & old_rev_id,
211 cset const & changes,
212 revision_t & rev);
213
214void
215make_revision_for_workspace(revision_id const & old_rev_id,
216 roster_t const & old_roster,
217 roster_t const & new_roster,
218 revision_t & rev);
219
220void
221make_revision_for_workspace(parent_map const & old_rosters,
222 roster_t const & new_roster,
223 revision_t & rev);
224
225void
226make_restricted_revision(parent_map const & old_rosters,
227 roster_t const & new_roster,
228 node_restriction const & mask,
229 revision_t & rev);
230
231void
232make_restricted_revision(parent_map const & old_rosters,
233 roster_t const & new_roster,
234 node_restriction const & mask,
235 revision_t & rev,
236 cset & excluded,
237 utf8 const & cmd_name);
238
239// basic_io access to printers and parsers
240void
241print_revision(basic_io::printer & printer,
242 revision_t const & rev);
243
244void
245parse_revision(basic_io::parser & parser,
246 revision_t & rev);
247
248void
249print_edge(basic_io::printer & printer,
250 edge_entry const & e);
251
252void
253parse_edge(basic_io::parser & parser,
254 edge_map & es);
255
256#endif // __REVISION_HH__
257
258// Local Variables:
259// mode: C++
260// fill-column: 76
261// c-file-style: "gnu"
262// indent-tabs-mode: nil
263// End:
264// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status