1 /* id.c : operations on node-revision IDs
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 * ====================================================================
27 #include "../libsvn_fs/fs-loader.h"
31 typedef struct id_private_t {
38 /* Accessing ID Pieces. */
41 svn_fs_base__id_node_id(const svn_fs_id_t *id)
43 id_private_t *pvt = id->fsap_data;
50 svn_fs_base__id_copy_id(const svn_fs_id_t *id)
52 id_private_t *pvt = id->fsap_data;
59 svn_fs_base__id_txn_id(const svn_fs_id_t *id)
61 id_private_t *pvt = id->fsap_data;
68 svn_fs_base__id_unparse(const svn_fs_id_t *id,
71 id_private_t *pvt = id->fsap_data;
73 return svn_string_createf(pool, "%s.%s.%s",
74 pvt->node_id, pvt->copy_id, pvt->txn_id);
78 /*** Comparing node IDs ***/
81 svn_fs_base__id_eq(const svn_fs_id_t *a,
84 id_private_t *pvta = a->fsap_data, *pvtb = b->fsap_data;
88 if (strcmp(pvta->node_id, pvtb->node_id) != 0)
90 if (strcmp(pvta->copy_id, pvtb->copy_id) != 0)
92 if (strcmp(pvta->txn_id, pvtb->txn_id) != 0)
99 svn_fs_base__id_check_related(const svn_fs_id_t *a,
100 const svn_fs_id_t *b)
102 id_private_t *pvta = a->fsap_data, *pvtb = b->fsap_data;
107 return (strcmp(pvta->node_id, pvtb->node_id) == 0);
112 svn_fs_base__id_compare(const svn_fs_id_t *a,
113 const svn_fs_id_t *b)
115 if (svn_fs_base__id_eq(a, b))
117 return (svn_fs_base__id_check_related(a, b) ? 1 : -1);
124 static id_vtable_t id_vtable = {
125 svn_fs_base__id_unparse,
126 svn_fs_base__id_compare
131 svn_fs_base__id_create(const char *node_id,
136 svn_fs_id_t *id = apr_palloc(pool, sizeof(*id));
137 id_private_t *pvt = apr_palloc(pool, sizeof(*pvt));
139 pvt->node_id = apr_pstrdup(pool, node_id);
140 pvt->copy_id = apr_pstrdup(pool, copy_id);
141 pvt->txn_id = apr_pstrdup(pool, txn_id);
142 id->vtable = &id_vtable;
149 svn_fs_base__id_copy(const svn_fs_id_t *id, apr_pool_t *pool)
151 svn_fs_id_t *new_id = apr_palloc(pool, sizeof(*new_id));
152 id_private_t *new_pvt = apr_palloc(pool, sizeof(*new_pvt));
153 id_private_t *pvt = id->fsap_data;
155 new_pvt->node_id = apr_pstrdup(pool, pvt->node_id);
156 new_pvt->copy_id = apr_pstrdup(pool, pvt->copy_id);
157 new_pvt->txn_id = apr_pstrdup(pool, pvt->txn_id);
158 new_id->vtable = &id_vtable;
159 new_id->fsap_data = new_pvt;
165 svn_fs_base__id_parse(const char *data,
171 char *data_copy, *str;
173 /* Dup the ID data into POOL. Our returned ID will have references
175 data_copy = apr_pstrmemdup(pool, data, len);
177 /* Alloc a new svn_fs_id_t structure. */
178 id = apr_palloc(pool, sizeof(*id));
179 pvt = apr_palloc(pool, sizeof(*pvt));
180 id->vtable = &id_vtable;
183 /* Now, we basically just need to "split" this data on `.'
184 characters. We will use svn_cstring_tokenize, which will put
185 terminators where each of the '.'s used to be. Then our new
186 id field will reference string locations inside our duplicate
190 str = svn_cstring_tokenize(".", &data_copy);
196 str = svn_cstring_tokenize(".", &data_copy);
202 str = svn_cstring_tokenize(".", &data_copy);