ctx.c revision 299742
1235429Sdelphij/* 2235429Sdelphij * ctx.c: initialization function for client context 3235429Sdelphij * 4235429Sdelphij * ==================================================================== 5235429Sdelphij * Licensed to the Apache Software Foundation (ASF) under one 6235429Sdelphij * or more contributor license agreements. See the NOTICE file 7235429Sdelphij * distributed with this work for additional information 8235429Sdelphij * regarding copyright ownership. The ASF licenses this file 9235429Sdelphij * to you under the Apache License, Version 2.0 (the 10235429Sdelphij * "License"); you may not use this file except in compliance 11235429Sdelphij * with the License. You may obtain a copy of the License at 12235429Sdelphij * 13235429Sdelphij * http://www.apache.org/licenses/LICENSE-2.0 14235429Sdelphij * 15235429Sdelphij * Unless required by applicable law or agreed to in writing, 16235429Sdelphij * software distributed under the License is distributed on an 17235429Sdelphij * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18235429Sdelphij * KIND, either express or implied. See the License for the 19235429Sdelphij * specific language governing permissions and limitations 20235429Sdelphij * under the License. 21235429Sdelphij * ==================================================================== 22235429Sdelphij */ 23235429Sdelphij 24235429Sdelphij/* ==================================================================== */ 25235429Sdelphij 26235429Sdelphij 27235429Sdelphij 28235429Sdelphij/*** Includes. ***/ 29235429Sdelphij 30235429Sdelphij#include <stddef.h> 31235429Sdelphij#include <apr_pools.h> 32235429Sdelphij#include "svn_hash.h" 33235429Sdelphij#include "svn_client.h" 34235429Sdelphij#include "svn_error.h" 35235429Sdelphij 36235429Sdelphij#include "private/svn_wc_private.h" 37235429Sdelphij 38235429Sdelphij#include "client.h" 39235429Sdelphij 40235429Sdelphij 41235429Sdelphij/*** Code. ***/ 42235429Sdelphij 43235429Sdelphij/* Call the notify_func of the context provided by BATON, if non-NULL. */ 44235429Sdelphijstatic void 45235429Sdelphijcall_notify_func(void *baton, const svn_wc_notify_t *n, apr_pool_t *pool) 46235429Sdelphij{ 47235429Sdelphij const svn_client_ctx_t *ctx = baton; 48235429Sdelphij 49235429Sdelphij if (ctx->notify_func) 50235429Sdelphij ctx->notify_func(ctx->notify_baton, n->path, n->action, n->kind, 51235429Sdelphij n->mime_type, n->content_state, n->prop_state, 52235429Sdelphij n->revision); 53235429Sdelphij} 54235429Sdelphij 55235429Sdelphijstatic svn_error_t * 56235429Sdelphijcall_conflict_func(svn_wc_conflict_result_t **result, 57235429Sdelphij const svn_wc_conflict_description2_t *conflict, 58235429Sdelphij void *baton, 59235429Sdelphij apr_pool_t *result_pool, 60235429Sdelphij apr_pool_t *scratch_pool) 61235429Sdelphij{ 62235429Sdelphij svn_client_ctx_t *ctx = baton; 63235429Sdelphij 64235429Sdelphij if (ctx->conflict_func) 65235429Sdelphij { 66235429Sdelphij const svn_wc_conflict_description_t *cd; 67235429Sdelphij 68235429Sdelphij cd = svn_wc__cd2_to_cd(conflict, scratch_pool); 69235429Sdelphij SVN_ERR(ctx->conflict_func(result, cd, ctx->conflict_baton, 70235429Sdelphij result_pool)); 71 } 72 else 73 { 74 /* We have to set a result; so we postpone */ 75 *result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone, 76 NULL, result_pool); 77 } 78 79 return SVN_NO_ERROR; 80} 81 82/* The magic number in client_ctx_t.magic_id. */ 83#define CLIENT_CTX_MAGIC APR_UINT64_C(0xDEADBEEF600DF00D) 84 85svn_client__private_ctx_t * 86svn_client__get_private_ctx(svn_client_ctx_t *ctx) 87{ 88 svn_client__private_ctx_t *const private_ctx = 89 (void*)((char *)ctx - offsetof(svn_client__private_ctx_t, public_ctx)); 90 SVN_ERR_ASSERT_NO_RETURN(&private_ctx->public_ctx == ctx); 91 SVN_ERR_ASSERT_NO_RETURN(0 == private_ctx->magic_null); 92 SVN_ERR_ASSERT_NO_RETURN(CLIENT_CTX_MAGIC == private_ctx->magic_id); 93 return private_ctx; 94} 95 96svn_error_t * 97svn_client_create_context2(svn_client_ctx_t **ctx, 98 apr_hash_t *cfg_hash, 99 apr_pool_t *pool) 100{ 101 svn_config_t *cfg_config; 102 103 svn_client__private_ctx_t *const private_ctx = 104 apr_pcalloc(pool, sizeof(*private_ctx)); 105 svn_client_ctx_t *const public_ctx = &private_ctx->public_ctx; 106 107 private_ctx->magic_null = 0; 108 private_ctx->magic_id = CLIENT_CTX_MAGIC; 109 110 public_ctx->notify_func2 = call_notify_func; 111 public_ctx->notify_baton2 = public_ctx; 112 113 public_ctx->conflict_func2 = call_conflict_func; 114 public_ctx->conflict_baton2 = public_ctx; 115 116 public_ctx->config = cfg_hash; 117 118 if (cfg_hash) 119 cfg_config = svn_hash_gets(cfg_hash, SVN_CONFIG_CATEGORY_CONFIG); 120 else 121 cfg_config = NULL; 122 123 SVN_ERR(svn_wc_context_create(&public_ctx->wc_ctx, cfg_config, 124 pool, pool)); 125 *ctx = public_ctx; 126 127 return SVN_NO_ERROR; 128} 129 130svn_error_t * 131svn_client_create_context(svn_client_ctx_t **ctx, 132 apr_pool_t *pool) 133{ 134 return svn_client_create_context2(ctx, NULL, pool); 135} 136