Remove no-longer-used svn_*_get_mergeinfo_for_tree APIs.
[svn.git] / subversion / libsvn_subr / iter.c
blob422fd3f44c38ea2bff5f58116a658cdd24d9226a
1 /* iter.c : iteration drivers
3 * ====================================================================
4 * Copyright (c) 2007 CollabNet. All rights reserved.
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.
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 * ====================================================================
19 #include "svn_iter.h"
20 #include "svn_error_codes.h"
22 static svn_error_t internal_break_error =
24 SVN_ERR_ITER_BREAK, /* APR status */
25 NULL, /* message */
26 NULL, /* child error */
27 NULL, /* pool */
28 __FILE__, /* file name */
29 __LINE__ /* line number */
32 svn_error_t *
33 svn_iter_apr_hash(svn_boolean_t *completed,
34 apr_hash_t *hash,
35 svn_iter_apr_hash_cb_t func,
36 void *baton,
37 apr_pool_t *pool)
39 svn_error_t *err = SVN_NO_ERROR;
40 apr_pool_t *iterpool = svn_pool_create(pool);
41 apr_hash_index_t *hi;
43 for (hi = apr_hash_first(pool, hash);
44 ! err && hi; hi = apr_hash_next(hi))
46 const void *key;
47 void *val;
48 apr_ssize_t len;
50 svn_pool_clear(iterpool);
52 apr_hash_this(hi, &key, &len, &val);
53 err = (*func)(baton, key, len, val, iterpool);
56 if (completed)
57 *completed = ! err;
59 if (err && err->apr_err == SVN_ERR_ITER_BREAK)
61 if (err != &internal_break_error)
62 /* Errors - except those created by svn_iter_break() -
63 need to be cleared when not further propagated. */
64 svn_error_clear(err);
66 err = SVN_NO_ERROR;
69 /* Clear iterpool, because callers may clear the error but have no way
70 to clear the iterpool with potentially lots of allocated memory */
71 svn_pool_destroy(iterpool);
73 return err;
76 svn_error_t *
77 svn_iter_apr_array(svn_boolean_t *completed,
78 const apr_array_header_t *array,
79 svn_iter_apr_array_cb_t func,
80 void *baton,
81 apr_pool_t *pool)
83 svn_error_t *err = SVN_NO_ERROR;
84 apr_pool_t *iterpool = svn_pool_create(pool);
85 int i;
87 for (i = 0; (! err) && i < array->nelts; ++i)
89 void *item = array->elts + array->elt_size*i;
91 svn_pool_clear(iterpool);
93 err = (*func)(baton, item, pool);
96 if (completed)
97 *completed = ! err;
99 if (err && err->apr_err == SVN_ERR_ITER_BREAK)
101 if (err != &internal_break_error)
102 /* Errors - except those created by svn_iter_break() -
103 need to be cleared when not further propagated. */
104 svn_error_clear(err);
106 err = SVN_NO_ERROR;
109 /* Clear iterpool, because callers may clear the error but have no way
110 to clear the iterpool with potentially lots of allocated memory */
111 svn_pool_destroy(iterpool);
113 return err;
116 svn_error_t *
117 svn_iter__break(void)
119 return &internal_break_error;