~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/include/svn_path.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
5
 *
 
6
 * This software is licensed as described in the file COPYING, which
 
7
 * you should have received as part of this distribution.  The terms
 
8
 * are also available at http://subversion.tigris.org/license-1.html.
 
9
 * If newer versions of this license are posted there, you may use a
 
10
 * newer version instead, at your option.
 
11
 *
 
12
 * This software consists of voluntary contributions made by many
 
13
 * individuals.  For exact contribution history, see the revision
 
14
 * history and logs, available at http://subversion.tigris.org/.
 
15
 * ====================================================================
 
16
 * @endcopyright
 
17
 *
 
18
 * @file svn_path.h
 
19
 * @brief A path manipulation library
 
20
 *
 
21
 * All incoming and outgoing paths are non-null and in UTF-8, unless
 
22
 * otherwise documented.
 
23
 * 
 
24
 * No result path ever ends with a separator, no matter whether the
 
25
 * path is a file or directory, because we always canonicalize() it.
 
26
 *
 
27
 * All paths passed to the @c svn_path_xxx functions, with the exceptions of
 
28
 * the @c svn_path_canonicalize and @c svn_path_internal_style functions, must
 
29
 * be in canonical form.
 
30
 */
 
31
 
 
32
#ifndef SVN_PATH_H
 
33
#define SVN_PATH_H
 
34
 
 
35
 
 
36
#include <apr_pools.h>
 
37
#include <apr_tables.h>
 
38
 
 
39
#include "svn_string.h"
 
40
#include "svn_error.h"
 
41
 
 
42
 
 
43
#ifdef __cplusplus
 
44
extern "C" {
 
45
#endif /* __cplusplus */
 
46
 
 
47
 
 
48
 
 
49
/** Convert @a path from the local style to the canonical internal style. */
 
50
const char *svn_path_internal_style (const char *path, apr_pool_t *pool);
 
51
 
 
52
/** Convert @a path from the canonical internal style to the local style. */
 
53
const char *svn_path_local_style (const char *path, apr_pool_t *pool);
 
54
 
 
55
 
 
56
/** Join a base path (@a base) with a component (@a component), allocated in 
 
57
 * @a pool.
 
58
 *
 
59
 * If either @a base or @a component is the empty path, then the other 
 
60
 * argument will be copied and returned.  If both are the empty path the 
 
61
 * empty path is returned.
 
62
 *
 
63
 * If the @a component is an absolute path, then it is copied and returned.
 
64
 * Exactly one slash character ('/') is used to joined the components,
 
65
 * accounting for any trailing slash in @a base.
 
66
 *
 
67
 * Note that the contents of @a base are not examined, so it is possible to
 
68
 * use this function for constructing URLs, or for relative URLs or
 
69
 * repository paths.
 
70
 *
 
71
 * This function is NOT appropriate for native (local) file
 
72
 * paths. Only for "internal" canonicalized paths, since it uses '/'
 
73
 * for the separator. Further, an absolute path (for @a component) is
 
74
 * based on a leading '/' character.  Thus, an "absolute URI" for the
 
75
 * @a component won't be detected. An absolute URI can only be used
 
76
 * for the base.
 
77
 */
 
78
char *svn_path_join (const char *base,
 
79
                     const char *component,
 
80
                     apr_pool_t *pool);
 
81
 
 
82
/** Join multiple components onto a @a base path, allocated in @a pool. The
 
83
 * components are terminated by a @c NULL.
 
84
 *
 
85
 * If any component is the empty string, it will be ignored.
 
86
 *
 
87
 * If any component is an absolute path, then it resets the base and
 
88
 * further components will be appended to it.
 
89
 *
 
90
 * See @c svn_path_join() for further notes about joining paths.
 
91
 */
 
92
char *svn_path_join_many (apr_pool_t *pool, const char *base, ...);
 
93
 
 
94
 
 
95
/** Get the basename of the specified canonicalized @a path.  The
 
96
 * basename is defined as the last component of the path (ignoring any
 
97
 * trailing slashes).  If the @a path is root ("/"), then that is
 
98
 * returned.  Otherwise, the returned value will have no slashes in
 
99
 * it.
 
100
 *
 
101
 * Example: svn_path_basename("/foo/bar") -> "bar"
 
102
 *
 
103
 * The returned basename will be allocated in @a pool.
 
104
 *
 
105
 * Note: if an empty string is passed, then an empty string will be returned.
 
106
 */
 
107
char *svn_path_basename (const char *path, apr_pool_t *pool);
 
108
 
 
109
/** Get the dirname of the specified canonicalized @a path, defined as
 
110
 * the path with its basename removed.
 
111
 *
 
112
 * Get the dirname of the specified @a path, defined as the path with its
 
113
 * basename removed.  If @a path is root ("/"), it is returned unchanged.
 
114
 *
 
115
 * The returned dirname will be allocated in @a pool.
 
116
 */
 
117
char *svn_path_dirname (const char *path, apr_pool_t *pool);
 
118
 
 
119
/** Return the number of components in the canonicalized @a path. */
 
120
apr_size_t
 
121
svn_path_component_count (const char *path);
 
122
 
 
123
/** Add a @a component (a null-terminated C-string) to the
 
124
 * canonicalized @a path.  @a component is allowed to contain
 
125
 * directory separators.
 
126
 *
 
127
 * If @a path is non-empty, append the appropriate directory separator
 
128
 * character, and then @a component.  If @a path is empty, simply set it to
 
129
 * @a component; don't add any separator character.
 
130
 *
 
131
 * If the result ends in a separator character, then remove the separator.
 
132
 */
 
133
void svn_path_add_component (svn_stringbuf_t *path, 
 
134
                             const char *component);
 
135
 
 
136
/** Remove one component off the end of the canonicalized @a path. */
 
137
void svn_path_remove_component (svn_stringbuf_t *path);
 
138
 
 
139
/** Remove @a n components off the end of the canonizalized @a path.
 
140
 * Equivalent to calling @c svn_remove_component @a n times. */
 
141
void svn_path_remove_components (svn_stringbuf_t *path, apr_size_t n);
 
142
 
 
143
/** Divide the canonicalized @a path into @a *dirpath and @a
 
144
 * *base_name, allocated in @a pool.
 
145
 *
 
146
 * If @a dirpath or @a base_name is null, then don't set that one.
 
147
 *
 
148
 * Either @a dirpath or @a base_name may be @a path's own address, but they 
 
149
 * may not both be the same address, or the results are undefined.
 
150
 *
 
151
 * If @a path has two or more components, the separator between @a dirpath
 
152
 * and @a base_name is not included in either of the new names.
 
153
 *
 
154
 *   examples:
 
155
 *             - <pre>"/foo/bar/baz"  ==>  "/foo/bar" and "baz"</pre>
 
156
 *             - <pre>"/bar"          ==>  "/"  and "bar"</pre>
 
157
 *             - <pre>"/"             ==>  "/"  and "/"</pre>
 
158
 *             - <pre>"bar"           ==>  ""   and "bar"</pre>
 
159
 *             - <pre>""              ==>  ""   and ""</pre>
 
160
 */
 
161
void svn_path_split (const char *path, 
 
162
                     const char **dirpath,
 
163
                     const char **base_name,
 
164
                     apr_pool_t *pool);
 
165
 
 
166
 
 
167
/** Return non-zero iff @a path is empty ("") or represents the current
 
168
 * directory -- that is, if prepending it as a component to an existing
 
169
 * path would result in no meaningful change.
 
170
 */
 
171
int svn_path_is_empty (const char *path);
 
172
 
 
173
 
 
174
/** Return a new path (or URL) like @a path, but transformed such that
 
175
 * some types of path specification redundancies are removed.
 
176
 *
 
177
 * This involves collapsing redundant "/./" elements, removing
 
178
 * multiple adjacent separator characters, removing trailing
 
179
 * separator characters, and possibly other semantically inoperative
 
180
 * transformations.
 
181
 *
 
182
 * The returned path may be statically allocated, equal to @a path, or
 
183
 * allocated from @a pool.
 
184
 */
 
185
const char *svn_path_canonicalize (const char *path, apr_pool_t *pool);
 
186
 
 
187
 
 
188
/** Return an integer greater than, equal to, or less than 0, according
 
189
 * as @a path1 is greater than, equal to, or less than @a path2.
 
190
 */
 
191
int svn_path_compare_paths (const char *path1, const char *path2);
 
192
 
 
193
 
 
194
/** Return the longest common path shared by two canonicalized paths,
 
195
 * @a path1 and @a path2.  If there's no common ancestor, return the
 
196
 * empty path.
 
197
 *
 
198
 * @a path1 and @a path2 may be URLs.  In order for two URLs to have 
 
199
 * a common ancestor, they must (a) have the same protocol (since two URLs 
 
200
 * with the same path but different protocols may point at completely 
 
201
 * different resources), and (b) share a common ancestor in their path 
 
202
 * component, i.e. 'protocol://' is not a sufficient ancestor.
 
203
 */
 
204
char *svn_path_get_longest_ancestor (const char *path1,
 
205
                                     const char *path2,
 
206
                                     apr_pool_t *pool);
 
207
 
 
208
/** Convert @a relative canonicalized path to an absolute path and
 
209
 * return the results in @a *pabsolute, allocated in @a pool.
 
210
 *
 
211
 * @a relative may be a URL, in which case no attempt is made to convert it, 
 
212
 * and a copy of the URL is returned. 
 
213
 */
 
214
svn_error_t *
 
215
svn_path_get_absolute (const char **pabsolute,
 
216
                       const char *relative,
 
217
                       apr_pool_t *pool);
 
218
 
 
219
/** Return the path part of the canonicalized @a path in @a
 
220
 * *pdirectory, and the file part in @a *pfile.  If @a path is a
 
221
 * directory, set @a *pdirectory to @a path, and @a *pfile to the
 
222
 * empty string.  If @a path does not exist it is treated as if it is
 
223
 * a file, since directories do not normally vanish.
 
224
 */
 
225
svn_error_t *
 
226
svn_path_split_if_file(const char *path,
 
227
                       const char **pdirectory, 
 
228
                       const char **pfile,
 
229
                       apr_pool_t *pool);
 
230
 
 
231
/** Find the common prefix of the canonicalized paths in @a targets
 
232
 * (an array of @a const char *'s), and remove redundant paths if @a
 
233
 * remove_redundancies is true.
 
234
 *
 
235
 *   - Set @a *pcommon to the absolute path of the path or URL common to
 
236
 *     all of the targets.  If the targets have no common prefix, or
 
237
 *     are a mix of URLs and local paths, set @a *pcommon to the
 
238
 *     empty string.
 
239
 *
 
240
 *   - If @a pcondensed_targets is non-null, set @a *pcondensed_targets
 
241
 *     to an array of targets relative to @a *pcommon, and if 
 
242
 *     @a remove_redundancies is true, omit any paths/URLs that are
 
243
 *     descendants of another path/URL in @a targets.  If *pcommon
 
244
 *     is empty, @a *pcondensed_targets will contain full URLs and/or
 
245
 *     absolute paths; redundancies can still be removed (from both URLs 
 
246
 *     and paths).  If @a pcondensed_targets is null, leave it alone.  
 
247
 *
 
248
 * Else if there is exactly one target, then
 
249
 *
 
250
 *   - Set @a *pcommon to that target, and
 
251
 *
 
252
 *   - If @a pcondensed_targets is non-null, set @a *pcondensed_targets
 
253
 *     to an array containing zero elements.  Else if
 
254
 *     @a pcondensed_targets is null, leave it alone.
 
255
 *
 
256
 * If there are no items in @a targets, set @a *pcommon and (if
 
257
 * applicable) @a *pcondensed_targets to @c NULL.
 
258
 *
 
259
 * NOTE: There is no guarantee that @a *pcommon is within a working
 
260
 * copy.  */
 
261
svn_error_t *
 
262
svn_path_condense_targets (const char **pcommon,
 
263
                           apr_array_header_t **pcondensed_targets,
 
264
                           const apr_array_header_t *targets,
 
265
                           svn_boolean_t remove_redundancies,
 
266
                           apr_pool_t *pool);
 
267
 
 
268
 
 
269
/** Copy a list of canonicalized @a targets, one at a time, into @a
 
270
 * pcondensed_targets, omitting any targets that are found earlier in
 
271
 * the list, or whose ancestor is found earlier in the list.  Ordering
 
272
 * of targets in the original list is preserved in the condensed list
 
273
 * of targets.  Use @a pool for any allocations.
 
274
 *
 
275
 * How does this differ in functionality from @c svn_path_condense_targets?
 
276
 *
 
277
 * Here's the short version:
 
278
 * 
 
279
 * 1.  Disclaimer: if you wish to debate the following, talk to Karl. :-)
 
280
 *     Order matters for updates because a multi-arg update is not
 
281
 *     atomic, and CVS users are used to, when doing 'cvs up targetA
 
282
 *     targetB' seeing targetA get updated, then targetB.  I think the
 
283
 *     idea is that if you're in a time-sensitive or flaky-network
 
284
 *     situation, a user can say, "I really *need* to update
 
285
 *     wc/A/D/G/tau, but I might as well update my whole working copy if
 
286
 *     I can."  So that user will do 'svn up wc/A/D/G/tau wc', and if
 
287
 *     something dies in the middles of the 'wc' update, at least the
 
288
 *     user has 'tau' up-to-date.
 
289
 * 
 
290
 * 2.  Also, we have this notion of an anchor and a target for updates
 
291
 *     (the anchor is where the update editor is rooted, the target is
 
292
 *     the actual thing we want to update).  I needed a function that
 
293
 *     would NOT screw with my input paths so that I could tell the
 
294
 *     difference between someone being in A/D and saying 'svn up G' and
 
295
 *     being in A/D/G and saying 'svn up .' -- believe it or not, these
 
296
 *     two things don't mean the same thing.  @c svn_path_condense_targets
 
297
 *     plays with absolute paths (which is fine, so does
 
298
 *     @c svn_path_remove_redundancies), but the difference is that it
 
299
 *     actually tweaks those targets to be relative to the "grandfather
 
300
 *     path" common to all the targets.  Updates don't require a
 
301
 *     "grandfather path" at all, and even if it did, the whole
 
302
 *     conversion to an absolute path drops the crucial difference
 
303
 *     between saying "i'm in foo, update bar" and "i'm in foo/bar,
 
304
 *     update '.'"
 
305
 */
 
306
svn_error_t *
 
307
svn_path_remove_redundancies (apr_array_header_t **pcondensed_targets,
 
308
                              const apr_array_header_t *targets,
 
309
                              apr_pool_t *pool);
 
310
 
 
311
 
 
312
/** Decompose the canonicalized @a path into an array of <tt>const
 
313
 * char *</tt> components, allocated in @a pool.  If @a path is
 
314
 * absolute, the first component will be a lone dir separator (the
 
315
 * root directory).
 
316
 */
 
317
apr_array_header_t *svn_path_decompose (const char *path,
 
318
                                        apr_pool_t *pool);
 
319
 
 
320
 
 
321
/** Test that @a name is a single path component, that is:
 
322
 *   - not @c NULL or empty.
 
323
 *   - not a `/'-separated directory path
 
324
 *   - not empty or `..'  
 
325
 */
 
326
svn_boolean_t svn_path_is_single_path_component (const char *name);
 
327
 
 
328
 
 
329
/**
 
330
 * @since New in 1.1.
 
331
 *
 
332
 * Test to see if a backpath, i.e. '..', is present in @a path.
 
333
 * If not, return @c FALSE.
 
334
 * If so, return @c TRUE.
 
335
 */
 
336
svn_boolean_t svn_path_is_backpath_present (const char *path);
 
337
 
 
338
 
 
339
/** Test if @a path2 is a child of @a path1.
 
340
 * If not, return @c NULL.
 
341
 * If so, return a copy of the remainder path, allocated in @a pool.
 
342
 * (The remainder is the component which, added to @a path1, yields
 
343
 * @a path2.  The remainder does not begin with a dir separator.)  
 
344
 *
 
345
 * Both paths must be in canonical form, and must either be absolute,
 
346
 * or contain no ".." components.
 
347
 *
 
348
 * ### todo: the ".." restriction is unfortunate, and would ideally
 
349
 * be lifted by making the implementation smarter.  But this is not
 
350
 * trivial: if the path is "../foo", how do you know whether or not
 
351
 * the current directory is named "foo" in its parent?
 
352
 */
 
353
const char *svn_path_is_child (const char *path1,
 
354
                               const char *path2,
 
355
                               apr_pool_t *pool);
 
356
 
 
357
/** 
 
358
 * @since New in 1.2.
 
359
 *
 
360
 * Check whether @a path is a valid Subversion path.
 
361
 *
 
362
 * A valid Subversion pathname is a UTF-8 string without control
 
363
 * characters.  "Valid" means Subversion can store the pathname in
 
364
 * a repository.  There may be other, OS-specific, limitations on
 
365
 * what paths can be represented in a working copy.
 
366
 *
 
367
 * ASSUMPTION: @a path is a valid UTF-8 string.  This function does
 
368
 * not check UTF-8 validity.
 
369
 *
 
370
 * Return @c SVN_NO_ERROR if valid and @c SVN_ERR_FS_PATH_SYNTAX if
 
371
 * invalid.
 
372
 */
 
373
svn_error_t *svn_path_check_valid (const char *path, apr_pool_t *pool);
 
374
 
 
375
 
 
376
/** URI/URL stuff
 
377
 *
 
378
 * @defgroup svn_path_uri_stuff URI/URL stuff
 
379
 * @{
 
380
 */
 
381
 
 
382
/** Return @c TRUE iff @a path looks like a valid URL, @c FALSE otherwise. */
 
383
svn_boolean_t svn_path_is_url (const char *path);
 
384
 
 
385
/** Return @c TRUE iff @a path is URI-safe, @c FALSE otherwise. */
 
386
svn_boolean_t svn_path_is_uri_safe (const char *path);
 
387
 
 
388
/** Return a URI-encoded copy of @a path, allocated in @a pool. */
 
389
const char *svn_path_uri_encode (const char *path, apr_pool_t *pool);
 
390
 
 
391
/** Return a URI-decoded copy of @a path, allocated in @a pool. */
 
392
const char *svn_path_uri_decode (const char *path, apr_pool_t *pool);
 
393
 
 
394
/** Extend @a url by a single @a component, URI-encoding that @a component
 
395
 * before adding it to the @a url.  Return the new @a url, allocated in
 
396
 * @a pool.  Notes: if @a component is @c NULL, just return a copy or @a url
 
397
 * allocated in @a pool; if @a component is already URI-encoded, calling
 
398
 * code should just use <tt>svn_path_join (url, component, pool)</tt>.  @a url
 
399
 * does not need to be a canonical path, it may have trailing '/'.
 
400
 */
 
401
const char *svn_path_url_add_component (const char *url,
 
402
                                        const char *component,
 
403
                                        apr_pool_t *pool);
 
404
 
 
405
/**
 
406
 * @since New in 1.1.
 
407
 *
 
408
 * Convert @a iri (Internationalized URI) to an URI.
 
409
 * The return value may be the same as @a iri if it was already
 
410
 * a URI.  Else, allocate the return value in @a pool. */
 
411
const char *svn_path_uri_from_iri (const char *iri,
 
412
                                   apr_pool_t *pool);
 
413
 
 
414
/**
 
415
 * @since New in 1.1.
 
416
 *
 
417
 * URI-encode certain characters in @a uri that are not valid in an URI, but
 
418
 * doesn't have any special meaning in @a uri at their positions.  If no
 
419
 * characters need escaping, just return @a uri.
 
420
 *
 
421
 * NOTE: Currently, this function escapes <, >, ", space, {, }, |, \, ^, and `.
 
422
 * This may be extended in the future to do context-dependent escaping.
 
423
 */
 
424
const char *svn_path_uri_autoescape (const char *uri,
 
425
                                     apr_pool_t *pool);
 
426
 
 
427
/** @} */
 
428
 
 
429
/** Charset conversion stuff
 
430
 *
 
431
 * @defgroup svn_path_charset_stuff Charset conversion stuff
 
432
 * @{
 
433
 */
 
434
 
 
435
/** Convert @a path_utf8 from UTF-8 to the internal encoding used by APR. */
 
436
svn_error_t *svn_path_cstring_from_utf8 (const char **path_apr,
 
437
                                         const char *path_utf8,
 
438
                                         apr_pool_t *pool);
 
439
 
 
440
/** Convert @a path_apr from the internal encoding used by APR to UTF-8. */
 
441
svn_error_t *svn_path_cstring_to_utf8 (const char **path_utf8,
 
442
                                       const char *path_apr,
 
443
                                       apr_pool_t *pool);
 
444
 
 
445
 
 
446
/** @} */
 
447
 
 
448
#ifdef __cplusplus
 
449
}
 
450
#endif /* __cplusplus */
 
451
 
 
452
 
 
453
#endif /* SVN_PATH_H */