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 * ====================================================================
22 #include "../libsvn_fs/fs-loader.h"
33 /* Accessing ID Pieces. */
36 svn_fs_base__id_node_id(const svn_fs_id_t
*id
)
38 id_private_t
*pvt
= id
->fsap_data
;
45 svn_fs_base__id_copy_id(const svn_fs_id_t
*id
)
47 id_private_t
*pvt
= id
->fsap_data
;
54 svn_fs_base__id_txn_id(const svn_fs_id_t
*id
)
56 id_private_t
*pvt
= id
->fsap_data
;
63 svn_fs_base__id_unparse(const svn_fs_id_t
*id
,
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 ***/
76 svn_fs_base__id_eq(const svn_fs_id_t
*a
,
79 id_private_t
*pvta
= a
->fsap_data
, *pvtb
= b
->fsap_data
;
83 if (strcmp(pvta
->node_id
, pvtb
->node_id
) != 0)
85 if (strcmp(pvta
->copy_id
, pvtb
->copy_id
) != 0)
87 if (strcmp(pvta
->txn_id
, pvtb
->txn_id
) != 0)
94 svn_fs_base__id_check_related(const svn_fs_id_t
*a
,
97 id_private_t
*pvta
= a
->fsap_data
, *pvtb
= b
->fsap_data
;
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
))
112 return (svn_fs_base__id_check_related(a
, b
) ? 1 : -1);
119 static id_vtable_t id_vtable
= {
120 svn_fs_base__id_unparse
,
121 svn_fs_base__id_compare
126 svn_fs_base__id_create(const char *node_id
,
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
;
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
;
160 svn_fs_base__id_parse(const char *data
,
166 char *data_copy
, *str
, *last_str
;
168 /* Dup the ID data into POOL. Our returned ID will have references
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
;
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.*/
184 str
= apr_strtok(data_copy
, ".", &last_str
);
190 str
= apr_strtok(NULL
, ".", &last_str
);
196 str
= apr_strtok(NULL
, ".", &last_str
);