2 * context.c: routines for managing a working copy context
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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
21 * ====================================================================
24 #include <apr_pools.h>
26 #include "svn_types.h"
27 #include "svn_pools.h"
28 #include "svn_dirent_uri.h"
34 #include "svn_private_config.h"
38 /* APR cleanup function used to explicitly close any of our dependent
39 data structures before we disappear ourselves. */
41 close_ctx_apr(void *data
)
43 svn_wc_context_t
*ctx
= data
;
45 if (ctx
->close_db_on_destroy
)
47 svn_error_t
*err
= svn_wc__db_close(ctx
->db
);
50 int result
= err
->apr_err
;
61 svn_wc_context_create(svn_wc_context_t
**wc_ctx
,
62 const svn_config_t
*config
,
63 apr_pool_t
*result_pool
,
64 apr_pool_t
*scratch_pool
)
66 svn_wc_context_t
*ctx
= apr_pcalloc(result_pool
, sizeof(*ctx
));
68 /* Create the state_pool, and open up a wc_db in it.
69 * Since config contains a private mutable member but C doesn't support
70 * we need to make it writable */
71 ctx
->state_pool
= result_pool
;
72 SVN_ERR(svn_wc__db_open(&ctx
->db
, (svn_config_t
*)config
,
73 FALSE
, TRUE
, ctx
->state_pool
, scratch_pool
));
74 ctx
->close_db_on_destroy
= TRUE
;
76 apr_pool_cleanup_register(result_pool
, ctx
, close_ctx_apr
,
77 apr_pool_cleanup_null
);
86 svn_wc__context_create_with_db(svn_wc_context_t
**wc_ctx
,
89 apr_pool_t
*result_pool
)
91 svn_wc_context_t
*ctx
= apr_pcalloc(result_pool
, sizeof(*ctx
));
93 /* Create the state pool. We don't put the wc_db in it, because it's
94 already open in a separate pool somewhere. We also won't close the
95 wc_db when we destroy the context, since it's not ours to close. */
96 ctx
->state_pool
= result_pool
;
98 ctx
->close_db_on_destroy
= FALSE
;
100 apr_pool_cleanup_register(result_pool
, ctx
, close_ctx_apr
,
101 apr_pool_cleanup_null
);
110 svn_wc_context_destroy(svn_wc_context_t
*wc_ctx
)
112 /* We added a cleanup when creating; just run it now to close the context. */
113 apr_pool_cleanup_run(wc_ctx
->state_pool
, wc_ctx
, close_ctx_apr
);