* subversion/libsvn_subr/validate.c
[svn.git] / subversion / libsvn_subr / constructors.c
blob3ddf16707a7eae3c6b15afa02d6d909cf7eab0f2
1 /*
2 * constructors.c : Constructors for various data structures.
4 * ====================================================================
5 * Copyright (c) 2005-2007 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 #include <apr_pools.h>
20 #include <apr_strings.h>
22 #include "svn_types.h"
23 #include "svn_props.h"
24 #include "svn_string.h"
27 svn_commit_info_t *
28 svn_create_commit_info(apr_pool_t *pool)
30 svn_commit_info_t *commit_info
31 = apr_pcalloc(pool, sizeof(*commit_info));
33 commit_info->revision = SVN_INVALID_REVNUM;
34 /* All other fields were initialized to NULL above. */
36 return commit_info;
39 svn_commit_info_t *
40 svn_commit_info_dup(const svn_commit_info_t *src_commit_info,
41 apr_pool_t *pool)
43 svn_commit_info_t *dst_commit_info = svn_create_commit_info(pool);
45 dst_commit_info->date = src_commit_info->date
46 ? apr_pstrdup(pool, src_commit_info->date) : NULL;
47 dst_commit_info->author = src_commit_info->author
48 ? apr_pstrdup(pool, src_commit_info->author) : NULL;
49 dst_commit_info->revision = src_commit_info->revision;
50 dst_commit_info->post_commit_err = src_commit_info->post_commit_err
51 ? apr_pstrdup(pool, src_commit_info->post_commit_err) : NULL;
53 return dst_commit_info;
56 svn_log_changed_path_t *
57 svn_log_changed_path_dup(const svn_log_changed_path_t *changed_path,
58 apr_pool_t *pool)
60 svn_log_changed_path_t *new_changed_path
61 = apr_palloc(pool, sizeof(*new_changed_path));
63 *new_changed_path = *changed_path;
65 if (new_changed_path->copyfrom_path)
66 new_changed_path->copyfrom_path =
67 apr_pstrdup(pool, new_changed_path->copyfrom_path);
69 return new_changed_path;
72 /**
73 * Reallocate the members of PROP using POOL.
75 static void
76 svn_prop__members_dup(svn_prop_t *prop, apr_pool_t *pool)
78 if (prop->name)
79 prop->name = apr_pstrdup(pool, prop->name);
80 if (prop->value)
81 prop->value = svn_string_dup(prop->value, pool);
84 svn_prop_t *
85 svn_prop_dup(const svn_prop_t *prop, apr_pool_t *pool)
87 svn_prop_t *new_prop = apr_palloc(pool, sizeof(*new_prop));
89 *new_prop = *prop;
91 svn_prop__members_dup(new_prop, pool);
93 return new_prop;
96 apr_array_header_t *
97 svn_prop_array_dup(const apr_array_header_t *array, apr_pool_t *pool)
99 int i;
100 apr_array_header_t *new_array = apr_array_copy(pool, array);
101 for (i = 0; i < new_array->nelts; ++i)
103 svn_prop_t *elt = &APR_ARRAY_IDX(new_array, i, svn_prop_t);
104 svn_prop__members_dup(elt, pool);
106 return new_array;
109 apr_array_header_t *
110 svn_prop_hash_to_array(apr_hash_t *hash, apr_pool_t *pool)
112 apr_hash_index_t *hi;
113 apr_array_header_t *array = apr_array_make(pool, apr_hash_count(hash),
114 sizeof(svn_prop_t));
116 for (hi = apr_hash_first(pool, hash); hi; hi = apr_hash_next(hi))
118 const void *key;
119 void *val;
120 svn_prop_t prop;
122 apr_hash_this(hi, &key, NULL, &val);
123 prop.name = key;
124 prop.value = val;
125 APR_ARRAY_PUSH(array, svn_prop_t) = prop;
128 return array;
131 svn_dirent_t *
132 svn_dirent_dup(const svn_dirent_t *dirent,
133 apr_pool_t *pool)
135 svn_dirent_t *new_dirent = apr_palloc(pool, sizeof(*new_dirent));
137 *new_dirent = *dirent;
139 new_dirent->last_author = apr_pstrdup(pool, dirent->last_author);
141 return new_dirent;
144 svn_log_entry_t *
145 svn_log_entry_create(apr_pool_t *pool)
147 svn_log_entry_t *log_entry = apr_pcalloc(pool, sizeof(*log_entry));
149 return log_entry;
152 svn_location_segment_t *
153 svn_location_segment_dup(svn_location_segment_t *segment,
154 apr_pool_t *pool)
156 svn_location_segment_t *new_segment =
157 apr_pcalloc(pool, sizeof(*new_segment));
158 *new_segment = *segment;
159 if (segment->path)
160 new_segment->path = apr_pstrdup(pool, segment->path);
161 return new_segment;