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

Archive Download this file

Branches

Tags

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