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

Archive Download this file

Branches

Tags

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