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 file_path const &
81delta_entry_path(change_set::delta_map::const_iterator i)
82{
83 return i->first;
84}
85
86inline file_id const &
87delta_entry_src(change_set::delta_map::const_iterator i)
88{
89 return i->second.first;
90}
91
92inline file_id const &
93delta_entry_dst(change_set::delta_map::const_iterator i)
94{
95 return i->second.second;
96}
97
98void
99apply_rearrangement_to_filesystem(change_set::path_rearrangement const & re,
100 bookkeeping_path const & temporary_root);
101
102
103// merging and concatenating
104
105void
106normalize_change_set(change_set & n);
107
108void
109normalize_path_rearrangement(change_set::path_rearrangement & n);
110
111void
112concatenate_rearrangements(change_set::path_rearrangement const & a,
113 change_set::path_rearrangement const & b,
114 change_set::path_rearrangement & concatenated);
115
116void
117concatenate_change_sets(change_set const & a,
118 change_set const & b,
119 change_set & concatenated);
120
121struct merge_provider;
122
123void
124merge_change_sets(change_set const & a,
125 change_set const & b,
126 change_set & a_merged,
127 change_set & b_merged,
128 merge_provider & merger,
129 app_state & app);
130
131// value-oriented access to printers and parsers
132
133void
134read_path_rearrangement(data const & dat,
135 change_set::path_rearrangement & re);
136
137void
138write_path_rearrangement(change_set::path_rearrangement const & re,
139 data & dat);
140
141void
142read_change_set(data const & dat,
143 change_set & cs);
144
145void
146write_change_set(change_set const & cs,
147 data & dat);
148
149void
150apply_path_rearrangement(path_set const & old_ps,
151 change_set::path_rearrangement const & pr,
152 path_set & new_ps);
153
154void
155complete_change_set(manifest_map const & m_old,
156 manifest_map const & m_new,
157 change_set & cs);
158
159void
160build_pure_addition_change_set(manifest_map const & man,
161 change_set & cs);
162
163void
164apply_change_set(manifest_map const & old_man,
165 change_set const & cs,
166 manifest_map & new_man);
167
168// quick, optimistic and destructive versions
169
170void
171apply_path_rearrangement(change_set::path_rearrangement const & pr,
172 path_set & ps);
173
174file_path
175apply_change_set_inverse(change_set const & cs,
176 file_path const & file_in_second);
177
178void
179apply_change_set(change_set const & cs,
180 manifest_map & man);
181
182void
183invert_change_set(change_set const & a2b,
184 manifest_map const & a_map,
185 change_set & b2a);
186
187
188// basic_io access to printers and parsers
189
190namespace basic_io { struct printer; struct parser; }
191
192void
193print_change_set(basic_io::printer & printer,
194 change_set const & cs);
195
196void
197parse_change_set(basic_io::parser & parser,
198 change_set & cs);
199
200void
201print_path_rearrangement(basic_io::printer & basic_printer,
202 change_set::path_rearrangement const & pr);
203
204void
205parse_path_rearrangement(basic_io::parser & pa,
206 change_set::path_rearrangement & pr);
207
208// debugging
209
210void dump(change_set const & cs, std::string & out);
211
212#endif // __CHANGE_SET_HH__

Archive Download this file

Branches

Tags

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