monotone

monotone Mtn Source Tree

Root/revision.hh

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

Archive Download this file

Branches

Tags

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