Remove no-longer-used svn_*_get_mergeinfo_for_tree APIs.
[svn.git] / subversion / libsvn_diff / token.c
blobd7850f610e179680c58b28e6528cbb363da69f9f
1 /*
2 * token.c : routines for doing diffs
4 * ====================================================================
5 * Copyright (c) 2000-2004 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 * ====================================================================
20 #include <apr.h>
21 #include <apr_pools.h>
22 #include <apr_general.h>
24 #include "svn_error.h"
25 #include "svn_diff.h"
26 #include "svn_types.h"
28 #include "diff.h"
32 * Prime number to use as the size of the hash table. This number was
33 * not selected by testing of any kind and may need tweaking.
35 #define SVN_DIFF__HASH_SIZE 127
37 struct svn_diff__node_t
39 svn_diff__node_t *parent;
40 svn_diff__node_t *left;
41 svn_diff__node_t *right;
43 apr_uint32_t hash;
44 void *token;
47 struct svn_diff__tree_t
49 svn_diff__node_t *root[SVN_DIFF__HASH_SIZE];
50 apr_pool_t *pool;
55 * Support functions to build a tree of token positions
58 void
59 svn_diff__tree_create(svn_diff__tree_t **tree, apr_pool_t *pool)
61 *tree = apr_pcalloc(pool, sizeof(**tree));
62 (*tree)->pool = pool;
66 static svn_error_t *
67 svn_diff__tree_insert_token(svn_diff__node_t **node, svn_diff__tree_t *tree,
68 void *diff_baton,
69 const svn_diff_fns_t *vtable,
70 apr_uint32_t hash, void *token)
72 svn_diff__node_t *new_node;
73 svn_diff__node_t **node_ref;
74 svn_diff__node_t *parent;
75 int rv;
77 if (!token)
78 abort();
80 parent = NULL;
81 node_ref = &tree->root[hash % SVN_DIFF__HASH_SIZE];
83 while (*node_ref != NULL)
85 parent = *node_ref;
87 rv = hash - parent->hash;
88 if (!rv)
89 SVN_ERR(vtable->token_compare(diff_baton, parent->token, token, &rv));
91 if (rv == 0)
93 /* Discard the previous token. This helps in cases where
94 * only recently read tokens are still in memory.
96 if (vtable->token_discard != NULL)
97 vtable->token_discard(diff_baton, parent->token);
99 parent->token = token;
100 *node = parent;
102 return SVN_NO_ERROR;
104 else if (rv > 0)
106 node_ref = &parent->left;
108 else
110 node_ref = &parent->right;
114 /* Create a new node */
115 new_node = apr_palloc(tree->pool, sizeof(*new_node));
116 new_node->parent = parent;
117 new_node->left = NULL;
118 new_node->right = NULL;
119 new_node->hash = hash;
120 new_node->token = token;
122 *node = *node_ref = new_node;
124 return SVN_NO_ERROR;
129 * Get all tokens from a datasource. Return the
130 * last item in the (circular) list.
132 svn_error_t *
133 svn_diff__get_tokens(svn_diff__position_t **position_list,
134 svn_diff__tree_t *tree,
135 void *diff_baton,
136 const svn_diff_fns_t *vtable,
137 svn_diff_datasource_e datasource,
138 apr_pool_t *pool)
140 svn_diff__position_t *start_position;
141 svn_diff__position_t *position = NULL;
142 svn_diff__position_t **position_ref;
143 svn_diff__node_t *node;
144 void *token;
145 apr_off_t offset;
146 apr_uint32_t hash;
148 *position_list = NULL;
151 SVN_ERR(vtable->datasource_open(diff_baton, datasource));
153 position_ref = &start_position;
154 offset = 0;
155 hash = 0; /* The callback fn doesn't need to touch it per se */
156 while (1)
158 SVN_ERR(vtable->datasource_get_next_token(&hash, &token,
159 diff_baton, datasource));
160 if (token == NULL)
161 break;
163 offset++;
164 SVN_ERR(svn_diff__tree_insert_token(&node, tree,
165 diff_baton, vtable,
166 hash, token));
168 /* Create a new position */
169 position = apr_palloc(pool, sizeof(*position));
170 position->next = NULL;
171 position->node = node;
172 position->offset = offset;
174 *position_ref = position;
175 position_ref = &position->next;
178 *position_ref = start_position;
180 SVN_ERR(vtable->datasource_close(diff_baton, datasource));
182 *position_list = position;
184 return SVN_NO_ERROR;