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
54struct
55revision_t
56{
57 void check_sane() const;
58 bool is_merge_node() const;
59 // trivial revisions are ones that have no effect -- e.g., commit should
60 // refuse to commit them, saying that there are no changes to commit.
61 bool is_nontrivial() const;
62 revision_t() {}
63 revision_t(revision_t const & other);
64 revision_t const & operator=(revision_t const & other);
65 manifest_id new_manifest;
66 edge_map edges;
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(revision_id const & left,
119 revision_id const & right,
120 revision_id & anc,
121 app_state & app);
122
123bool
124is_ancestor(revision_id const & ancestor,
125 revision_id const & descendent,
126 app_state & app);
127
128void
129toposort(std::set<revision_id> const & revisions,
130 std::vector<revision_id> & sorted,
131 app_state & app);
132
133void
134erase_ancestors(std::set<revision_id> & revisions, app_state & app);
135
136void
137ancestry_difference(revision_id const & a, std::set<revision_id> const & bs,
138 std::set<revision_id> & new_stuff,
139 app_state & app);
140
141
142// FIXME: can probably optimize this passing a lookaside cache of the active
143// frontier set of shared_ptr<roster_t>s, while traversing history.
144void
145select_nodes_modified_by_rev(revision_id const & rid,
146 revision_t const & rev,
147 roster_t const roster,
148 std::set<node_id> & nodes_modified,
149 app_state & app);
150
151void
152make_revision(revision_id const & old_rev_id,
153 roster_t const & old_roster,
154 roster_t const & new_roster,
155 revision_t & rev);
156
157/*
158void
159calculate_composite_cset(revision_id const & ancestor,
160 revision_id const & child,
161 app_state & app,
162 cset & composed);
163
164void
165calculate_arbitrary_cset(revision_id const & start,
166 revision_id const & end,
167 app_state & app,
168 cset & composed);
169
170*/
171
172void
173build_changesets_from_manifest_ancestry(app_state & app);
174
175void
176build_roster_style_revs_from_manifest_style_revs(app_state & app);
177
178// basic_io access to printers and parsers
179
180namespace basic_io { struct printer; struct parser; }
181
182void
183print_revision(basic_io::printer & printer,
184 revision_t const & rev);
185
186void
187parse_revision(basic_io::parser & parser,
188 revision_t & rev);
189
190void
191print_edge(basic_io::printer & printer,
192 edge_entry const & e);
193
194void
195parse_edge(basic_io::parser & parser,
196 edge_map & es);
197
198// Local Variables:
199// mode: C++
200// fill-column: 76
201// c-file-style: "gnu"
202// indent-tabs-mode: nil
203// End:
204// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
205
206#endif // __REVISION_HH__

Archive Download this file

Branches

Tags

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