]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/libsvn_client/resolved.c
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / libsvn_client / resolved.c
1 /*
2  * resolved.c:  wrapper around wc resolved functionality.
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23
24 /* ==================================================================== */
25
26
27 \f
28 /*** Includes. ***/
29
30 #include "svn_types.h"
31 #include "svn_wc.h"
32 #include "svn_client.h"
33 #include "svn_error.h"
34 #include "svn_dirent_uri.h"
35 #include "svn_path.h"
36 #include "svn_pools.h"
37 #include "svn_hash.h"
38 #include "svn_sorts.h"
39 #include "client.h"
40 #include "private/svn_sorts_private.h"
41 #include "private/svn_wc_private.h"
42
43 #include "svn_private_config.h"
44 \f
45 /*** Code. ***/
46
47 svn_error_t *
48 svn_client__resolve_conflicts(svn_boolean_t *conflicts_remain,
49                               apr_hash_t *conflicted_paths,
50                               svn_client_ctx_t *ctx,
51                               apr_pool_t *scratch_pool)
52 {
53   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
54   apr_array_header_t *array;
55   int i;
56
57   if (conflicts_remain)
58     *conflicts_remain = FALSE;
59
60   SVN_ERR(svn_hash_keys(&array, conflicted_paths, scratch_pool));
61   svn_sort__array(array, svn_sort_compare_paths);
62
63   for (i = 0; i < array->nelts; i++)
64     {
65       const char *local_abspath = APR_ARRAY_IDX(array, i, const char *);
66
67       svn_pool_clear(iterpool);
68       SVN_ERR(svn_wc__resolve_conflicts(ctx->wc_ctx, local_abspath,
69                                         svn_depth_empty,
70                                         TRUE /* resolve_text */,
71                                         "" /* resolve_prop (ALL props) */,
72                                         TRUE /* resolve_tree */,
73                                         svn_wc_conflict_choose_unspecified,
74                                         ctx->conflict_func2,
75                                         ctx->conflict_baton2,
76                                         ctx->cancel_func, ctx->cancel_baton,
77                                         ctx->notify_func2, ctx->notify_baton2,
78                                         iterpool));
79
80       if (conflicts_remain && !*conflicts_remain)
81         {
82           svn_error_t *err;
83           svn_boolean_t text_c, prop_c, tree_c;
84
85           err = svn_wc_conflicted_p3(&text_c, &prop_c, &tree_c,
86                                      ctx->wc_ctx, local_abspath,
87                                      iterpool);
88           if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
89             {
90               svn_error_clear(err);
91               text_c = prop_c = tree_c = FALSE;
92             }
93           else
94             {
95               SVN_ERR(err);
96             }
97           if (text_c || prop_c || tree_c)
98             *conflicts_remain = TRUE;
99         }
100     }
101   svn_pool_destroy(iterpool);
102
103   return SVN_NO_ERROR;
104 }
105
106 svn_error_t *
107 svn_client_resolve(const char *path,
108                    svn_depth_t depth,
109                    svn_wc_conflict_choice_t conflict_choice,
110                    svn_client_ctx_t *ctx,
111                    apr_pool_t *pool)
112 {
113   const char *local_abspath;
114   svn_error_t *err;
115   const char *lock_abspath;
116
117   if (svn_path_is_url(path))
118     return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
119                              _("'%s' is not a local path"), path);
120
121   SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
122
123   /* Similar to SVN_WC__CALL_WITH_WRITE_LOCK but using a custom
124      locking function. */
125
126   SVN_ERR(svn_wc__acquire_write_lock_for_resolve(&lock_abspath, ctx->wc_ctx,
127                                                  local_abspath, pool, pool));
128   err = svn_wc__resolve_conflicts(ctx->wc_ctx, local_abspath,
129                                   depth,
130                                   TRUE /* resolve_text */,
131                                   "" /* resolve_prop (ALL props) */,
132                                   TRUE /* resolve_tree */,
133                                   conflict_choice,
134                                   ctx->conflict_func2,
135                                   ctx->conflict_baton2,
136                                   ctx->cancel_func, ctx->cancel_baton,
137                                   ctx->notify_func2, ctx->notify_baton2,
138                                   pool);
139
140   err = svn_error_compose_create(err, svn_wc__release_write_lock(ctx->wc_ctx,
141                                                                  lock_abspath,
142                                                                  pool));
143   svn_io_sleep_for_timestamps(path, pool);
144
145   return svn_error_trace(err);
146 }