monotone

monotone Mtn Source Tree

Root/change_set.hh

1#ifndef __CHANGE_SET_HH__
2#define __CHANGE_SET_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 <map>
10#include <string>
11
12#include <boost/shared_ptr.hpp>
13
14#include "interner.hh"
15#include "manifest.hh"
16#include "vocab.hh"
17
18// a change_set is a text object. It has a precise, normalizable serial form
19// as UTF-8 text.
20//
21// note that this object is made up of two important sub-components:
22// path_edits and deltas. "path_edits" is exactly the same object stored
23// in MT/work.
24
25struct
26change_set
27{
28
29 typedef std::map<file_path, std::pair<file_id, file_id> > delta_map;
30
31 struct
32 path_rearrangement
33 {
34 std::set<file_path> deleted_files;
35 std::set<file_path> deleted_dirs;
36 std::map<file_path, file_path> renamed_files;
37 std::map<file_path, file_path> renamed_dirs;
38 std::set<file_path> added_files;
39
40 path_rearrangement() {}
41 path_rearrangement(path_rearrangement const & other);
42 path_rearrangement const & operator=(path_rearrangement const & other);
43 bool operator==(path_rearrangement const & other) const;
44 bool empty() const;
45 void check_sane() const;
46 void check_sane(delta_map const &) const;
47
48 bool has_added_file(file_path const & file) const;
49 bool has_deleted_file(file_path const & file) const;
50 bool has_renamed_file_dst(file_path const & file) const;
51 bool has_renamed_file_src(file_path const & file) const;
52 };
53
54 path_rearrangement rearrangement;
55 delta_map deltas;
56
57 change_set() {}
58 change_set(change_set const & other);
59 change_set const &operator=(change_set const & other);
60 bool operator==(change_set const & other) const;
61 void check_sane() const;
62 bool empty() const;
63 void add_file(file_path const & a);
64 void add_file(file_path const & a, file_id const & ident);
65 void apply_delta(file_path const & path,
66 file_id const & src,
67 file_id const & dst);
68 void delete_file(file_path const & d);
69 void delete_dir(file_path const & d);
70 void rename_file(file_path const & a, file_path const & b);
71 void rename_dir(file_path const & a, file_path const & b);
72};
73
74inline bool
75null_name(file_path const & p)
76{
77 return p.empty();
78}
79
80inline bool
81null_id(file_id const & i)
82{
83 return i.inner()().empty();
84}
85
86inline bool
87null_id(manifest_id const & i)
88{
89 return i.inner()().empty();
90}
91
92inline bool
93null_id(revision_id const & i)
94{
95 return i.inner()().empty();
96}
97
98inline file_path const &
99delta_entry_path(change_set::delta_map::const_iterator i)
100{
101 return i->first;
102}
103
104inline file_id const &
105delta_entry_src(change_set::delta_map::const_iterator i)
106{
107 return i->second.first;
108}
109
110inline file_id const &
111delta_entry_dst(change_set::delta_map::const_iterator i)
112{
113 return i->second.second;
114}
115
116void
117apply_rearrangement_to_filesystem(change_set::path_rearrangement const & re,
118 bookkeeping_path const & temporary_root);
119
120
121// merging and concatenating
122
123void
124normalize_change_set(change_set & n);
125
126void
127normalize_path_rearrangement(change_set::path_rearrangement & n);
128
129void
130concatenate_rearrangements(change_set::path_rearrangement const & a,
131 change_set::path_rearrangement const & b,
132 change_set::path_rearrangement & concatenated);
133
134void
135concatenate_change_sets(change_set const & a,
136 change_set const & b,
137 change_set & concatenated);
138
139struct merge_provider;
140
141void
142merge_change_sets(change_set const & a,
143 change_set const & b,
144 change_set & a_merged,
145 change_set & b_merged,
146 merge_provider & merger,
147 app_state & app);
148
149// value-oriented access to printers and parsers
150
151void
152read_path_rearrangement(data const & dat,
153 change_set::path_rearrangement & re);
154
155void
156write_path_rearrangement(change_set::path_rearrangement const & re,
157 data & dat);
158
159void
160read_change_set(data const & dat,
161 change_set & cs);
162
163void
164write_change_set(change_set const & cs,
165 data & dat);
166
167void
168apply_path_rearrangement(path_set const & old_ps,
169 change_set::path_rearrangement const & pr,
170 path_set & new_ps);
171
172void
173complete_change_set(manifest_map const & m_old,
174 manifest_map const & m_new,
175 change_set & cs);
176
177void
178build_pure_addition_change_set(manifest_map const & man,
179 change_set & cs);
180
181void
182apply_change_set(manifest_map const & old_man,
183 change_set const & cs,
184 manifest_map & new_man);
185
186// quick, optimistic and destructive versions
187
188void
189apply_path_rearrangement(change_set::path_rearrangement const & pr,
190 path_set & ps);
191
192file_path
193apply_change_set_inverse(change_set const & cs,
194 file_path const & file_in_second);
195
196void
197apply_change_set(change_set const & cs,
198 manifest_map & man);
199
200void
201invert_change_set(change_set const & a2b,
202 manifest_map const & a_map,
203 change_set & b2a);
204
205
206// basic_io access to printers and parsers
207
208namespace basic_io { struct printer; struct parser; }
209
210void
211print_change_set(basic_io::printer & printer,
212 change_set const & cs);
213
214void
215parse_change_set(basic_io::parser & parser,
216 change_set & cs);
217
218void
219print_path_rearrangement(basic_io::printer & basic_printer,
220 change_set::path_rearrangement const & pr);
221
222void
223parse_path_rearrangement(basic_io::parser & pa,
224 change_set::path_rearrangement & pr);
225
226// debugging
227
228void dump(change_set const & cs, std::string & out);
229
230#endif // __CHANGE_SET_HH__

Archive Download this file

Branches

Tags

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