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// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <set>
10#include <string>
11
12#include <boost/shared_ptr.hpp>
13
14#include "app_state.hh"
15#include "change_set.hh"
16#include "vocab.hh"
17
18// a revision is a text object. It has a precise, normalizable serial form
19// as UTF-8 text. it also has some sub-components. not all of these
20// sub-components are separately serialized (they could be but there is no
21// call for it). a grammar (aside from the parsing code) for the serialized
22// form will show up here eventually. until then, here is an example.
23//
24// revision:
25// {
26// new_manifest: [71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc]
27// edge:
28// {
29// old_revision: [71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc]
30// old_manifest: [71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc]
31// change_set:
32// {
33// paths:
34// {
35// rename_file:
36// {
37// src: "usr/bin/sh"
38// dst: "usr/bin/foo"
39// }
40// delete_dir: "usr/bin"
41// add_file: "tmp/foo/bar.txt"
42// }
43// deltas:
44// {
45// delta:
46// {
47// path: "tmp/foo/bar.txt"
48// src: [71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc]
49// dst: [71e0274f16cd68bdf9a2bf5743b86fcc1e597cdc]
50// }
51// }
52// }
53// }
54
55extern std::string revision_file_name;
56
57typedef std::map<revision_id, std::pair<manifest_id, boost::shared_ptr<change_set> > >
58edge_map;
59
60typedef edge_map::value_type
61edge_entry;
62
63struct
64revision_set
65{
66 void check_sane() const;
67 revision_set() {}
68 revision_set(revision_set const & other);
69 revision_set const & operator=(revision_set const & other);
70 manifest_id new_manifest;
71 edge_map edges;
72};
73
74inline revision_id const &
75edge_old_revision(edge_entry const & e)
76{
77 return e.first;
78}
79
80inline revision_id const &
81edge_old_revision(edge_map::const_iterator i)
82{
83 return i->first;
84}
85
86inline manifest_id const &
87edge_old_manifest(edge_entry const & e)
88{
89 return e.second.first;
90}
91
92inline manifest_id const &
93edge_old_manifest(edge_map::const_iterator i)
94{
95 return i->second.first;
96}
97
98inline change_set const &
99edge_changes(edge_entry const & e)
100{
101 return *(e.second.second);
102}
103
104inline change_set const &
105edge_changes(edge_map::const_iterator i)
106{
107 return *(i->second.second);
108}
109
110void
111read_revision_set(data const & dat,
112 revision_set & rev);
113
114void
115read_revision_set(revision_data const & dat,
116 revision_set & rev);
117
118void
119write_revision_set(revision_set const & rev,
120 data & dat);
121
122void
123write_revision_set(revision_set const & rev,
124 revision_data & dat);
125
126// sanity checking
127
128void
129check_sane_history(revision_id const & child_id, int depth, app_state & app);
130
131// graph walking
132
133bool
134find_common_ancestor_for_merge(revision_id const & left,
135 revision_id const & right,
136 revision_id & anc,
137 app_state & app);
138
139bool
140find_least_common_ancestor(revision_id const & left,
141 revision_id const & right,
142 revision_id & anc,
143 app_state & app);
144
145bool
146is_ancestor(revision_id const & ancestor,
147 revision_id const & descendent,
148 app_state & app);
149
150void
151toposort(std::set<revision_id> const & revisions,
152 std::vector<revision_id> & sorted,
153 app_state & app);
154
155void
156erase_ancestors(std::set<revision_id> & revisions, app_state & app);
157
158void
159ancestry_difference(revision_id const & a, std::set<revision_id> const & bs,
160 std::set<revision_id> & new_stuff,
161 app_state & app);
162
163void
164calculate_composite_change_set(revision_id const & ancestor,
165 revision_id const & child,
166 app_state & app,
167 change_set & composed);
168
169void
170calculate_arbitrary_change_set(revision_id const & start,
171 revision_id const & end,
172 app_state & app,
173 change_set & composed);
174
175void
176build_changesets_from_manifest_ancestry(app_state & app);
177
178void
179build_changesets_from_existing_revs(app_state & app);
180
181// basic_io access to printers and parsers
182
183namespace basic_io { struct printer; struct parser; }
184
185void
186print_revision(basic_io::printer & printer,
187 revision_set const & rev);
188
189void
190parse_revision(basic_io::parser & parser,
191 revision_set & rev);
192
193void
194print_edge(basic_io::printer & printer,
195 edge_entry const & e);
196
197void
198parse_edge(basic_io::parser & parser,
199 edge_map & es);
200
201#endif // __REVISION_HH__

Archive Download this file

Branches

Tags

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