1251881Speter/*
2251881Speter * conflicts.h: declarations related to conflicts
3251881Speter *
4251881Speter * ====================================================================
5251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
6251881Speter *    or more contributor license agreements.  See the NOTICE file
7251881Speter *    distributed with this work for additional information
8251881Speter *    regarding copyright ownership.  The ASF licenses this file
9251881Speter *    to you under the Apache License, Version 2.0 (the
10251881Speter *    "License"); you may not use this file except in compliance
11251881Speter *    with the License.  You may obtain a copy of the License at
12251881Speter *
13251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
14251881Speter *
15251881Speter *    Unless required by applicable law or agreed to in writing,
16251881Speter *    software distributed under the License is distributed on an
17251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18251881Speter *    KIND, either express or implied.  See the License for the
19251881Speter *    specific language governing permissions and limitations
20251881Speter *    under the License.
21251881Speter * ====================================================================
22251881Speter */
23251881Speter
24251881Speter#ifndef SVN_WC_CONFLICTS_H
25251881Speter#define SVN_WC_CONFLICTS_H
26251881Speter
27251881Speter#include <apr_pools.h>
28251881Speter
29251881Speter#include "svn_types.h"
30251881Speter#include "svn_wc.h"
31251881Speter
32251881Speter#include "wc_db.h"
33251881Speter#include "private/svn_skel.h"
34251881Speter
35251881Speter#ifdef __cplusplus
36251881Speterextern "C" {
37251881Speter#endif /* __cplusplus */
38251881Speter
39251881Speter
40251881Speter
41251881Speter#define SVN_WC__CONFLICT_OP_UPDATE "update"
42251881Speter#define SVN_WC__CONFLICT_OP_SWITCH "switch"
43251881Speter#define SVN_WC__CONFLICT_OP_MERGE "merge"
44251881Speter#define SVN_WC__CONFLICT_OP_PATCH "patch"
45251881Speter
46251881Speter#define SVN_WC__CONFLICT_KIND_TEXT "text"
47251881Speter#define SVN_WC__CONFLICT_KIND_PROP "prop"
48251881Speter#define SVN_WC__CONFLICT_KIND_TREE "tree"
49251881Speter#define SVN_WC__CONFLICT_KIND_REJECT "reject"
50251881Speter#define SVN_WC__CONFLICT_KIND_OBSTRUCTED "obstructed"
51251881Speter
52251881Speter#define SVN_WC__CONFLICT_SRC_SUBVERSION "subversion"
53251881Speter
54251881Speter/* Return a new conflict skel, allocated in RESULT_POOL.
55251881Speter
56251881Speter   Typically creating a conflict starts with calling this function and then
57251881Speter   collecting details via one or more calls to svn_wc__conflict_skel_add_*().
58251881Speter
59251881Speter   The caller can then (when necessary) add operation details via
60251881Speter   svn_wc__conflict_skel_set_op_*() and store the resulting conflict together
61251881Speter   with the result of its operation in the working copy database.
62251881Speter*/
63251881Spetersvn_skel_t *
64251881Spetersvn_wc__conflict_skel_create(apr_pool_t *result_pool);
65251881Speter
66251881Speter/* Return a boolean in *COMPLETE indicating whether CONFLICT_SKEL contains
67251881Speter   everything needed for installing in the working copy database.
68251881Speter
69251881Speter   This typically checks if CONFLICT_SKEL contains at least one conflict
70251881Speter   and an operation.
71251881Speter */
72251881Spetersvn_error_t *
73251881Spetersvn_wc__conflict_skel_is_complete(svn_boolean_t *complete,
74251881Speter                                  const svn_skel_t *conflict_skel);
75251881Speter
76251881Speter
77251881Speter/* Set 'update' as the conflicting operation in CONFLICT_SKEL.
78251881Speter   Allocate data stored in the skel in RESULT_POOL.
79251881Speter
80251881Speter   ORIGINAL and TARGET specify the BASE node before and after updating.
81251881Speter
82251881Speter   It is an error to set another operation to a conflict skel that
83251881Speter   already has an operation.
84251881Speter
85251881Speter   Do temporary allocations in SCRATCH_POOL. The new skel data is
86251881Speter   completely stored in RESULT-POOL. */
87251881Spetersvn_error_t *
88251881Spetersvn_wc__conflict_skel_set_op_update(svn_skel_t *conflict_skel,
89251881Speter                                    const svn_wc_conflict_version_t *original,
90251881Speter                                    const svn_wc_conflict_version_t *target,
91251881Speter                                    apr_pool_t *result_pool,
92251881Speter                                    apr_pool_t *scratch_pool);
93251881Speter
94251881Speter
95251881Speter/* Set 'switch' as the conflicting operation in CONFLICT_SKEL.
96251881Speter   Allocate data stored in the skel in RESULT_POOL.
97251881Speter
98251881Speter   ORIGINAL and TARGET specify the BASE node before and after switching.
99251881Speter
100251881Speter   It is an error to set another operation to a conflict skel that
101251881Speter   already has an operation.
102251881Speter
103251881Speter   Do temporary allocations in SCRATCH_POOL. */
104251881Spetersvn_error_t *
105251881Spetersvn_wc__conflict_skel_set_op_switch(svn_skel_t *conflict_skel,
106251881Speter                                    const svn_wc_conflict_version_t *original,
107251881Speter                                    const svn_wc_conflict_version_t *target,
108251881Speter                                    apr_pool_t *result_pool,
109251881Speter                                    apr_pool_t *scratch_pool);
110251881Speter
111251881Speter
112251881Speter/* Set 'merge' as conflicting operation in CONFLICT_SKEL.
113251881Speter   Allocate data stored in the skel in RESULT_POOL.
114251881Speter
115251881Speter   LEFT and RIGHT paths are the merge-left and merge-right merge
116251881Speter   sources of the merge.
117251881Speter
118251881Speter   It is an error to set another operation to a conflict skel that
119251881Speter   already has an operation.
120251881Speter
121251881Speter   Do temporary allocations in SCRATCH_POOL. */
122251881Spetersvn_error_t *
123251881Spetersvn_wc__conflict_skel_set_op_merge(svn_skel_t *conflict_skel,
124251881Speter                                   const svn_wc_conflict_version_t *left,
125251881Speter                                   const svn_wc_conflict_version_t *right,
126251881Speter                                   apr_pool_t *result_pool,
127251881Speter                                   apr_pool_t *scratch_pool);
128251881Speter
129251881Speter
130251881Speter/* Add a text conflict to CONFLICT_SKEL.
131251881Speter   Allocate data stored in the skel in RESULT_POOL.
132251881Speter
133251881Speter   The DB, WRI_ABSPATH pair specifies in which working copy the conflict
134251881Speter   will be recorded. (Needed for making the paths relative).
135251881Speter
136251881Speter   MINE_ABSPATH, THEIR_OLD_ABSPATH and THEIR_ABSPATH specify the marker
137251881Speter   files for this text conflict. Each of these values can be NULL to specify
138251881Speter   that the node doesn't exist in this case.
139251881Speter
140251881Speter   ### It is expected that in a future version we will also want to store
141251881Speter   ### the sha1 checksum of these files to allow reinstalling the conflict
142251881Speter   ### markers from the pristine store.
143251881Speter
144251881Speter   It is an error to add another text conflict to a conflict skel that
145251881Speter   already contains a text conflict.
146251881Speter
147251881Speter   Do temporary allocations in SCRATCH_POOL.
148251881Speter*/
149251881Spetersvn_error_t *
150251881Spetersvn_wc__conflict_skel_add_text_conflict(svn_skel_t *conflict_skel,
151251881Speter                                        svn_wc__db_t *db,
152251881Speter                                        const char *wri_abspath,
153251881Speter                                        const char *mine_abspath,
154251881Speter                                        const char *their_old_abspath,
155251881Speter                                        const char *their_abspath,
156251881Speter                                        apr_pool_t *result_pool,
157251881Speter                                        apr_pool_t *scratch_pool);
158251881Speter
159251881Speter
160251881Speter/* Add property conflict details to CONFLICT_SKEL.
161251881Speter   Allocate data stored in the skel in RESULT_POOL.
162251881Speter
163251881Speter   The DB, WRI_ABSPATH pair specifies in which working copy the conflict
164251881Speter   will be recorded. (Needed for making the paths relative).
165251881Speter
166251881Speter   The MARKER_ABSPATH is NULL when raising a conflict in v1.8+.  See below.
167251881Speter
168251881Speter   The MINE_PROPS, THEIR_OLD_PROPS and THEIR_PROPS are hashes mapping a
169251881Speter   const char * property name to a const svn_string_t* value.
170251881Speter
171251881Speter   The CONFLICTED_PROP_NAMES is a const char * property name value mapping
172251881Speter   to "", recording which properties aren't resolved yet in the current
173251881Speter   property values.
174251881Speter   ### Needed for creating the marker file from this conflict data.
175251881Speter   ### Would also allow per property marking as resolved.
176251881Speter   ### Maybe useful for calling (legacy) conflict resolvers that expect one
177251881Speter   ### property conflict per invocation.
178251881Speter
179251881Speter   When raising a property conflict in the course of upgrading an old WC,
180251881Speter   MARKER_ABSPATH is the path to the file containing a human-readable
181251881Speter   description of the conflict, MINE_PROPS and THEIR_OLD_PROPS and
182251881Speter   THEIR_PROPS are all NULL, and CONFLICTED_PROP_NAMES is an empty hash.
183251881Speter
184251881Speter   It is an error to add another prop conflict to a conflict skel that
185251881Speter   already contains a prop conflict.  (A single call to this function can
186251881Speter   record that multiple properties are in conflict.)
187251881Speter
188251881Speter   Do temporary allocations in SCRATCH_POOL.
189251881Speter*/
190251881Spetersvn_error_t *
191251881Spetersvn_wc__conflict_skel_add_prop_conflict(svn_skel_t *conflict_skel,
192251881Speter                                        svn_wc__db_t *db,
193251881Speter                                        const char *wri_abspath,
194251881Speter                                        const char *marker_abspath,
195251881Speter                                        const apr_hash_t *mine_props,
196251881Speter                                        const apr_hash_t *their_old_props,
197251881Speter                                        const apr_hash_t *their_props,
198251881Speter                                        const apr_hash_t *conflicted_prop_names,
199251881Speter                                        apr_pool_t *result_pool,
200251881Speter                                        apr_pool_t *scratch_pool);
201251881Speter
202251881Speter
203251881Speter/* Add a tree conflict to CONFLICT_SKEL.
204251881Speter   Allocate data stored in the skel in RESULT_POOL.
205251881Speter
206251881Speter   LOCAL_CHANGE is the local tree change made to the node.
207251881Speter   INCOMING_CHANGE is the incoming change made to the node.
208251881Speter
209251881Speter   MOVE_SRC_OP_ROOT_ABSPATH must be set when LOCAL_CHANGE is
210251881Speter   svn_wc_conflict_reason_moved_away and NULL otherwise and the operation
211251881Speter   is svn_wc_operation_update or svn_wc_operation_switch.  It should be
212251881Speter   set to the op-root of the move-away unless the move is inside a
213251881Speter   delete in which case it should be set to the op-root of the delete
214251881Speter   (the delete can be a replace). So given:
215251881Speter       A/B/C moved away (1)
216251881Speter       A deleted and replaced
217251881Speter       A/B/C moved away (2)
218251881Speter       A/B deleted
219251881Speter   MOVE_SRC_OP_ROOT_ABSPATH should be A for a conflict associated
220251881Speter   with (1), MOVE_SRC_OP_ROOT_ABSPATH should be A/B for a conflict
221251881Speter   associated with (2).
222362181Sdim   MOVE_DST_OP_ROOT_ABSPATH is the op-root of the move target (i.e. the
223362181Sdim   op-root of the corresponding copy). This needs to be stored because
224362181Sdim   moves in the NODE table do not always persist after an update, while
225362181Sdim   the conflict resolver may need information about the pre-update state
226362181Sdim   of the move.
227251881Speter
228251881Speter   It is an error to add another tree conflict to a conflict skel that
229251881Speter   already contains a tree conflict.  (It is not an error, at this level,
230251881Speter   to add a tree conflict to an existing text or property conflict skel.)
231251881Speter
232251881Speter   Do temporary allocations in SCRATCH_POOL.
233251881Speter*/
234251881Spetersvn_error_t *
235251881Spetersvn_wc__conflict_skel_add_tree_conflict(svn_skel_t *conflict_skel,
236251881Speter                                        svn_wc__db_t *db,
237251881Speter                                        const char *wri_abspath,
238251881Speter                                        svn_wc_conflict_reason_t local_change,
239251881Speter                                        svn_wc_conflict_action_t incoming_change,
240251881Speter                                        const char *move_src_op_root_abspath,
241362181Sdim                                        const char *move_dst_op_root_abspath,
242251881Speter                                        apr_pool_t *result_pool,
243251881Speter                                        apr_pool_t *scratch_pool);
244251881Speter
245251881Speter/* Allows resolving specific conflicts stored in CONFLICT_SKEL.
246251881Speter
247251881Speter   When RESOLVE_TEXT is TRUE and CONFLICT_SKEL contains a text conflict,
248251881Speter   resolve/remove the text conflict in CONFLICT_SKEL.
249251881Speter
250251881Speter   When RESOLVE_PROP is "" and CONFLICT_SKEL contains a property conflict,
251251881Speter   resolve/remove all property conflicts in CONFLICT_SKEL.
252251881Speter
253251881Speter   When RESOLVE_PROP is not NULL and not "", remove the property conflict on
254251881Speter   the property RESOLVE_PROP in CONFLICT_SKEL. When RESOLVE_PROP was the last
255251881Speter   property in CONFLICT_SKEL remove the property conflict info from
256251881Speter   CONFLICT_SKEL.
257251881Speter
258251881Speter   When RESOLVE_TREE is TRUE and CONFLICT_SKEL contains a tree conflict,
259251881Speter   resolve/remove the tree conflict in CONFLICT_SKEL.
260251881Speter
261251881Speter   If COMPLETELY_RESOLVED is not NULL, then set *COMPLETELY_RESOLVED to TRUE,
262251881Speter   when no conflict registration is left in CONFLICT_SKEL after editting,
263251881Speter   otherwise to FALSE.
264251881Speter
265251881Speter   Allocate data stored in the skel in RESULT_POOL.
266251881Speter
267251881Speter   This functions edits CONFLICT_SKEL. New skels might be created in
268251881Speter   RESULT_POOL. Temporary allocations will use SCRATCH_POOL.
269251881Speter */
270251881Speter/* ### db, wri_abspath is currently unused. Remove? */
271251881Spetersvn_error_t *
272251881Spetersvn_wc__conflict_skel_resolve(svn_boolean_t *completely_resolved,
273251881Speter                              svn_skel_t *conflict_skel,
274251881Speter                              svn_wc__db_t *db,
275251881Speter                              const char *wri_abspath,
276251881Speter                              svn_boolean_t resolve_text,
277251881Speter                              const char *resolve_prop,
278251881Speter                              svn_boolean_t resolve_tree,
279251881Speter                              apr_pool_t *result_pool,
280251881Speter                              apr_pool_t *scratch_pool);
281251881Speter
282251881Speter/*
283251881Speter * -----------------------------------------------------------
284251881Speter * Reading conflict skels. Maybe this can be made private later
285251881Speter * -----------------------------------------------------------
286251881Speter */
287251881Speter
288251881Speter/* Read common information from CONFLICT_SKEL to determine the operation
289251881Speter * and merge origins.
290251881Speter *
291251881Speter * Output arguments can be NULL if the value is not necessary.
292251881Speter *
293251881Speter * Set *LOCATIONS to an array of (svn_wc_conflict_version_t *).  For
294251881Speter * conflicts written by current code, there are 2 elements: index [0] is
295251881Speter * the 'old' or 'left' side and [1] is the 'new' or 'right' side.
296251881Speter *
297251881Speter * For conflicts written by 1.6 or 1.7 there are 2 locations for a tree
298251881Speter * conflict, but none for a text or property conflict.
299251881Speter *
300251881Speter * TEXT_, PROP_ and TREE_CONFLICTED (when not NULL) will be set to TRUE
301251881Speter * when the conflict contains the specified kind of conflict, otherwise
302251881Speter * to false.
303251881Speter *
304251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
305251881Speter * SCRATCH_POOL.
306251881Speter */
307251881Spetersvn_error_t *
308251881Spetersvn_wc__conflict_read_info(svn_wc_operation_t *operation,
309251881Speter                           const apr_array_header_t **locations,
310251881Speter                           svn_boolean_t *text_conflicted,
311251881Speter                           svn_boolean_t *prop_conflicted,
312251881Speter                           svn_boolean_t *tree_conflicted,
313251881Speter                           svn_wc__db_t *db,
314251881Speter                           const char *wri_abspath,
315251881Speter                           const svn_skel_t *conflict_skel,
316251881Speter                           apr_pool_t *result_pool,
317251881Speter                           apr_pool_t *scratch_pool);
318251881Speter
319251881Speter/* Reads back the original data stored by svn_wc__conflict_skel_add_text_conflict()
320251881Speter * in CONFLICT_SKEL for a node in DB, WRI_ABSPATH.
321251881Speter *
322251881Speter * Values as documented for svn_wc__conflict_skel_add_text_conflict().
323251881Speter *
324251881Speter * Output arguments can be NULL if the value is not necessary.
325251881Speter *
326251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
327251881Speter * SCRATCH_POOL.
328251881Speter */
329251881Spetersvn_error_t *
330251881Spetersvn_wc__conflict_read_text_conflict(const char **mine_abspath,
331251881Speter                                    const char **their_old_abspath,
332251881Speter                                    const char **their_abspath,
333251881Speter                                    svn_wc__db_t *db,
334251881Speter                                    const char *wri_abspath,
335251881Speter                                    const svn_skel_t *conflict_skel,
336251881Speter                                    apr_pool_t *result_pool,
337251881Speter                                    apr_pool_t *scratch_pool);
338251881Speter
339251881Speter/* Reads back the original data stored by svn_wc__conflict_skel_add_prop_conflict()
340251881Speter * in CONFLICT_SKEL for a node in DB, WRI_ABSPATH.
341251881Speter *
342251881Speter * Values as documented for svn_wc__conflict_skel_add_prop_conflict().
343251881Speter *
344251881Speter * Output arguments can be NULL if the value is not necessary
345251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
346251881Speter * SCRATCH_POOL.
347251881Speter */
348251881Spetersvn_error_t *
349251881Spetersvn_wc__conflict_read_prop_conflict(const char **marker_abspath,
350251881Speter                                    apr_hash_t **mine_props,
351251881Speter                                    apr_hash_t **their_old_props,
352251881Speter                                    apr_hash_t **their_props,
353251881Speter                                    apr_hash_t **conflicted_prop_names,
354251881Speter                                    svn_wc__db_t *db,
355251881Speter                                    const char *wri_abspath,
356251881Speter                                    const svn_skel_t *conflict_skel,
357251881Speter                                    apr_pool_t *result_pool,
358251881Speter                                    apr_pool_t *scratch_pool);
359251881Speter
360251881Speter/* Reads back the original data stored by svn_wc__conflict_skel_add_tree_conflict()
361251881Speter * in CONFLICT_SKEL for a node in DB, WRI_ABSPATH.
362251881Speter *
363251881Speter * Values as documented for svn_wc__conflict_skel_add_tree_conflict().
364251881Speter *
365251881Speter * Output arguments can be NULL if the value is not necessary
366251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
367251881Speter * SCRATCH_POOL.
368251881Speter */
369251881Spetersvn_error_t *
370251881Spetersvn_wc__conflict_read_tree_conflict(svn_wc_conflict_reason_t *local_change,
371251881Speter                                    svn_wc_conflict_action_t *incoming_change,
372251881Speter                                    const char **move_src_op_root_abspath,
373362181Sdim                                    const char **move_dst_op_root_abspath,
374251881Speter                                    svn_wc__db_t *db,
375251881Speter                                    const char *wri_abspath,
376251881Speter                                    const svn_skel_t *conflict_skel,
377251881Speter                                    apr_pool_t *result_pool,
378251881Speter                                    apr_pool_t *scratch_pool);
379251881Speter
380251881Speter/* Reads in *MARKERS a list of const char * absolute paths of the marker files
381251881Speter   referenced from CONFLICT_SKEL.
382251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
383251881Speter * SCRATCH_POOL.
384251881Speter */
385251881Spetersvn_error_t *
386251881Spetersvn_wc__conflict_read_markers(const apr_array_header_t **markers,
387251881Speter                              svn_wc__db_t *db,
388251881Speter                              const char *wri_abspath,
389251881Speter                              const svn_skel_t *conflict_skel,
390251881Speter                              apr_pool_t *result_pool,
391251881Speter                              apr_pool_t *scratch_pool);
392251881Speter
393251881Speter/* Create the necessary marker files for the conflicts stored in
394251881Speter * CONFLICT_SKEL and return the work items to fill the markers from
395251881Speter * the work queue.
396251881Speter *
397251881Speter * Currently only used for property conflicts as text conflict markers
398251881Speter * are just in-wc files.
399251881Speter *
400251881Speter * Allocate the result in RESULT_POOL. Perform temporary allocations in
401251881Speter * SCRATCH_POOL.
402251881Speter */
403251881Spetersvn_error_t *
404251881Spetersvn_wc__conflict_create_markers(svn_skel_t **work_item,
405251881Speter                                svn_wc__db_t *db,
406251881Speter                                const char *local_abspath,
407251881Speter                                svn_skel_t *conflict_skel,
408251881Speter                                apr_pool_t *result_pool,
409251881Speter                                apr_pool_t *scratch_pool);
410251881Speter
411262250Speter/* Call the conflict resolver RESOLVER_FUNC with RESOLVER_BATON for each
412262250Speter   of the conflicts on LOCAL_ABSPATH.  Depending on the results that
413262250Speter   the callback returns, perhaps resolve the conflicts, and perhaps mark
414262250Speter   them as resolved in the WC DB.
415251881Speter
416251881Speter   Call RESOLVER_FUNC once for each property conflict, and again for any
417251881Speter   text conflict, and again for any tree conflict on the node.
418251881Speter
419251881Speter   CONFLICT_SKEL contains the details of the conflicts on LOCAL_ABSPATH.
420251881Speter
421262250Speter   Use MERGE_OPTIONS when the resolver requests a merge.
422262250Speter
423251881Speter   Resolver actions are directly applied to the in-db state of LOCAL_ABSPATH,
424251881Speter   so the conflict and the state in CONFLICT_SKEL must already be installed in
425251881Speter   wc.db. */
426251881Spetersvn_error_t *
427251881Spetersvn_wc__conflict_invoke_resolver(svn_wc__db_t *db,
428251881Speter                                 const char *local_abspath,
429289180Speter                                 svn_node_kind_t kind,
430251881Speter                                 const svn_skel_t *conflict_skel,
431251881Speter                                 const apr_array_header_t *merge_options,
432251881Speter                                 svn_wc_conflict_resolver_func2_t resolver_func,
433251881Speter                                 void *resolver_baton,
434251881Speter                                 svn_cancel_func_t cancel_func,
435251881Speter                                 void *cancel_baton,
436251881Speter                                 apr_pool_t *scratch_pool);
437251881Speter
438251881Speter
439251881Speter/* Mark as resolved any text conflict on the node at DB/LOCAL_ABSPATH.  */
440251881Spetersvn_error_t *
441251881Spetersvn_wc__mark_resolved_text_conflict(svn_wc__db_t *db,
442251881Speter                                    const char *local_abspath,
443289180Speter                                    svn_cancel_func_t cancel_func,
444289180Speter                                    void *cancel_baton,
445251881Speter                                    apr_pool_t *scratch_pool);
446251881Speter
447251881Speter/* Mark as resolved any prop conflicts on the node at DB/LOCAL_ABSPATH.  */
448251881Spetersvn_error_t *
449251881Spetersvn_wc__mark_resolved_prop_conflicts(svn_wc__db_t *db,
450251881Speter                                     const char *local_abspath,
451251881Speter                                     apr_pool_t *scratch_pool);
452251881Speter
453251881Speter#ifdef __cplusplus
454251881Speter}
455251881Speter#endif /* __cplusplus */
456251881Speter
457251881Speter#endif /* SVN_WC_CONFLICTS_H */
458