monotone

monotone Mtn Source Tree

Root/diff_patch.hh

1#ifndef __DIFF_PATCH_HH__
2#define __DIFF_PATCH_HH__
3
4// Copyright (C) 2002 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 "rev_types.hh"
14// XXX needed for gcc 3.3 which will otherwise complain that struct file_path
15// is just a forward in rev_types.hh and therefor leads to an incomplete type
16#include "paths.hh"
17
18class database;
19class lua_hooks;
20
21struct conflict {};
22
23// this file is to contain some stripped down, in-process implementations
24// of GNU-diffutils-like things (diff, diff3, maybe patch..)
25
26void make_diff(std::string const & filename1,
27 std::string const & filename2,
28 file_id const & id1,
29 file_id const & id2,
30 data const & data1,
31 data const & data2,
32 std::ostream & ost,
33 diff_type type,
34 std::string const & pattern);
35
36bool merge3(std::vector<std::string> const & ancestor,
37 std::vector<std::string> const & left,
38 std::vector<std::string> const & right,
39 std::vector<std::string> & merged);
40
41struct
42content_merge_adaptor
43{
44 virtual void record_merge(file_id const & left_ident,
45 file_id const & right_ident,
46 file_id const & merged_ident,
47 file_data const & left_data,
48 file_data const & right_data,
49 file_data const & merged_data) = 0;
50
51 virtual void get_ancestral_roster(node_id nid,
52 revision_id & rid,
53 boost::shared_ptr<roster_t const> & anc) = 0;
54
55 virtual void get_version(file_id const & ident,
56 file_data & dat) const = 0;
57
58 virtual ~content_merge_adaptor() {}
59};
60
61struct
62content_merge_database_adaptor
63 : public content_merge_adaptor
64{
65 database & db;
66 revision_id lca;
67 revision_id left_rid;
68 revision_id right_rid;
69 marking_map const & left_mm;
70 marking_map const & right_mm;
71 std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
72 content_merge_database_adaptor(database & db,
73 revision_id const & left,
74 revision_id const & right,
75 marking_map const & left_mm,
76 marking_map const & right_mm);
77 void record_merge(file_id const & left_ident,
78 file_id const & right_ident,
79 file_id const & merged_ident,
80 file_data const & left_data,
81 file_data const & right_data,
82 file_data const & merged_data);
83
84 void cache_roster(revision_id const & rid,
85 boost::shared_ptr<roster_t const> roster);
86
87 void get_ancestral_roster(node_id nid,
88 revision_id & rid,
89 boost::shared_ptr<roster_t const> & anc);
90
91 void get_version(file_id const & ident,
92 file_data & dat) const;
93};
94
95struct
96content_merge_workspace_adaptor
97 : public content_merge_adaptor
98{
99 std::map<file_id, file_data> temporary_store;
100 database & db;
101 revision_id const lca;
102 boost::shared_ptr<roster_t const> base;
103 marking_map const & left_mm;
104 marking_map const & right_mm;
105 std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
106 std::map<file_id, file_path> content_paths;
107 content_merge_workspace_adaptor(database & db,
108 revision_id const & lca,
109 boost::shared_ptr<roster_t const> base,
110 marking_map const & left_mm,
111 marking_map const & right_mm,
112 std::map<file_id, file_path> const & paths)
113 : db(db), lca(lca), base(base),
114 left_mm(left_mm), right_mm(right_mm), content_paths(paths)
115 {}
116
117 void cache_roster(revision_id const & rid,
118 boost::shared_ptr<roster_t const> roster);
119
120 void record_merge(file_id const & left_ident,
121 file_id const & right_ident,
122 file_id const & merged_ident,
123 file_data const & left_data,
124 file_data const & right_data,
125 file_data const & merged_data);
126
127 void get_ancestral_roster(node_id nid,
128 revision_id & rid,
129 boost::shared_ptr<roster_t const> & anc);
130
131 void get_version(file_id const & ident,
132 file_data & dat) const;
133};
134
135struct
136content_merge_checkout_adaptor
137 : public content_merge_adaptor
138{
139 database & db;
140 content_merge_checkout_adaptor(database & db)
141 : db(db)
142 {}
143
144 void record_merge(file_id const & left_ident,
145 file_id const & right_ident,
146 file_id const & merged_ident,
147 file_data const & left_data,
148 file_data const & right_data,
149 file_data const & merged_data);
150
151 void get_ancestral_roster(node_id nid,
152 revision_id & rid,
153 boost::shared_ptr<roster_t const> & anc);
154
155 void get_version(file_id const & ident,
156 file_data & dat) const;
157
158};
159
160
161struct content_merger
162{
163 lua_hooks & lua;
164 roster_t const & anc_ros;
165 roster_t const & left_ros;
166 roster_t const & right_ros;
167
168 content_merge_adaptor & adaptor;
169
170 content_merger(lua_hooks & lua,
171 roster_t const & anc_ros,
172 roster_t const & left_ros,
173 roster_t const & right_ros,
174 content_merge_adaptor & adaptor)
175 : lua(lua),
176 anc_ros(anc_ros),
177 left_ros(left_ros),
178 right_ros(right_ros),
179 adaptor(adaptor)
180 {}
181
182 // merge3 on a file (line by line)
183 bool try_auto_merge(file_path const & anc_path,
184 file_path const & left_path,
185 file_path const & right_path,
186 file_path const & merged_path,
187 file_id const & ancestor_id,
188 file_id const & left_id,
189 file_id const & right,
190 file_id & merged_id);
191
192 bool try_user_merge(file_path const & anc_path,
193 file_path const & left_path,
194 file_path const & right_path,
195 file_path const & merged_path,
196 file_id const & ancestor_id,
197 file_id const & left_id,
198 file_id const & right,
199 file_id & merged_id);
200
201 std::string get_file_encoding(file_path const & path,
202 roster_t const & ros);
203
204 bool attribute_manual_merge(file_path const & path,
205 roster_t const & ros);
206};
207
208// Local Variables:
209// mode: C++
210// fill-column: 76
211// c-file-style: "gnu"
212// indent-tabs-mode: nil
213// End:
214// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
215
216#endif // __DIFF_PATCH_HH__

Archive Download this file

Branches

Tags

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