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 "app_state.hh"
14#include "cert.hh"
15#include "vocab.hh"
16
17#include <boost/shared_ptr.hpp>
18
19#include <map>
20#include <string>
21#include <vector>
22
23class roster_t;
24
25struct conflict {};
26
27// this file is to contain some stripped down, in-process implementations
28// of GNU-diffutils-like things (diff, diff3, maybe patch..)
29
30void make_diff(std::string const & filename1,
31 std::string const & filename2,
32 file_id const & id1,
33 file_id const & id2,
34 data const & data1,
35 data const & data2,
36 std::ostream & ost,
37 diff_type type,
38 std::string const & pattern);
39
40bool merge3(std::vector<std::string> const & ancestor,
41 std::vector<std::string> const & left,
42 std::vector<std::string> const & right,
43 std::vector<std::string> & merged);
44
45struct
46content_merge_adaptor
47{
48 virtual void record_merge(file_id const & left_ident,
49 file_id const & right_ident,
50 file_id const & merged_ident,
51 file_data const & left_data,
52 file_data const & merged_data) = 0;
53
54 virtual void get_ancestral_roster(node_id nid,
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 & mm;
70 std::map<revision_id, boost::shared_ptr<roster_t const> > rosters;
71 content_merge_database_adaptor (app_state & app,
72 revision_id const & left,
73 revision_id const & right,
74 marking_map const & 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 & merged_data);
80
81 void get_ancestral_roster(node_id nid,
82 boost::shared_ptr<roster_t const> & anc);
83
84 void get_version(file_id const & ident,
85 file_data & dat) const;
86};
87
88struct
89content_merge_workspace_adaptor
90 : public content_merge_adaptor
91{
92 std::map<file_id, file_data> temporary_store;
93 app_state & app;
94 boost::shared_ptr<roster_t const> base;
95 std::map<file_id, file_path> content_paths;
96 content_merge_workspace_adaptor (app_state & app,
97 boost::shared_ptr<roster_t const> base,
98 std::map<file_id, file_path> const & paths)
99 : app(app), base(base), content_paths(paths)
100 {}
101 void record_merge(file_id const & left_ident,
102 file_id const & right_ident,
103 file_id const & merged_ident,
104 file_data const & left_data,
105 file_data const & merged_data);
106
107 void get_ancestral_roster(node_id nid,
108 boost::shared_ptr<roster_t const> & anc);
109
110 void get_version(file_id const & ident,
111 file_data & dat) const;
112};
113
114struct content_merger
115{
116 app_state & app;
117 roster_t const & anc_ros;
118 roster_t const & left_ros;
119 roster_t const & right_ros;
120
121 content_merge_adaptor & adaptor;
122
123 content_merger(app_state & app,
124 roster_t const & anc_ros,
125 roster_t const & left_ros,
126 roster_t const & right_ros,
127 content_merge_adaptor & adaptor);
128
129 // merge3 on a file (line by line)
130 bool try_to_merge_files(file_path const & anc_path,
131 file_path const & left_path,
132 file_path const & right_path,
133 file_path const & merged_path,
134 file_id const & ancestor_id,
135 file_id const & left_id,
136 file_id const & right,
137 file_id & merged_id);
138
139 std::string get_file_encoding(file_path const & path,
140 roster_t const & ros);
141
142 bool attribute_manual_merge(file_path const & path,
143 roster_t const & ros);
144};
145
146// Local Variables:
147// mode: C++
148// fill-column: 76
149// c-file-style: "gnu"
150// indent-tabs-mode: nil
151// End:
152// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
153
154#endif // __DIFF_PATCH_HH__

Archive Download this file

Branches

Tags

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