-
Notifications
You must be signed in to change notification settings - Fork 6
/
diff_patch.hh
252 lines (212 loc) · 8.79 KB
/
diff_patch.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef __DIFF_PATCH_HH__
#define __DIFF_PATCH_HH__
// Copyright (C) 2008 Stephen Leake <[email protected]>
// Copyright (C) 2002 Graydon Hoare <[email protected]>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.
#include "rev_types.hh"
// XXX needed for gcc 3.3 which will otherwise complain that struct file_path
// is just a forward in rev_types.hh and therefor leads to an incomplete type
#include "paths.hh"
class database;
class lua_hooks;
struct conflict {};
// this file is to contain some stripped down, in-process implementations
// of GNU-diffutils-like things (diff, diff3, maybe patch..)
void make_diff(std::string const & filename1,
std::string const & filename2,
file_id const & id1,
file_id const & id2,
data const & data1,
data const & data2,
std::ostream & ost,
diff_type type,
std::string const & pattern);
bool merge3(std::vector<std::string> const & ancestor,
std::vector<std::string> const & left,
std::vector<std::string> const & right,
std::vector<std::string> & merged);
struct
content_merge_adaptor
{
virtual void record_merge(file_id const & left_ident,
file_id const & right_ident,
file_id const & merged_ident,
file_data const & left_data,
file_data const & right_data,
file_data const & merged_data) = 0;
// For use when one side of the merge is dropped
virtual void record_file(file_id const & parent_ident,
file_id const & merged_ident,
file_data const & parent_data,
file_data const & merged_data) = 0;
virtual void get_ancestral_roster(node_id nid,
revision_id & rid,
boost::shared_ptr<roster_t const> & anc) = 0;
virtual void get_version(file_id const & ident,
file_data & dat) const = 0;
virtual ~content_merge_adaptor() {}
};
struct
content_merge_database_adaptor
: public content_merge_adaptor
{
database & db;
revision_id lca;
revision_id left_rid;
revision_id right_rid;
marking_map const & left_mm;
marking_map const & right_mm;
std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
content_merge_database_adaptor(database & db,
revision_id const & left,
revision_id const & right,
marking_map const & left_mm,
marking_map const & right_mm);
void record_merge(file_id const & left_ident,
file_id const & right_ident,
file_id const & merged_ident,
file_data const & left_data,
file_data const & right_data,
file_data const & merged_data);
void record_file(file_id const & parent_ident,
file_id const & merged_ident,
file_data const & parent_data,
file_data const & merged_data);
void cache_roster(revision_id const & rid,
boost::shared_ptr<roster_t const> roster);
void get_ancestral_roster(node_id nid,
revision_id & rid,
boost::shared_ptr<roster_t const> & anc);
void get_version(file_id const & ident,
file_data & dat) const;
};
struct
content_merge_workspace_adaptor
: public content_merge_adaptor
{
std::map<file_id, file_data> temporary_store;
database & db;
revision_id const lca;
boost::shared_ptr<roster_t const> base;
marking_map const & left_mm;
marking_map const & right_mm;
std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
std::map<file_id, file_path> content_paths;
content_merge_workspace_adaptor(database & db,
revision_id const & lca,
boost::shared_ptr<roster_t const> base,
marking_map const & left_mm,
marking_map const & right_mm,
std::map<file_id, file_path> const & paths)
: db(db), lca(lca), base(base),
left_mm(left_mm), right_mm(right_mm), content_paths(paths)
{}
void cache_roster(revision_id const & rid,
boost::shared_ptr<roster_t const> roster);
void record_merge(file_id const & left_ident,
file_id const & right_ident,
file_id const & merged_ident,
file_data const & left_data,
file_data const & right_data,
file_data const & merged_data);
void record_file(file_id const & parent_ident,
file_id const & merged_ident,
file_data const & parent_data,
file_data const & merged_data);
void get_ancestral_roster(node_id nid,
revision_id & rid,
boost::shared_ptr<roster_t const> & anc);
void get_version(file_id const & ident,
file_data & dat) const;
};
struct
content_merge_checkout_adaptor
: public content_merge_adaptor
{
database & db;
content_merge_checkout_adaptor(database & db)
: db(db)
{}
void record_merge(file_id const & left_ident,
file_id const & right_ident,
file_id const & merged_ident,
file_data const & left_data,
file_data const & right_data,
file_data const & merged_data);
void record_file(file_id const & parent_ident,
file_id const & merged_ident,
file_data const & parent_data,
file_data const & merged_data);
void get_ancestral_roster(node_id nid,
revision_id & rid,
boost::shared_ptr<roster_t const> & anc);
void get_version(file_id const & ident,
file_data & dat) const;
};
struct content_merger
{
lua_hooks & lua;
roster_t const & anc_ros;
roster_t const & left_ros;
roster_t const & right_ros;
content_merge_adaptor & adaptor;
content_merger(lua_hooks & lua,
roster_t const & anc_ros,
roster_t const & left_ros,
roster_t const & right_ros,
content_merge_adaptor & adaptor)
: lua(lua),
anc_ros(anc_ros),
left_ros(left_ros),
right_ros(right_ros),
adaptor(adaptor)
{}
// Attempt merge3 on a file (line by line). Return true and valid data if
// it would succeed; false and invalid data otherwise.
bool attempt_auto_merge(file_path const & anc_path, // inputs
file_path const & left_path,
file_path const & right_path,
file_id const & ancestor_id,
file_id const & left_id,
file_id const & right_id,
file_data & left_data, // outputs
file_data & right_data,
file_data & merge_data);
// Attempt merge3 on a file (line by line). If it succeeded, store results
// in database and return true and valid merged_id; return false
// otherwise.
bool try_auto_merge(file_path const & anc_path,
file_path const & left_path,
file_path const & right_path,
file_path const & merged_path,
file_id const & ancestor_id,
file_id const & left_id,
file_id const & right,
file_id & merged_id);
bool try_user_merge(file_path const & anc_path,
file_path const & left_path,
file_path const & right_path,
file_path const & merged_path,
file_id const & ancestor_id,
file_id const & left_id,
file_id const & right,
file_id & merged_id);
std::string get_file_encoding(file_path const & path,
roster_t const & ros);
bool attribute_manual_merge(file_path const & path,
roster_t const & ros);
};
// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
#endif // __DIFF_PATCH_HH__