155714Skris/* 2280297Sjkim * ctx.c: initialization function for client context 3280297Sjkim * 4280297Sjkim * ==================================================================== 555714Skris * Licensed to the Apache Software Foundation (ASF) under one 655714Skris * or more contributor license agreements. See the NOTICE file 755714Skris * distributed with this work for additional information 855714Skris * regarding copyright ownership. The ASF licenses this file 955714Skris * to you under the Apache License, Version 2.0 (the 1055714Skris * "License"); you may not use this file except in compliance 1155714Skris * with the License. You may obtain a copy of the License at 1255714Skris * 1355714Skris * http://www.apache.org/licenses/LICENSE-2.0 14280297Sjkim * 1555714Skris * Unless required by applicable law or agreed to in writing, 1655714Skris * software distributed under the License is distributed on an 1755714Skris * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1855714Skris * KIND, either express or implied. See the License for the 1955714Skris * specific language governing permissions and limitations 2055714Skris * under the License. 2155714Skris * ==================================================================== 2255714Skris */ 2355714Skris 2455714Skris/* ==================================================================== */ 2555714Skris 2655714Skris 2755714Skris 2855714Skris/*** Includes. ***/ 2955714Skris 3055714Skris#include <stddef.h> 3155714Skris#include <apr_pools.h> 3255714Skris#include "svn_hash.h" 3355714Skris#include "svn_client.h" 3455714Skris#include "svn_error.h" 3555714Skris 3655714Skris#include "private/svn_wc_private.h" 3755714Skris 3855714Skris#include "client.h" 3955714Skris 4055714Skris 4155714Skris/*** Code. ***/ 4255714Skris 4355714Skris/* Call the notify_func of the context provided by BATON, if non-NULL. */ 4455714Skrisstatic void 4555714Skriscall_notify_func(void *baton, const svn_wc_notify_t *n, apr_pool_t *pool) 4655714Skris{ 4755714Skris const svn_client_ctx_t *ctx = baton; 4855714Skris 4955714Skris if (ctx->notify_func) 5055714Skris ctx->notify_func(ctx->notify_baton, n->path, n->action, n->kind, 5155714Skris n->mime_type, n->content_state, n->prop_state, 5255714Skris n->revision); 5355714Skris} 5455714Skris 5555714Skrisstatic svn_error_t * 5655714Skriscall_conflict_func(svn_wc_conflict_result_t **result, 5755714Skris const svn_wc_conflict_description2_t *conflict, 5855714Skris void *baton, 5955714Skris apr_pool_t *result_pool, 6055714Skris apr_pool_t *scratch_pool) 6159191Skris{ 6255714Skris svn_client_ctx_t *ctx = baton; 6355714Skris 6455714Skris if (ctx->conflict_func) 6555714Skris { 6655714Skris const svn_wc_conflict_description_t *cd; 6755714Skris 6855714Skris cd = svn_wc__cd2_to_cd(conflict, scratch_pool); 6959191Skris SVN_ERR(ctx->conflict_func(result, cd, ctx->conflict_baton, 7055714Skris result_pool)); 7155714Skris } 72280297Sjkim else 73280297Sjkim { 74280297Sjkim /* We have to set a result; so we postpone */ 75280297Sjkim *result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone, 76280297Sjkim NULL, result_pool); 77280297Sjkim } 78280297Sjkim 79280297Sjkim return SVN_NO_ERROR; 80280297Sjkim} 81280297Sjkim 82280297Sjkim/* The magic number in client_ctx_t.magic_id. */ 83280297Sjkim#define CLIENT_CTX_MAGIC APR_UINT64_C(0xDEADBEEF600DF00D) 84280297Sjkim 85280297Sjkimsvn_client__private_ctx_t * 86280297Sjkimsvn_client__get_private_ctx(svn_client_ctx_t *ctx) 87280297Sjkim{ 88280297Sjkim svn_client__private_ctx_t *const private_ctx = 89280297Sjkim (void*)((char *)ctx - offsetof(svn_client__private_ctx_t, public_ctx)); 90280297Sjkim SVN_ERR_ASSERT_NO_RETURN(&private_ctx->public_ctx == ctx); 91109998Smarkm SVN_ERR_ASSERT_NO_RETURN(0 == private_ctx->magic_null); 92280297Sjkim SVN_ERR_ASSERT_NO_RETURN(CLIENT_CTX_MAGIC == private_ctx->magic_id); 93280297Sjkim return private_ctx; 94109998Smarkm} 95280297Sjkim 96280297Sjkimsvn_error_t * 97109998Smarkmsvn_client_create_context2(svn_client_ctx_t **ctx, 98280297Sjkim apr_hash_t *cfg_hash, 99280297Sjkim apr_pool_t *pool) 100109998Smarkm{ 101280297Sjkim svn_config_t *cfg_config; 102280297Sjkim 103280297Sjkim svn_client__private_ctx_t *const private_ctx = 104280297Sjkim apr_pcalloc(pool, sizeof(*private_ctx)); 105280297Sjkim svn_client_ctx_t *const public_ctx = &private_ctx->public_ctx; 106280297Sjkim 107280297Sjkim private_ctx->magic_null = 0; 108280297Sjkim private_ctx->magic_id = CLIENT_CTX_MAGIC; 109280297Sjkim 110280297Sjkim public_ctx->notify_func2 = call_notify_func; 111280297Sjkim public_ctx->notify_baton2 = public_ctx; 112280297Sjkim 113280297Sjkim public_ctx->conflict_func2 = call_conflict_func; 114280297Sjkim public_ctx->conflict_baton2 = public_ctx; 115280297Sjkim 116280297Sjkim public_ctx->config = cfg_hash; 117280297Sjkim 118280297Sjkim if (cfg_hash) 119280297Sjkim cfg_config = svn_hash_gets(cfg_hash, SVN_CONFIG_CATEGORY_CONFIG); 120280297Sjkim else 121280297Sjkim cfg_config = NULL; 122280297Sjkim 123280297Sjkim SVN_ERR(svn_wc_context_create(&public_ctx->wc_ctx, cfg_config, 124280297Sjkim pool, pool)); 125290207Sjkim *ctx = public_ctx; 126290207Sjkim 127290207Sjkim return SVN_NO_ERROR; 128290207Sjkim} 129290207Sjkim 130290207Sjkimsvn_error_t * 131290207Sjkimsvn_client_create_context(svn_client_ctx_t **ctx, 132290207Sjkim apr_pool_t *pool) 133290207Sjkim{ 134290207Sjkim return svn_client_create_context2(ctx, NULL, pool); 135280297Sjkim} 136280297Sjkim