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

Archive Download this file

Branches

Tags

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