1 /* repos.h : interface to Subversion repository, private to libsvn_repos
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
23 #ifndef SVN_LIBSVN_REPOS_H
24 #define SVN_LIBSVN_REPOS_H
26 #include <apr_pools.h>
33 #endif /* __cplusplus */
36 /* Repository format number.
38 Formats 0, 1 and 2 were pre-1.0.
40 Format 3 was current for 1.0 through to 1.3.
42 Format 4 was an abortive experiment during the development of the
43 locking feature in the lead up to 1.2.
45 Format 5 was new in 1.4, and is the first format which may contain
46 BDB or FSFS filesystems with a FS format other than 1, since prior
47 formats are accepted by some versions of Subversion which do not
48 pay attention to the FS format number.
50 #define SVN_REPOS__FORMAT_NUMBER SVN_REPOS__FORMAT_NUMBER_1_4
51 #define SVN_REPOS__FORMAT_NUMBER_1_4 5
52 #define SVN_REPOS__FORMAT_NUMBER_LEGACY 3
55 /*** Repository layout. ***/
57 /* The top-level repository dir contains a README and various
59 #define SVN_REPOS__README "README.txt" /* Explanation for trespassers. */
60 #define SVN_REPOS__FORMAT "format" /* Stores the current version
62 #define SVN_REPOS__DB_DIR "db" /* Where Berkeley lives. */
63 #define SVN_REPOS__DAV_DIR "dav" /* DAV sandbox, for pre-1.5 */
64 #define SVN_REPOS__LOCK_DIR "locks" /* Lock files live here. */
65 #define SVN_REPOS__HOOK_DIR "hooks" /* Hook programs. */
66 #define SVN_REPOS__CONF_DIR "conf" /* Configuration files. */
68 /* Things for which we keep lockfiles. */
69 #define SVN_REPOS__DB_LOCKFILE "db.lock" /* Our Berkeley lockfile. */
70 #define SVN_REPOS__DB_LOGS_LOCKFILE "db-logs.lock" /* BDB logs lockfile. */
72 /* In the repository hooks directory, look for these files. */
73 #define SVN_REPOS__HOOK_START_COMMIT "start-commit"
74 #define SVN_REPOS__HOOK_PRE_COMMIT "pre-commit"
75 #define SVN_REPOS__HOOK_POST_COMMIT "post-commit"
76 #define SVN_REPOS__HOOK_READ_SENTINEL "read-sentinels"
77 #define SVN_REPOS__HOOK_WRITE_SENTINEL "write-sentinels"
78 #define SVN_REPOS__HOOK_PRE_REVPROP_CHANGE "pre-revprop-change"
79 #define SVN_REPOS__HOOK_POST_REVPROP_CHANGE "post-revprop-change"
80 #define SVN_REPOS__HOOK_PRE_LOCK "pre-lock"
81 #define SVN_REPOS__HOOK_POST_LOCK "post-lock"
82 #define SVN_REPOS__HOOK_PRE_UNLOCK "pre-unlock"
83 #define SVN_REPOS__HOOK_POST_UNLOCK "post-unlock"
86 /* The extension added to the names of example hook scripts. */
87 #define SVN_REPOS__HOOK_DESC_EXT ".tmpl"
89 /* The file which contains a custom set of environment variables
90 * passed inherited to hook scripts, in the repository conf directory. */
91 #define SVN_REPOS__CONF_HOOKS_ENV "hooks-env"
92 /* The name of the default section in the hooks-env config file. */
93 #define SVN_REPOS__HOOKS_ENV_DEFAULT_SECTION "default"
95 /* The configuration file for svnserve, in the repository conf directory. */
96 #define SVN_REPOS__CONF_SVNSERVE_CONF "svnserve.conf"
98 /* In the svnserve default configuration, these are the suggested
99 locations for the passwd, authz and groups files (in the repository
100 conf directory), and we put example templates there. */
101 #define SVN_REPOS__CONF_PASSWD "passwd"
102 #define SVN_REPOS__CONF_AUTHZ "authz"
103 #define SVN_REPOS__CONF_GROUPS "groups"
105 /* The Repository object, created by svn_repos_open2() and
106 svn_repos_create(). */
109 /* A Subversion filesystem object. */
112 /* The path to the repository's top-level directory. */
115 /* The path to the repository's conf directory. */
118 /* The path to the repository's hooks directory. */
121 /* The path to the repository's locks directory. */
124 /* The path to the Berkeley DB filesystem environment. */
127 /* The format number of this repository. */
130 /* The path to the repository's hooks enviroment file. If NULL, hooks run
131 * in an empty environment. */
132 const char *hooks_env_path;
134 /* The FS backend in use within this repository. */
137 /* If non-null, a list of all the capabilities the client (on the
138 current connection) has self-reported. Each element is a
139 'const char *', one of SVN_RA_CAPABILITY_*.
141 Note: it is somewhat counterintuitive that we store the client's
142 capabilities, which are session-specific, on the repository
143 object. You'd think the capabilities here would represent the
144 *repository's* capabilities, but no, they represent the
145 client's -- we just don't have any other place to persist them. */
146 const apr_array_header_t *client_capabilities;
148 /* Maps SVN_REPOS_CAPABILITY_foo keys to "yes" or "no" values.
149 If a capability is not yet discovered, it is absent from the table.
150 Most likely the keys and values are constants anyway (and
151 sufficiently well-informed internal code may just compare against
152 those constants' addresses, therefore). */
153 apr_hash_t *repository_capabilities;
155 /* Pool from which this structure was allocated. Also used for
156 auxiliary repository-related data that requires a matching
157 lifespan. (As the svn_repos_t structure tends to be relatively
158 long-lived, please be careful regarding this pool's usage.) */
163 /*** Hook-running Functions ***/
165 /* Set *HOOKS_ENV_P to the parsed contents of the hooks-env file
166 LOCAL_ABSPATH, allocated in RESULT_POOL. (This result is suitable
167 for delivery to the various hook wrapper functions which accept a
168 'hooks_env' parameter.) If LOCAL_ABSPATH is NULL, set *HOOKS_ENV_P
171 Use SCRATCH_POOL for temporary allocations. */
173 svn_repos__parse_hooks_env(apr_hash_t **hooks_env_p,
174 const char *local_abspath,
175 apr_pool_t *result_pool,
176 apr_pool_t *scratch_pool);
178 /* Run the start-commit hook for REPOS. Use POOL for any temporary
179 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
181 HOOKS_ENV is a hash of hook script environment information returned
182 via svn_repos__parse_hooks_env() (or NULL if no such information is
185 USER is the authenticated name of the user starting the commit.
187 CAPABILITIES is a list of 'const char *' capability names (using
188 SVN_RA_CAPABILITY_*) that the client has self-reported. Note that
189 there is no guarantee the client is telling the truth: the hook
190 should not make security assumptions based on the capabilities.
192 TXN_NAME is the name of the commit transaction that's just been
195 svn_repos__hooks_start_commit(svn_repos_t *repos,
196 apr_hash_t *hooks_env,
198 const apr_array_header_t *capabilities,
199 const char *txn_name,
202 /* Run the pre-commit hook for REPOS. Use POOL for any temporary
203 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
205 HOOKS_ENV is a hash of hook script environment information returned
206 via svn_repos__parse_hooks_env() (or NULL if no such information is
209 TXN_NAME is the name of the transaction that is being committed. */
211 svn_repos__hooks_pre_commit(svn_repos_t *repos,
212 apr_hash_t *hooks_env,
213 const char *txn_name,
216 /* Run the post-commit hook for REPOS. Use POOL for any temporary
217 allocations. If the hook fails, run SVN_ERR_REPOS_HOOK_FAILURE.
219 HOOKS_ENV is a hash of hook script environment information returned
220 via svn_repos__parse_hooks_env() (or NULL if no such information is
223 REV is the revision that was created as a result of the commit. */
225 svn_repos__hooks_post_commit(svn_repos_t *repos,
226 apr_hash_t *hooks_env,
228 const char *txn_name,
231 /* Run the pre-revprop-change hook for REPOS. Use POOL for any
232 temporary allocations. If the hook fails, return
233 SVN_ERR_REPOS_HOOK_FAILURE.
235 HOOKS_ENV is a hash of hook script environment information returned
236 via svn_repos__parse_hooks_env() (or NULL if no such information is
239 REV is the revision whose property is being changed.
240 AUTHOR is the authenticated name of the user changing the prop.
241 NAME is the name of the property being changed.
242 NEW_VALUE is the new value of the property.
243 ACTION is indicates if the property is being 'A'dded, 'M'odified,
246 The pre-revprop-change hook will have the new property value
247 written to its stdin. If the property is being deleted, no data
250 svn_repos__hooks_pre_revprop_change(svn_repos_t *repos,
251 apr_hash_t *hooks_env,
255 const svn_string_t *new_value,
259 /* Run the pre-revprop-change hook for REPOS. Use POOL for any
260 temporary allocations. If the hook fails, return
261 SVN_ERR_REPOS_HOOK_FAILURE.
263 HOOKS_ENV is a hash of hook script environment information returned
264 via svn_repos__parse_hooks_env() (or NULL if no such information is
267 REV is the revision whose property was changed.
268 AUTHOR is the authenticated name of the user who changed the prop.
269 NAME is the name of the property that was changed, and OLD_VALUE is
270 that property's value immediately before the change, or null if
271 none. ACTION indicates if the property was 'A'dded, 'M'odified,
274 The old value will be passed to the post-revprop hook on stdin. If
275 the property is being created, no data will be written. */
277 svn_repos__hooks_post_revprop_change(svn_repos_t *repos,
278 apr_hash_t *hooks_env,
282 const svn_string_t *old_value,
286 /* Run the pre-lock hook for REPOS. Use POOL for any temporary
287 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
289 HOOKS_ENV is a hash of hook script environment information returned
290 via svn_repos__parse_hooks_env() (or NULL if no such information is
293 PATH is the path being locked, USERNAME is the person doing it,
294 COMMENT is the comment of the lock, and is treated as an empty
295 string when NULL is given. STEAL-LOCK is a flag if the user is
298 If TOKEN is non-null, set *TOKEN to a new lock token generated by
299 the pre-lock hook, if any (see the pre-lock hook template for more
300 information). If TOKEN is non-null but the hook does not return
301 any token, then set *TOKEN to empty string. */
304 svn_repos__hooks_pre_lock(svn_repos_t *repos,
305 apr_hash_t *hooks_env,
308 const char *username,
310 svn_boolean_t steal_lock,
313 /* Run the post-lock hook for REPOS. Use POOL for any temporary
314 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
316 HOOKS_ENV is a hash of hook script environment information returned
317 via svn_repos__parse_hooks_env() (or NULL if no such information is
320 PATHS is an array of paths being locked, USERNAME is the person
323 svn_repos__hooks_post_lock(svn_repos_t *repos,
324 apr_hash_t *hooks_env,
325 const apr_array_header_t *paths,
326 const char *username,
329 /* Run the pre-unlock hook for REPOS. Use POOL for any temporary
330 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
332 HOOKS_ENV is a hash of hook script environment information returned
333 via svn_repos__parse_hooks_env() (or NULL if no such information is
336 PATH is the path being unlocked, USERNAME is the person doing it,
337 TOKEN is the lock token to be unlocked which should not be NULL,
338 and BREAK-LOCK is a flag if the user is breaking the lock. */
340 svn_repos__hooks_pre_unlock(svn_repos_t *repos,
341 apr_hash_t *hooks_env,
343 const char *username,
345 svn_boolean_t break_lock,
348 /* Run the post-unlock hook for REPOS. Use POOL for any temporary
349 allocations. If the hook fails, return SVN_ERR_REPOS_HOOK_FAILURE.
351 HOOKS_ENV is a hash of hook script environment information returned
352 via svn_repos__parse_hooks_env() (or NULL if no such information is
355 PATHS is an array of paths being unlocked, USERNAME is the person
358 svn_repos__hooks_post_unlock(svn_repos_t *repos,
359 apr_hash_t *hooks_env,
360 const apr_array_header_t *paths,
361 const char *username,
365 /*** Authz Functions ***/
367 /* Read authz configuration data from PATH into *AUTHZ_P, allocated
368 in POOL. If GROUPS_PATH is set, use the global groups parsed from it.
370 PATH and GROUPS_PATH may be a dirent or a registry path and iff ACCEPT_URLS
371 is set it may also be an absolute file url.
373 If PATH or GROUPS_PATH is not a valid authz rule file, then return
374 SVN_AUTHZ_INVALID_CONFIG. The contents of *AUTHZ_P is then
375 undefined. If MUST_EXIST is TRUE, a missing authz or global groups file
378 svn_repos__authz_read(svn_authz_t **authz_p,
380 const char *groups_path,
381 svn_boolean_t must_exist,
382 svn_boolean_t accept_urls,
385 /* Walk the configuration in AUTHZ looking for any errors. */
387 svn_repos__authz_validate(svn_authz_t *authz,
391 /*** Utility Functions ***/
393 /* Set *CHANGED_P to TRUE if ROOT1/PATH1 and ROOT2/PATH2 have
394 different contents, FALSE if they have the same contents.
395 Use POOL for temporary allocation. */
397 svn_repos__compare_files(svn_boolean_t *changed_p,
398 svn_fs_root_t *root1,
400 svn_fs_root_t *root2,
404 /* Set *PREV_PATH and *PREV_REV to the path and revision which
405 represent the location at which PATH in FS was located immediately
406 prior to REVISION iff there was a copy operation (to PATH or one of
407 its parent directories) between that previous location and
408 PATH@REVISION, and set *APPEARED_REV to the first revision in which
409 PATH@REVISION appeared at PATH as a result of that copy operation.
411 If there was no such copy operation in that portion
412 of PATH's history, set *PREV_PATH to NULL, and set *PREV_REV and
413 *APPEARED_REV to SVN_INVALID_REVNUM.
415 NOTE: Any of PREV_PATH, PREV_REV, and APPEARED_REV may be NULL to
416 if that information is of no interest to the caller. */
418 svn_repos__prev_location(svn_revnum_t *appeared_rev,
419 const char **prev_path,
420 svn_revnum_t *prev_rev,
422 svn_revnum_t revision,
428 #endif /* __cplusplus */
430 #endif /* SVN_LIBSVN_REPOS_H */