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 marking_map const & left_mm;
68 marking_map const & right_mm;
69 std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
70 content_merge_database_adaptor(database & db,
71 revision_id const & left,
72 revision_id const & right,
73 marking_map const & left_mm,
74 marking_map const & right_mm);
75 void record_merge(file_id const & left_ident,
76 file_id const & right_ident,
77 file_id const & merged_ident,
78 file_data const & left_data,
79 file_data const & right_data,
80 file_data const & merged_data);
81
82 void get_ancestral_roster(node_id nid,
83 revision_id & rid,
84 boost::shared_ptr<roster_t const> & anc);
85
86 void get_version(file_id const & ident,
87 file_data & dat) const;
88};
89
90struct
91content_merge_workspace_adaptor
92 : public content_merge_adaptor
93{
94 std::map<file_id, file_data> temporary_store;
95 database & db;
96 revision_id const lca;
97 boost::shared_ptr<roster_t const> base;
98 marking_map const & left_mm;
99 marking_map const & right_mm;
100 std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
101 std::map<file_id, file_path> content_paths;
102 content_merge_workspace_adaptor(database & db,
103 revision_id const & lca,
104 boost::shared_ptr<roster_t const> base,
105 marking_map const & left_mm,
106 marking_map const & right_mm,
107 std::map<file_id, file_path> const & paths)
108 : db(db), lca(lca), base(base),
109 left_mm(left_mm), right_mm(right_mm), content_paths(paths)
110 {}
111
112 void cache_roster(revision_id const & rid,
113 boost::shared_ptr<roster_t const> roster);
114
115 void record_merge(file_id const & left_ident,
116 file_id const & right_ident,
117 file_id const & merged_ident,
118 file_data const & left_data,
119 file_data const & right_data,
120 file_data const & merged_data);
121
122 void get_ancestral_roster(node_id nid,
123 revision_id & rid,
124 boost::shared_ptr<roster_t const> & anc);
125
126 void get_version(file_id const & ident,
127 file_data & dat) const;
128};
129
130struct
131content_merge_checkout_adaptor
132 : public content_merge_adaptor
133{
134 database & db;
135 content_merge_checkout_adaptor(database & db)
136 : db(db)
137 {}
138
139 void record_merge(file_id const & left_ident,
140 file_id const & right_ident,
141 file_id const & merged_ident,
142 file_data const & left_data,
143 file_data const & right_data,
144 file_data const & merged_data);
145
146 void get_ancestral_roster(node_id nid,
147 revision_id & rid,
148 boost::shared_ptr<roster_t const> & anc);
149
150 void get_version(file_id const & ident,
151 file_data & dat) const;
152
153};
154
155
156struct content_merger
157{
158 lua_hooks & lua;
159 roster_t const & anc_ros;
160 roster_t const & left_ros;
161 roster_t const & right_ros;
162
163 content_merge_adaptor & adaptor;
164
165 content_merger(lua_hooks & lua,
166 roster_t const & anc_ros,
167 roster_t const & left_ros,
168 roster_t const & right_ros,
169 content_merge_adaptor & adaptor)
170 : lua(lua),
171 anc_ros(anc_ros),
172 left_ros(left_ros),
173 right_ros(right_ros),
174 adaptor(adaptor)
175 {}
176
177 // merge3 on a file (line by line)
178 bool try_auto_merge(file_path const & anc_path,
179 file_path const & left_path,
180 file_path const & right_path,
181 file_path const & merged_path,
182 file_id const & ancestor_id,
183 file_id const & left_id,
184 file_id const & right,
185 file_id & merged_id);
186
187 bool try_user_merge(file_path const & anc_path,
188 file_path const & left_path,
189 file_path const & right_path,
190 file_path const & merged_path,
191 file_id const & ancestor_id,
192 file_id const & left_id,
193 file_id const & right,
194 file_id & merged_id);
195
196 std::string get_file_encoding(file_path const & path,
197 roster_t const & ros);
198
199 bool attribute_manual_merge(file_path const & path,
200 roster_t const & ros);
201};
202
203// Local Variables:
204// mode: C++
205// fill-column: 76
206// c-file-style: "gnu"
207// indent-tabs-mode: nil
208// End:
209// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
210
211#endif // __DIFF_PATCH_HH__

Archive Download this file

Branches

Tags

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