xref: /trueos/contrib/subversion/subversion/libsvn_diff/deprecated.c (revision 1e5107043085964bba002e6a91aa04e864f74d02)
1 /*
2  * deprecated.c:  holding file for all deprecated APIs.
3  *                "we can't lose 'em, but we can shun 'em!"
4  *
5  * ====================================================================
6  *    Licensed to the Apache Software Foundation (ASF) under one
7  *    or more contributor license agreements.  See the NOTICE file
8  *    distributed with this work for additional information
9  *    regarding copyright ownership.  The ASF licenses this file
10  *    to you under the Apache License, Version 2.0 (the
11  *    "License"); you may not use this file except in compliance
12  *    with the License.  You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  *    Unless required by applicable law or agreed to in writing,
17  *    software distributed under the License is distributed on an
18  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  *    KIND, either express or implied.  See the License for the
20  *    specific language governing permissions and limitations
21  *    under the License.
22  * ====================================================================
23  */
24 
25 /* ==================================================================== */
26 
27 
28 
29 /*** Includes. ***/
30 
31 /* We define this here to remove any further warnings about the usage of
32    deprecated functions in this file. */
33 #define SVN_DEPRECATED
34 
35 #include "svn_diff.h"
36 #include "svn_utf.h"
37 
38 #include "svn_private_config.h"
39 
40 
41 
42 
43 /*** Code. ***/
44 struct fns_wrapper_baton
45 {
46   /* We put the old baton in front of this one, so that we can still use
47      this baton in place of the old.  This prevents us from having to
48      implement simple wrappers around each member of diff_fns_t. */
49   void *old_baton;
50   const svn_diff_fns_t *vtable;
51 };
52 
53 static svn_error_t *
datasources_open(void * baton,apr_off_t * prefix_lines,apr_off_t * suffix_lines,const svn_diff_datasource_e * datasources,apr_size_t datasource_len)54 datasources_open(void *baton,
55                  apr_off_t *prefix_lines,
56                  apr_off_t *suffix_lines,
57                  const svn_diff_datasource_e *datasources,
58                  apr_size_t datasource_len)
59 {
60   struct fns_wrapper_baton *fwb = baton;
61   apr_size_t i;
62 
63   /* Just iterate over the datasources, using the old singular version. */
64   for (i = 0; i < datasource_len; i++)
65     {
66       SVN_ERR(fwb->vtable->datasource_open(fwb->old_baton, datasources[i]));
67     }
68 
69   /* Don't claim any prefix or suffix matches. */
70   *prefix_lines = 0;
71   *suffix_lines = 0;
72 
73   return SVN_NO_ERROR;
74 }
75 
76 static svn_error_t *
datasource_close(void * baton,svn_diff_datasource_e datasource)77 datasource_close(void *baton,
78                  svn_diff_datasource_e datasource)
79 {
80   struct fns_wrapper_baton *fwb = baton;
81   return fwb->vtable->datasource_close(fwb->old_baton, datasource);
82 }
83 
84 static svn_error_t *
datasource_get_next_token(apr_uint32_t * hash,void ** token,void * baton,svn_diff_datasource_e datasource)85 datasource_get_next_token(apr_uint32_t *hash,
86                           void **token,
87                           void *baton,
88                           svn_diff_datasource_e datasource)
89 {
90   struct fns_wrapper_baton *fwb = baton;
91   return fwb->vtable->datasource_get_next_token(hash, token, fwb->old_baton,
92                                                 datasource);
93 }
94 
95 static svn_error_t *
token_compare(void * baton,void * ltoken,void * rtoken,int * compare)96 token_compare(void *baton,
97               void *ltoken,
98               void *rtoken,
99               int *compare)
100 {
101   struct fns_wrapper_baton *fwb = baton;
102   return fwb->vtable->token_compare(fwb->old_baton, ltoken, rtoken, compare);
103 }
104 
105 static void
token_discard(void * baton,void * token)106 token_discard(void *baton,
107               void *token)
108 {
109   struct fns_wrapper_baton *fwb = baton;
110   fwb->vtable->token_discard(fwb->old_baton, token);
111 }
112 
113 static void
token_discard_all(void * baton)114 token_discard_all(void *baton)
115 {
116   struct fns_wrapper_baton *fwb = baton;
117   fwb->vtable->token_discard_all(fwb->old_baton);
118 }
119 
120 
121 static void
wrap_diff_fns(svn_diff_fns2_t ** diff_fns2,struct fns_wrapper_baton ** baton2,const svn_diff_fns_t * diff_fns,void * baton,apr_pool_t * result_pool)122 wrap_diff_fns(svn_diff_fns2_t **diff_fns2,
123               struct fns_wrapper_baton **baton2,
124               const svn_diff_fns_t *diff_fns,
125               void *baton,
126               apr_pool_t *result_pool)
127 {
128   /* Initialize the return vtable. */
129   *diff_fns2 = apr_palloc(result_pool, sizeof(**diff_fns2));
130 
131   (*diff_fns2)->datasources_open = datasources_open;
132   (*diff_fns2)->datasource_close = datasource_close;
133   (*diff_fns2)->datasource_get_next_token = datasource_get_next_token;
134   (*diff_fns2)->token_compare = token_compare;
135   (*diff_fns2)->token_discard = token_discard;
136   (*diff_fns2)->token_discard_all = token_discard_all;
137 
138   /* Initialize the wrapper baton. */
139   *baton2 = apr_palloc(result_pool, sizeof (**baton2));
140   (*baton2)->old_baton = baton;
141   (*baton2)->vtable = diff_fns;
142 }
143 
144 
145 /*** From diff_file.c ***/
146 svn_error_t *
svn_diff_file_output_unified2(svn_stream_t * output_stream,svn_diff_t * diff,const char * original_path,const char * modified_path,const char * original_header,const char * modified_header,const char * header_encoding,apr_pool_t * pool)147 svn_diff_file_output_unified2(svn_stream_t *output_stream,
148                               svn_diff_t *diff,
149                               const char *original_path,
150                               const char *modified_path,
151                               const char *original_header,
152                               const char *modified_header,
153                               const char *header_encoding,
154                               apr_pool_t *pool)
155 {
156   return svn_diff_file_output_unified3(output_stream, diff,
157                                        original_path, modified_path,
158                                        original_header, modified_header,
159                                        header_encoding, NULL, FALSE, pool);
160 }
161 
162 svn_error_t *
svn_diff_file_output_unified(svn_stream_t * output_stream,svn_diff_t * diff,const char * original_path,const char * modified_path,const char * original_header,const char * modified_header,apr_pool_t * pool)163 svn_diff_file_output_unified(svn_stream_t *output_stream,
164                              svn_diff_t *diff,
165                              const char *original_path,
166                              const char *modified_path,
167                              const char *original_header,
168                              const char *modified_header,
169                              apr_pool_t *pool)
170 {
171   return svn_diff_file_output_unified2(output_stream, diff,
172                                        original_path, modified_path,
173                                        original_header, modified_header,
174                                        SVN_APR_LOCALE_CHARSET, pool);
175 }
176 
177 svn_error_t *
svn_diff_file_diff(svn_diff_t ** diff,const char * original,const char * modified,apr_pool_t * pool)178 svn_diff_file_diff(svn_diff_t **diff,
179                    const char *original,
180                    const char *modified,
181                    apr_pool_t *pool)
182 {
183   return svn_diff_file_diff_2(diff, original, modified,
184                               svn_diff_file_options_create(pool), pool);
185 }
186 
187 svn_error_t *
svn_diff_file_diff3(svn_diff_t ** diff,const char * original,const char * modified,const char * latest,apr_pool_t * pool)188 svn_diff_file_diff3(svn_diff_t **diff,
189                     const char *original,
190                     const char *modified,
191                     const char *latest,
192                     apr_pool_t *pool)
193 {
194   return svn_diff_file_diff3_2(diff, original, modified, latest,
195                                svn_diff_file_options_create(pool), pool);
196 }
197 
198 svn_error_t *
svn_diff_file_diff4(svn_diff_t ** diff,const char * original,const char * modified,const char * latest,const char * ancestor,apr_pool_t * pool)199 svn_diff_file_diff4(svn_diff_t **diff,
200                     const char *original,
201                     const char *modified,
202                     const char *latest,
203                     const char *ancestor,
204                     apr_pool_t *pool)
205 {
206   return svn_diff_file_diff4_2(diff, original, modified, latest, ancestor,
207                                svn_diff_file_options_create(pool), pool);
208 }
209 
210 svn_error_t *
svn_diff_file_output_merge(svn_stream_t * output_stream,svn_diff_t * diff,const char * original_path,const char * modified_path,const char * latest_path,const char * conflict_original,const char * conflict_modified,const char * conflict_latest,const char * conflict_separator,svn_boolean_t display_original_in_conflict,svn_boolean_t display_resolved_conflicts,apr_pool_t * pool)211 svn_diff_file_output_merge(svn_stream_t *output_stream,
212                            svn_diff_t *diff,
213                            const char *original_path,
214                            const char *modified_path,
215                            const char *latest_path,
216                            const char *conflict_original,
217                            const char *conflict_modified,
218                            const char *conflict_latest,
219                            const char *conflict_separator,
220                            svn_boolean_t display_original_in_conflict,
221                            svn_boolean_t display_resolved_conflicts,
222                            apr_pool_t *pool)
223 {
224   svn_diff_conflict_display_style_t style =
225     svn_diff_conflict_display_modified_latest;
226 
227   if (display_resolved_conflicts)
228     style = svn_diff_conflict_display_resolved_modified_latest;
229 
230   if (display_original_in_conflict)
231     style = svn_diff_conflict_display_modified_original_latest;
232 
233   return svn_diff_file_output_merge2(output_stream,
234                                      diff,
235                                      original_path,
236                                      modified_path,
237                                      latest_path,
238                                      conflict_original,
239                                      conflict_modified,
240                                      conflict_latest,
241                                      conflict_separator,
242                                      style,
243                                      pool);
244 }
245 
246 
247 /*** From diff.c ***/
248 svn_error_t *
svn_diff_diff(svn_diff_t ** diff,void * diff_baton,const svn_diff_fns_t * vtable,apr_pool_t * pool)249 svn_diff_diff(svn_diff_t **diff,
250               void *diff_baton,
251               const svn_diff_fns_t *vtable,
252               apr_pool_t *pool)
253 {
254   svn_diff_fns2_t *diff_fns2;
255   struct fns_wrapper_baton *fwb;
256 
257   wrap_diff_fns(&diff_fns2, &fwb, vtable, diff_baton, pool);
258   return svn_diff_diff_2(diff, fwb, diff_fns2, pool);
259 }
260 
261 
262 /*** From diff3.c ***/
263 svn_error_t *
svn_diff_diff3(svn_diff_t ** diff,void * diff_baton,const svn_diff_fns_t * vtable,apr_pool_t * pool)264 svn_diff_diff3(svn_diff_t **diff,
265                void *diff_baton,
266                const svn_diff_fns_t *vtable,
267                apr_pool_t *pool)
268 {
269   svn_diff_fns2_t *diff_fns2;
270   struct fns_wrapper_baton *fwb;
271 
272   wrap_diff_fns(&diff_fns2, &fwb, vtable, diff_baton, pool);
273   return svn_diff_diff3_2(diff, fwb, diff_fns2, pool);
274 }
275 
276 
277 /*** From diff4.c ***/
278 svn_error_t *
svn_diff_diff4(svn_diff_t ** diff,void * diff_baton,const svn_diff_fns_t * vtable,apr_pool_t * pool)279 svn_diff_diff4(svn_diff_t **diff,
280                void *diff_baton,
281                const svn_diff_fns_t *vtable,
282                apr_pool_t *pool)
283 {
284   svn_diff_fns2_t *diff_fns2;
285   struct fns_wrapper_baton *fwb;
286 
287   wrap_diff_fns(&diff_fns2, &fwb, vtable, diff_baton, pool);
288   return svn_diff_diff4_2(diff, fwb, diff_fns2, pool);
289 }
290