summaryrefslogtreecommitdiff
path: root/src/revobject.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2010-08-08 14:12:17 +0200
committerVicent Marti <tanoku@gmail.com>2010-08-12 18:48:55 +0200
commit3315782cb4f2b683c66a53c93aa81de501c5a4ab (patch)
treee3fa8b56dc17b749cc53520eb350cbcc46101007 /src/revobject.c
parentf8758044876b30b0f6482d1fe8c3b1de743f4186 (diff)
downloadlibgit2-3315782cb4f2b683c66a53c93aa81de501c5a4ab.tar.gz
Redesigned the walking/object lookup interface
The old 'git_revpool' object has been removed and split into two distinct objects with separate functionality, in order to have separate methods for object management and object walking. * A new object 'git_repository' does the high-level management of a repository's objects (commits, trees, tags, etc) on top of a 'git_odb'. Eventually, it will also manage other repository attributes (e.g. tag resolution, references, etc). See: src/git/repository.h * A new external method 'git_repository_lookup(repo, oid, type)' has been added to the 'git_repository' API. All object lookups (git_XXX_lookup()) are now wrappers to this method, and duplicated code has been removed. The method does automatic type checking and returns a generic 'git_revpool_object' that can be cast to any specific object. See: src/git/repository.h * The external methods for object parsing of repository objects (git_XXX_parse()) have been removed. Loading objects from the repository is now managed through the 'lookup' functions. These objects are loaded with minimal information, and the relevant parsing is done automatically when the user requests any of the parsed attributes through accessor methods. An attribute has been added to 'git_repository' in order to force the parsing of all the repository objects immediately after lookup. See: src/git/commit.h See: src/git/tag.h See: src/git/tree.h * The previous walking functionality of the revpool is now found in 'git_revwalk', which does the actual revision walking on a repository; the attributes when walking through commits in a database have been decoupled from the actual commit objects. This increases performance when accessing commits during the walk and allows to have several 'git_revwalk' instances working at the same time on top of the same repository, without having to load commits in memory several times. See: src/git/revwalk.h * The old 'git_revpool_table' has been renamed to 'git_hashtable' and now works as a generic hashtable with support for any kind of object and custom hash functions. See: src/hashtable.h * All the relevant unit tests have been updated, renamed and grouped accordingly. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/revobject.c')
-rw-r--r--src/revobject.c210
1 files changed, 0 insertions, 210 deletions
diff --git a/src/revobject.c b/src/revobject.c
deleted file mode 100644
index 47d75e047..000000000
--- a/src/revobject.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
- *
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "common.h"
-#include "revobject.h"
-
-static const double max_load_factor = 0.65;
-
-static unsigned int git_revpool_table__hash(const git_oid *id)
-{
- unsigned int r;
- memcpy(&r, id->id, sizeof(r));
- return r;
-}
-
-git_revpool_table *git_revpool_table_create(unsigned int min_size)
-{
- git_revpool_table *table;
- unsigned int i;
-
- table = git__malloc(sizeof(*table));
-
- if (table == NULL)
- return NULL;
-
- /* round up size to closest power of 2 */
- min_size--;
- min_size |= min_size >> 1;
- min_size |= min_size >> 2;
- min_size |= min_size >> 4;
- min_size |= min_size >> 8;
- min_size |= min_size >> 16;
-
- table->size_mask = min_size;
- table->count = 0;
- table->max_count = (unsigned int)((min_size + 1) * max_load_factor);
-
- table->nodes = git__malloc((min_size + 1) * sizeof(git_revpool_node *));
-
- if (table->nodes == NULL) {
- free(table);
- return NULL;
- }
-
- for (i = 0; i <= min_size; ++i)
- table->nodes[i] = NULL;
-
- return table;
-}
-
-int git_revpool_table_insert(git_revpool_table *table, git_revpool_object *object)
-{
- git_revpool_node *node;
- unsigned int index, hash;
-
- if (table == NULL)
- return GIT_ERROR;
-
- if (table->count + 1 > table->max_count)
- git_revpool_table_resize(table);
-
- node = git__malloc(sizeof(git_revpool_node));
- if (node == NULL)
- return GIT_ENOMEM;
-
- hash = git_revpool_table__hash(&object->id);
- index = (hash & table->size_mask);
-
- node->object = object;
- node->hash = hash;
- node->next = table->nodes[index];
-
- table->nodes[index] = node;
- table->count++;
-
- return 0;
-}
-
-git_revpool_object *git_revpool_table_lookup(git_revpool_table *table, const git_oid *id)
-{
- git_revpool_node *node;
- unsigned int index, hash;
-
- if (table == NULL)
- return NULL;
-
- hash = git_revpool_table__hash(id);
- index = (hash & table->size_mask);
- node = table->nodes[index];
-
- while (node != NULL) {
- if (node->hash == hash && git_oid_cmp(id, &node->object->id) == 0)
- return node->object;
-
- node = node->next;
- }
-
- return NULL;
-}
-
-void git_revpool_table_resize(git_revpool_table *table)
-{
- git_revpool_node **new_nodes;
- unsigned int new_size, i;
-
- new_size = (table->size_mask + 1) * 2;
-
- new_nodes = git__malloc(new_size * sizeof(git_revpool_node *));
- if (new_nodes == NULL)
- return;
-
- memset(new_nodes, 0x0, new_size * sizeof(git_revpool_node *));
-
- for (i = 0; i <= table->size_mask; ++i) {
- git_revpool_node *n;
- unsigned int index;
-
- while ((n = table->nodes[i]) != NULL) {
- table->nodes[i] = n->next;
- index = n->hash & (new_size - 1);
- n->next = new_nodes[index];
- new_nodes[index] = n;
- }
- }
-
- free(table->nodes);
- table->nodes = new_nodes;
- table->size_mask = (new_size - 1);
- table->max_count = (unsigned int)(new_size * max_load_factor);
-}
-
-
-void git_revpool_table_free(git_revpool_table *table)
-{
- unsigned int index;
-
- for (index = 0; index <= table->size_mask; ++index) {
- git_revpool_node *node, *next_node;
-
- node = table->nodes[index];
- while (node != NULL) {
- next_node = node->next;
- free(node);
- node = next_node;
- }
- }
-
- free(table->nodes);
- free(table);
-}
-
-void git_revpool_tableit_init(git_revpool_table *table, git_revpool_tableit *it)
-{
- memset(it, 0x0, sizeof(git_revpool_tableit));
-
- it->nodes = table->nodes;
- it->current_node = NULL;
- it->current_pos = 0;
- it->size = table->size_mask + 1;
-}
-
-git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it)
-{
- git_revpool_node *next = NULL;
-
- while (it->current_node == NULL) {
- if (it->current_pos >= it->size)
- return NULL;
-
- it->current_node = it->nodes[it->current_pos++];
- }
-
- next = it->current_node;
- it->current_node = it->current_node->next;
-
- return next->object;
-}
-
-git_revpool_object *git_revpool_tableit_nextfilter(git_revpool_tableit *it, git_otype type)
-{
- git_revpool_object *obj;
-
- do {
- obj = git_revpool_tableit_next(it);
- } while (obj != NULL && obj->type != type);
-
- return obj;
-}