]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/subversion/subversion/libsvn_client/ctx.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / subversion / subversion / libsvn_client / ctx.c
1 /*
2  * ctx.c:  initialization function for client context
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 <apr_pools.h>
31 #include "svn_hash.h"
32 #include "svn_client.h"
33 #include "svn_error.h"
34
35 #include "private/svn_wc_private.h"
36
37 \f
38 /*** Code. ***/
39
40 /* Call the notify_func of the context provided by BATON, if non-NULL. */
41 static void
42 call_notify_func(void *baton, const svn_wc_notify_t *n, apr_pool_t *pool)
43 {
44   const svn_client_ctx_t *ctx = baton;
45
46   if (ctx->notify_func)
47     ctx->notify_func(ctx->notify_baton, n->path, n->action, n->kind,
48                      n->mime_type, n->content_state, n->prop_state,
49                      n->revision);
50 }
51
52 static svn_error_t *
53 call_conflict_func(svn_wc_conflict_result_t **result,
54                    const svn_wc_conflict_description2_t *conflict,
55                    void *baton,
56                    apr_pool_t *result_pool,
57                    apr_pool_t *scratch_pool)
58 {
59   svn_client_ctx_t *ctx = baton;
60
61   if (ctx->conflict_func)
62     {
63       const svn_wc_conflict_description_t *cd;
64
65       cd = svn_wc__cd2_to_cd(conflict, scratch_pool);
66       SVN_ERR(ctx->conflict_func(result, cd, ctx->conflict_baton,
67                                  result_pool));
68     }
69   else
70     {
71       /* We have to set a result; so we postpone */
72       *result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone,
73                                               NULL, result_pool);
74     }
75
76   return SVN_NO_ERROR;
77 }
78
79 svn_error_t *
80 svn_client_create_context2(svn_client_ctx_t **ctx,
81                            apr_hash_t *cfg_hash,
82                            apr_pool_t *pool)
83 {
84   svn_config_t *cfg_config;
85
86   *ctx = apr_pcalloc(pool, sizeof(svn_client_ctx_t));
87
88   (*ctx)->notify_func2 = call_notify_func;
89   (*ctx)->notify_baton2 = *ctx;
90
91   (*ctx)->conflict_func2 = call_conflict_func;
92   (*ctx)->conflict_baton2 = *ctx;
93
94   (*ctx)->config = cfg_hash;
95
96   if (cfg_hash)
97     cfg_config = svn_hash_gets(cfg_hash, SVN_CONFIG_CATEGORY_CONFIG);
98   else
99     cfg_config = NULL;
100
101   SVN_ERR(svn_wc_context_create(&(*ctx)->wc_ctx, cfg_config, pool,
102                                 pool));
103
104   return SVN_NO_ERROR;
105 }
106
107 svn_error_t *
108 svn_client_create_context(svn_client_ctx_t **ctx,
109                           apr_pool_t *pool)
110 {
111   return svn_client_create_context2(ctx, NULL, pool);
112 }