vendor/libgit2/src/pack-objects.c in rugged-0.28.4 vs vendor/libgit2/src/pack-objects.c in rugged-0.28.4.1

- old
+ new

@@ -36,11 +36,11 @@ git_buf buf; }; struct pack_write_context { git_indexer *indexer; - git_indexer_progress *stats; + git_transfer_progress *stats; }; struct walk_object { git_oid id; unsigned int uninteresting:1, @@ -139,14 +139,16 @@ *out = NULL; pb = git__calloc(1, sizeof(*pb)); GIT_ERROR_CHECK_ALLOC(pb); - if (git_oidmap_new(&pb->object_ix) < 0) + pb->object_ix = git_oidmap_alloc(); + if (!pb->object_ix) goto on_error; - if (git_oidmap_new(&pb->walk_objects) < 0) + pb->walk_objects = git_oidmap_alloc(); + if (!pb->walk_objects) goto on_error; git_pool_init(&pb->object_pool, sizeof(struct walk_object)); pb->repo = repo; @@ -190,30 +192,28 @@ #endif return pb->nr_threads; } -static int rehash(git_packbuilder *pb) +static void rehash(git_packbuilder *pb) { git_pobject *po; - size_t i; + size_t pos, i; + int ret; git_oidmap_clear(pb->object_ix); - for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) { - if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) - return -1; + pos = git_oidmap_put(pb->object_ix, &po->id, &ret); + git_oidmap_set_value_at(pb->object_ix, pos, po); } - - return 0; } int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, const char *name) { git_pobject *po; - size_t newsize; + size_t newsize, pos; int ret; assert(pb && oid); /* If the object already exists in the hash table, then we don't @@ -221,11 +221,11 @@ if (git_oidmap_exists(pb->object_ix, oid)) return 0; if (pb->nr_objects >= pb->nr_alloc) { GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024); - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize / 2, 3); + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize, 3 / 2); if (!git__is_uint32(newsize)) { git_error_set(GIT_ERROR_NOMEMORY, "packfile too large to fit in memory."); return -1; } @@ -233,13 +233,11 @@ pb->nr_alloc = newsize; pb->object_list = git__reallocarray(pb->object_list, pb->nr_alloc, sizeof(*po)); GIT_ERROR_CHECK_ALLOC(pb->object_list); - - if (rehash(pb) < 0) - return -1; + rehash(pb); } po = pb->object_list + pb->nr_objects; memset(po, 0x0, sizeof(*po)); @@ -248,14 +246,17 @@ pb->nr_objects++; git_oid_cpy(&po->id, oid); po->hash = name_hash(name); - if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) { + pos = git_oidmap_put(pb->object_ix, &po->id, &ret); + if (ret < 0) { git_error_set_oom(); - return -1; + return ret; } + assert(ret != 0); + git_oidmap_set_value_at(pb->object_ix, pos, po); pb->done = false; if (pb->progress_cb) { double current_time = git__timer(); @@ -511,16 +512,19 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data) { git_packbuilder *pb = data; git_pobject *po; + size_t pos; GIT_UNUSED(name); - if ((po = git_oidmap_get(pb->object_ix, oid)) == NULL) + pos = git_oidmap_lookup_index(pb->object_ix, oid); + if (!git_oidmap_valid_index(pb->object_ix, pos)) return 0; + po = git_oidmap_value_at(pb->object_ix, pos); po->tagged = 1; /* TODO: peel objects */ return 0; @@ -1377,16 +1381,16 @@ int git_packbuilder_write( git_packbuilder *pb, const char *path, unsigned int mode, - git_indexer_progress_cb progress_cb, + git_transfer_progress_cb progress_cb, void *progress_cb_payload) { git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; git_indexer *indexer; - git_indexer_progress stats; + git_transfer_progress stats; struct pack_write_context ctx; int t; PREPARE_PACK; @@ -1395,11 +1399,11 @@ if (git_indexer_new( &indexer, path, mode, pb->odb, &opts) < 0) return -1; - if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) + if (!git_repository__cvar(&t, pb->repo, GIT_CVAR_FSYNCOBJECTFILES) && t) git_indexer__set_fsync(indexer, 1); ctx.indexer = indexer; ctx.stats = &stats; @@ -1533,18 +1537,21 @@ return 0; } static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id) { - struct walk_object *obj; int error; + size_t pos; + struct walk_object *obj; - if ((obj = git_oidmap_get(pb->walk_objects, id)) == NULL) { + pos = git_oidmap_lookup_index(pb->walk_objects, id); + if (git_oidmap_valid_index(pb->walk_objects, pos)) { + obj = git_oidmap_value_at(pb->walk_objects, pos); + } else { if ((error = lookup_walk_object(&obj, pb, id)) < 0) return error; - if ((error = git_oidmap_set(pb->walk_objects, &obj->id, obj)) < 0) - return error; + git_oidmap_insert(pb->walk_objects, &obj->id, obj, &error); } *out = obj; return 0; }