Mark many merge tests as skip-against-old-server.
[svn.git] / subversion / libsvn_fs_base / id.c
blob14686b65e4c8050ec18a14af7bebfb2563297bf6
1 /* id.c : operations on node-revision IDs
3 * ====================================================================
4 * Copyright (c) 2000-2004 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 * ====================================================================
18 #include <string.h>
19 #include <stdlib.h>
21 #include "id.h"
22 #include "../libsvn_fs/fs-loader.h"
26 typedef struct {
27 const char *node_id;
28 const char *copy_id;
29 const char *txn_id;
30 } id_private_t;
33 /* Accessing ID Pieces. */
35 const char *
36 svn_fs_base__id_node_id(const svn_fs_id_t *id)
38 id_private_t *pvt = id->fsap_data;
40 return pvt->node_id;
44 const char *
45 svn_fs_base__id_copy_id(const svn_fs_id_t *id)
47 id_private_t *pvt = id->fsap_data;
49 return pvt->copy_id;
53 const char *
54 svn_fs_base__id_txn_id(const svn_fs_id_t *id)
56 id_private_t *pvt = id->fsap_data;
58 return pvt->txn_id;
62 svn_string_t *
63 svn_fs_base__id_unparse(const svn_fs_id_t *id,
64 apr_pool_t *pool)
66 id_private_t *pvt = id->fsap_data;
68 return svn_string_createf(pool, "%s.%s.%s",
69 pvt->node_id, pvt->copy_id, pvt->txn_id);
73 /*** Comparing node IDs ***/
75 svn_boolean_t
76 svn_fs_base__id_eq(const svn_fs_id_t *a,
77 const svn_fs_id_t *b)
79 id_private_t *pvta = a->fsap_data, *pvtb = b->fsap_data;
81 if (a == b)
82 return TRUE;
83 if (strcmp(pvta->node_id, pvtb->node_id) != 0)
84 return FALSE;
85 if (strcmp(pvta->copy_id, pvtb->copy_id) != 0)
86 return FALSE;
87 if (strcmp(pvta->txn_id, pvtb->txn_id) != 0)
88 return FALSE;
89 return TRUE;
93 svn_boolean_t
94 svn_fs_base__id_check_related(const svn_fs_id_t *a,
95 const svn_fs_id_t *b)
97 id_private_t *pvta = a->fsap_data, *pvtb = b->fsap_data;
99 if (a == b)
100 return TRUE;
102 return (strcmp(pvta->node_id, pvtb->node_id) == 0) ? TRUE : FALSE;
107 svn_fs_base__id_compare(const svn_fs_id_t *a,
108 const svn_fs_id_t *b)
110 if (svn_fs_base__id_eq(a, b))
111 return 0;
112 return (svn_fs_base__id_check_related(a, b) ? 1 : -1);
117 /* Creating ID's. */
119 static id_vtable_t id_vtable = {
120 svn_fs_base__id_unparse,
121 svn_fs_base__id_compare
125 svn_fs_id_t *
126 svn_fs_base__id_create(const char *node_id,
127 const char *copy_id,
128 const char *txn_id,
129 apr_pool_t *pool)
131 svn_fs_id_t *id = apr_palloc(pool, sizeof(*id));
132 id_private_t *pvt = apr_palloc(pool, sizeof(*pvt));
134 pvt->node_id = apr_pstrdup(pool, node_id);
135 pvt->copy_id = apr_pstrdup(pool, copy_id);
136 pvt->txn_id = apr_pstrdup(pool, txn_id);
137 id->vtable = &id_vtable;
138 id->fsap_data = pvt;
139 return id;
143 svn_fs_id_t *
144 svn_fs_base__id_copy(const svn_fs_id_t *id, apr_pool_t *pool)
146 svn_fs_id_t *new_id = apr_palloc(pool, sizeof(*new_id));
147 id_private_t *new_pvt = apr_palloc(pool, sizeof(*new_pvt));
148 id_private_t *pvt = id->fsap_data;
150 new_pvt->node_id = apr_pstrdup(pool, pvt->node_id);
151 new_pvt->copy_id = apr_pstrdup(pool, pvt->copy_id);
152 new_pvt->txn_id = apr_pstrdup(pool, pvt->txn_id);
153 new_id->vtable = &id_vtable;
154 new_id->fsap_data = new_pvt;
155 return new_id;
159 svn_fs_id_t *
160 svn_fs_base__id_parse(const char *data,
161 apr_size_t len,
162 apr_pool_t *pool)
164 svn_fs_id_t *id;
165 id_private_t *pvt;
166 char *data_copy, *str, *last_str;
168 /* Dup the ID data into POOL. Our returned ID will have references
169 into this memory. */
170 data_copy = apr_pstrmemdup(pool, data, len);
172 /* Alloc a new svn_fs_id_t structure. */
173 id = apr_palloc(pool, sizeof(*id));
174 pvt = apr_palloc(pool, sizeof(*pvt));
175 id->vtable = &id_vtable;
176 id->fsap_data = pvt;
178 /* Now, we basically just need to "split" this data on `.'
179 characters. We will use apr_strtok, which will put terminators
180 where each of the '.'s used to be. Then our new id field will
181 reference string locations inside our duplicate string.*/
183 /* Node Id */
184 str = apr_strtok(data_copy, ".", &last_str);
185 if (str == NULL)
186 return NULL;
187 pvt->node_id = str;
189 /* Copy Id */
190 str = apr_strtok(NULL, ".", &last_str);
191 if (str == NULL)
192 return NULL;
193 pvt->copy_id = str;
195 /* Txn Id */
196 str = apr_strtok(NULL, ".", &last_str);
197 if (str == NULL)
198 return NULL;
199 pvt->txn_id = str;
201 return id;