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 "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
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
69inline revision_id const &
70edge_old_revision(edge_entry const & e)
71{
72 return e.first;
73}
74
75inline revision_id const &
76edge_old_revision(edge_map::const_iterator i)
77{
78 return i->first;
79}
80
81inline cset const &
82edge_changes(edge_entry const & e)
83{
84 return *(e.second);
85}
86
87inline cset const &
88edge_changes(edge_map::const_iterator i)
89{
90 return *(i->second);
91}
92
93template <> void
94dump(revision_t const & rev, std::string & out);
95
96void
97read_revision(data const & dat,
98 revision_t & rev);
99
100void
101read_revision(revision_data const & dat,
102 revision_t & rev);
103
104void
105write_revision(revision_t const & rev,
106 data & dat);
107
108void
109write_revision(revision_t const & rev,
110 revision_data & dat);
111
112void calculate_ident(revision_t const & cs,
113 revision_id & ident);
114
115// sanity checking
116
117void
118find_common_ancestor_for_merge(database & db,
119 revision_id const & left,
120 revision_id const & right,
121 revision_id & anc);
122
123bool
124is_ancestor(database & db, revision_id const & ancestor,
125 revision_id const & descendent);
126
127void
128toposort(database & db,
129 std::set<revision_id> const & revisions,
130 std::vector<revision_id> & sorted);
131
132void
133erase_ancestors(database & db, std::set<revision_id> & revisions);
134
135struct is_failure
136{
137 virtual bool operator()(revision_id const & rid) = 0;
138 virtual ~is_failure() {};
139};
140void
141erase_ancestors_and_failures(database & db,
142 std::set<revision_id> & revisions,
143 is_failure & p,
144 std::multimap<revision_id, revision_id> *inverse_graph_cache_ptr = NULL);
145
146void
147ancestry_difference(database & db, revision_id const & a,
148 std::set<revision_id> const & bs,
149 std::set<revision_id> & new_stuff);
150
151
152// FIXME: can probably optimize this passing a lookaside cache of the active
153// frontier set of shared_ptr<roster_t>s, while traversing history.
154void
155select_nodes_modified_by_rev(database & db,
156 revision_t const & rev,
157 roster_t const roster,
158 std::set<node_id> & nodes_modified);
159
160void
161make_revision(revision_id const & old_rev_id,
162 roster_t const & old_roster,
163 roster_t const & new_roster,
164 revision_t & rev);
165
166void
167make_revision(parent_map const & old_rosters,
168 roster_t const & new_roster,
169 revision_t & rev);
170
171// This overload takes a base roster and a changeset instead.
172void
173make_revision(revision_id const & old_rev_id,
174 roster_t const & old_roster,
175 cset const & changes,
176 revision_t & rev);
177
178// These functions produce a faked "new_manifest" id and discard all
179// content-only changes from the cset. They are only to be used to
180// construct a revision that will be written to the workspace. Don't use
181// them for revisions written to the database or presented to the user.
182void
183make_revision_for_workspace(revision_id const & old_rev_id,
184 cset const & changes,
185 revision_t & rev);
186
187void
188make_revision_for_workspace(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_for_workspace(parent_map const & old_rosters,
195 roster_t const & new_roster,
196 revision_t & rev);
197
198void
199make_restricted_revision(parent_map const & old_rosters,
200 roster_t const & new_roster,
201 node_restriction const & mask,
202 revision_t & rev);
203
204void
205make_restricted_revision(parent_map const & old_rosters,
206 roster_t const & new_roster,
207 node_restriction const & mask,
208 revision_t & rev,
209 cset & excluded,
210 utf8 const & cmd_name);
211
212void
213build_changesets_from_manifest_ancestry(database & db, key_store & keys,
214 std::set<std::string> const & attrs_to_drop);
215
216void
217build_roster_style_revs_from_manifest_style_revs(database & db, key_store & keys,
218 std::set<std::string> const & attrs_to_drop);
219
220void
221regenerate_caches(database & db);
222
223// basic_io access to printers and parsers
224void
225print_revision(basic_io::printer & printer,
226 revision_t const & rev);
227
228void
229parse_revision(basic_io::parser & parser,
230 revision_t & rev);
231
232void
233print_edge(basic_io::printer & printer,
234 edge_entry const & e);
235
236void
237parse_edge(basic_io::parser & parser,
238 edge_map & es);
239
240// Local Variables:
241// mode: C++
242// fill-column: 76
243// c-file-style: "gnu"
244// indent-tabs-mode: nil
245// End:
246// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
247
248#endif // __REVISION_HH__

Archive Download this file

Branches

Tags

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