vendor/libgit2/src/pack-objects.c in rugged-0.27.10 vs vendor/libgit2/src/pack-objects.c in rugged-0.27.10.1
- old
+ new
@@ -36,19 +36,13 @@
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,
- seen:1;
-};
-
#ifdef GIT_THREADS
#define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) do { \
int result = git_mutex_##op(&(pb)->mtx); \
assert(!result); \
@@ -103,11 +97,11 @@
#define config_get(KEY,DST,DFLT) do { \
ret = git_config_get_int64(&val, config, KEY); \
if (!ret) { \
if (!git__is_sizet(val)) { \
- git_error_set(GIT_ERROR_CONFIG, \
+ giterr_set(GITERR_CONFIG, \
"configuration value '%s' is too large", KEY); \
ret = -1; \
goto out; \
} \
(DST) = (size_t)val; \
@@ -137,19 +131,21 @@
git_packbuilder *pb;
*out = NULL;
pb = git__calloc(1, sizeof(*pb));
- GIT_ERROR_CHECK_ALLOC(pb);
+ GITERR_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));
+ git_pool_init(&pb->object_pool, sizeof(git_walk_object));
pb->repo = repo;
pb->nr_threads = 1; /* do not spawn any thread by default */
if (git_hash_ctx_init(&pb->ctx) < 0 ||
@@ -162,11 +158,11 @@
if (git_mutex_init(&pb->cache_mutex) ||
git_mutex_init(&pb->progress_mutex) ||
git_cond_init(&pb->progress_cond))
{
- git_error_set(GIT_ERROR_OS, "failed to initialize packbuilder mutex");
+ giterr_set(GITERR_OS, "failed to initialize packbuilder mutex");
goto on_error;
}
#endif
@@ -190,29 +186,29 @@
#endif
return pb->nr_threads;
}
-static int rehash(git_packbuilder *pb)
+static void rehash(git_packbuilder *pb)
{
git_pobject *po;
+ khiter_t pos;
size_t 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;
+ khiter_t pos;
size_t newsize;
int ret;
assert(pb && oid);
@@ -220,26 +216,24 @@
* have any work to do */
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);
+ GITERR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
+ GITERR_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.");
+ giterr_set(GITERR_NOMEMORY, "packfile too large to fit in memory.");
return -1;
}
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;
+ GITERR_CHECK_ALLOC(pb->object_list);
+ rehash(pb);
}
po = pb->object_list + pb->nr_objects;
memset(po, 0x0, sizeof(*po));
@@ -248,14 +242,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) {
- git_error_set_oom();
- return -1;
+ pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
+ if (ret < 0) {
+ giterr_set_oom();
+ 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();
@@ -267,11 +264,11 @@
ret = pb->progress_cb(
GIT_PACKBUILDER_ADDING_OBJECTS,
pb->nr_objects, 0, pb->progress_cb_payload);
if (ret)
- return git_error_set_after_callback(ret);
+ return giterr_set_after_callback(ret);
}
}
return 0;
}
@@ -296,11 +293,11 @@
if (error < 0 && error != GIT_EBUFS)
goto on_error;
if (error == GIT_EBUFS || delta_size != po->delta_size) {
- git_error_set(GIT_ERROR_INVALID, "delta size changed");
+ giterr_set(GITERR_INVALID, "delta size changed");
goto on_error;
}
*out = delta_buf;
@@ -319,11 +316,11 @@
git_pobject *po,
int (*write_cb)(void *buf, size_t size, void *cb_data),
void *cb_data)
{
git_odb_object *obj = NULL;
- git_object_t type;
+ git_otype type;
unsigned char hdr[10], *zbuf = NULL;
void *data = NULL;
size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len;
int error;
@@ -337,11 +334,11 @@
data = po->delta_data;
else if ((error = get_delta(&data, pb->odb, po)) < 0)
goto done;
data_len = po->delta_size;
- type = GIT_OBJECT_REF_DELTA;
+ type = GIT_OBJ_REF_DELTA;
} else {
if ((error = git_odb_read(&obj, pb->odb, &po->id)) < 0)
goto done;
data = (void *)git_odb_object_data(obj);
@@ -354,11 +351,11 @@
if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
(error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
goto done;
- if (type == GIT_OBJECT_REF_DELTA) {
+ if (type == GIT_OBJ_REF_DELTA) {
if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 ||
(error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ)) < 0)
goto done;
}
@@ -369,11 +366,11 @@
if ((error = write_cb(data, data_len, cb_data)) < 0 ||
(error = git_hash_update(&pb->ctx, data, data_len)) < 0)
goto done;
} else {
zbuf = git__malloc(zbuf_len);
- GIT_ERROR_CHECK_ALLOC(zbuf);
+ GITERR_CHECK_ALLOC(zbuf);
git_zstream_reset(&pb->zstream);
git_zstream_set_input(&pb->zstream, data, data_len);
while (!git_zstream_done(&pb->zstream)) {
@@ -511,16 +508,19 @@
static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
{
git_packbuilder *pb = data;
git_pobject *po;
+ khiter_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;
@@ -588,22 +588,22 @@
/*
* And then all remaining commits and tags.
*/
for (i = last_untagged; i < pb->nr_objects; i++) {
git_pobject *po = pb->object_list + i;
- if (po->type != GIT_OBJECT_COMMIT &&
- po->type != GIT_OBJECT_TAG)
+ if (po->type != GIT_OBJ_COMMIT &&
+ po->type != GIT_OBJ_TAG)
continue;
add_to_write_order(wo, &wo_end, po);
}
/*
* And then all the trees.
*/
for (i = last_untagged; i < pb->nr_objects; i++) {
git_pobject *po = pb->object_list + i;
- if (po->type != GIT_OBJECT_TREE)
+ if (po->type != GIT_OBJ_TREE)
continue;
add_to_write_order(wo, &wo_end, po);
}
/*
@@ -615,11 +615,11 @@
add_family_to_write_order(wo, &wo_end, po);
}
if (wo_end != pb->nr_objects) {
git__free(wo);
- git_error_set(GIT_ERROR_INVALID, "invalid write order");
+ giterr_set(GITERR_INVALID, "invalid write order");
return NULL;
}
return wo;
}
@@ -639,11 +639,11 @@
write_order = compute_write_order(pb);
if (write_order == NULL)
return -1;
if (!git__is_uint32(pb->nr_objects)) {
- git_error_set(GIT_ERROR_INVALID, "too many objects");
+ giterr_set(GITERR_INVALID, "too many objects");
return -1;
}
/* Write pack header */
ph.hdr_signature = htonl(PACK_SIGNATURE);
@@ -796,17 +796,17 @@
if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
return -1;
sz = git_odb_object_size(obj);
trg->data = git__malloc(sz);
- GIT_ERROR_CHECK_ALLOC(trg->data);
+ GITERR_CHECK_ALLOC(trg->data);
memcpy(trg->data, git_odb_object_data(obj), sz);
git_odb_object_free(obj);
if (sz != trg_size) {
- git_error_set(GIT_ERROR_INVALID,
+ giterr_set(GITERR_INVALID,
"inconsistent target object length");
return -1;
}
*mem_usage += sz;
@@ -818,17 +818,17 @@
!git__is_ulong(obj_sz = git_odb_object_size(obj)))
return -1;
sz = obj_sz;
src->data = git__malloc(sz);
- GIT_ERROR_CHECK_ALLOC(src->data);
+ GITERR_CHECK_ALLOC(src->data);
memcpy(src->data, git_odb_object_data(obj), sz);
git_odb_object_free(obj);
if (sz != src_size) {
- git_error_set(GIT_ERROR_INVALID,
+ giterr_set(GITERR_INVALID,
"inconsistent source object length");
return -1;
}
*mem_usage += sz;
@@ -870,11 +870,11 @@
git__free(delta_buf);
return -1;
}
trg_object->delta_data = git__realloc(delta_buf, delta_size);
- GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
+ GITERR_CHECK_ALLOC(trg_object->delta_data);
} else {
/* create delta when writing the pack */
git_packbuilder__cache_unlock(pb);
git__free(delta_buf);
}
@@ -936,11 +936,11 @@
ret = pb->progress_cb(
GIT_PACKBUILDER_DELTAFICATION,
count, pb->nr_objects, pb->progress_cb_payload);
if (ret)
- return git_error_set_after_callback(ret);
+ return giterr_set_after_callback(ret);
}
}
return 0;
}
@@ -955,11 +955,11 @@
size_t mem_usage = 0;
size_t i;
int error = -1;
array = git__calloc(window, sizeof(struct unpacked));
- GIT_ERROR_CHECK_ALLOC(array);
+ GITERR_CHECK_ALLOC(array);
for (;;) {
struct unpacked *n = array + idx;
size_t max_depth, j, best_base = SIZE_MAX;
@@ -1041,11 +1041,11 @@
if (git_zstream_deflatebuf(&zbuf, po->delta_data, po->delta_size) < 0)
goto on_error;
git__free(po->delta_data);
po->delta_data = git__malloc(zbuf.size);
- GIT_ERROR_CHECK_ALLOC(po->delta_data);
+ GITERR_CHECK_ALLOC(po->delta_data);
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
po->z_delta_size = zbuf.size;
git_buf_clear(&zbuf);
@@ -1093,11 +1093,11 @@
for (i = 0; i < window; ++i) {
git__free(array[i].index);
git__free(array[i].data);
}
git__free(array);
- git_buf_dispose(&zbuf);
+ git_buf_free(&zbuf);
return error;
}
#ifdef GIT_THREADS
@@ -1134,11 +1134,11 @@
me->working = 0;
git_cond_signal(&me->pb->progress_cond);
git_packbuilder__progress_unlock(me->pb);
if (git_mutex_lock(&me->mutex)) {
- git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
+ giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex");
return NULL;
}
while (!me->data_ready)
git_cond_wait(&me->cond, &me->mutex);
@@ -1172,11 +1172,11 @@
find_deltas(pb, list, &list_size, window, depth);
return 0;
}
p = git__mallocarray(pb->nr_threads, sizeof(*p));
- GIT_ERROR_CHECK_ALLOC(p);
+ GITERR_CHECK_ALLOC(p);
/* Partition the work among the threads */
for (i = 0; i < pb->nr_threads; ++i) {
size_t sub_size = list_size / (pb->nr_threads - i);
@@ -1213,11 +1213,11 @@
git_cond_init(&p[i].cond);
ret = git_thread_create(&p[i].thread,
threaded_find_deltas, &p[i]);
if (ret) {
- git_error_set(GIT_ERROR_THREAD, "unable to create thread");
+ giterr_set(GITERR_THREAD, "unable to create thread");
return -1;
}
active_threads++;
}
@@ -1282,11 +1282,11 @@
target->remaining = sub_size;
target->working = 1;
git_packbuilder__progress_unlock(pb);
if (git_mutex_lock(&target->mutex)) {
- git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
+ giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex");
git__free(p);
return -1;
}
target->data_ready = 1;
@@ -1323,11 +1323,11 @@
*/
if (pb->progress_cb)
pb->progress_cb(GIT_PACKBUILDER_DELTAFICATION, 0, pb->nr_objects, pb->progress_cb_payload);
delta_list = git__mallocarray(pb->nr_objects, sizeof(*delta_list));
- GIT_ERROR_CHECK_ALLOC(delta_list);
+ GITERR_CHECK_ALLOC(delta_list);
for (i = 0; i < pb->nr_objects; ++i) {
git_pobject *po = pb->object_list + i;
/* Make sure the item is within our size limits */
@@ -1377,29 +1377,25 @@
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;
- opts.progress_cb = progress_cb;
- opts.progress_cb_payload = progress_cb_payload;
-
if (git_indexer_new(
- &indexer, path, mode, pb->odb, &opts) < 0)
+ &indexer, path, mode, pb->odb, progress_cb, progress_cb_payload) < 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;
@@ -1428,11 +1424,11 @@
{
int error;
struct tree_walk_context *ctx = payload;
/* A commit inside a tree represents a submodule commit and should be skipped. */
- if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
+ if (git_tree_entry_type(entry) == GIT_OBJ_COMMIT)
return 0;
if (!(error = git_buf_sets(&ctx->buf, root)) &&
!(error = git_buf_puts(&ctx->buf, git_tree_entry_name(entry))))
error = git_packbuilder_insert(
@@ -1465,42 +1461,42 @@
if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
!(error = git_packbuilder_insert(pb, oid, NULL)))
error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context);
git_tree_free(tree);
- git_buf_dispose(&context.buf);
+ git_buf_free(&context.buf);
return error;
}
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name)
{
git_object *obj;
int error;
assert(pb && id);
- if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
+ if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJ_ANY)) < 0)
return error;
switch (git_object_type(obj)) {
- case GIT_OBJECT_BLOB:
+ case GIT_OBJ_BLOB:
error = git_packbuilder_insert(pb, id, name);
break;
- case GIT_OBJECT_TREE:
+ case GIT_OBJ_TREE:
error = git_packbuilder_insert_tree(pb, id);
break;
- case GIT_OBJECT_COMMIT:
+ case GIT_OBJ_COMMIT:
error = git_packbuilder_insert_commit(pb, id);
break;
- case GIT_OBJECT_TAG:
+ case GIT_OBJ_TAG:
if ((error = git_packbuilder_insert(pb, id, name)) < 0)
goto cleanup;
error = git_packbuilder_insert_recur(pb, git_tag_target_id((git_tag *) obj), NULL);
break;
default:
- git_error_set(GIT_ERROR_INVALID, "unknown object type");
+ giterr_set(GITERR_INVALID, "unknown object type");
error = -1;
}
cleanup:
git_object_free(obj);
@@ -1515,47 +1511,50 @@
size_t git_packbuilder_written(git_packbuilder *pb)
{
return pb->nr_written;
}
-static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
+int lookup_walk_object(git_walk_object **out, git_packbuilder *pb, const git_oid *id)
{
- struct walk_object *obj;
+ git_walk_object *obj;
obj = git_pool_mallocz(&pb->object_pool, 1);
if (!obj) {
- git_error_set_oom();
+ giterr_set_oom();
return -1;
}
git_oid_cpy(&obj->id, id);
*out = obj;
return 0;
}
-static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
+static int retrieve_object(git_walk_object **out, git_packbuilder *pb, const git_oid *id)
{
- struct walk_object *obj;
int error;
+ khiter_t pos;
+ git_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;
}
static int mark_blob_uninteresting(git_packbuilder *pb, const git_oid *id)
{
int error;
- struct walk_object *obj;
+ git_walk_object *obj;
if ((error = retrieve_object(&obj, pb, id)) < 0)
return error;
obj->uninteresting = 1;
@@ -1563,11 +1562,11 @@
return 0;
}
static int mark_tree_uninteresting(git_packbuilder *pb, const git_oid *id)
{
- struct walk_object *obj;
+ git_walk_object *obj;
git_tree *tree;
int error;
size_t i;
if ((error = retrieve_object(&obj, pb, id)) < 0)
@@ -1583,15 +1582,15 @@
for (i = 0; i < git_tree_entrycount(tree); i++) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
const git_oid *entry_id = git_tree_entry_id(entry);
switch (git_tree_entry_type(entry)) {
- case GIT_OBJECT_TREE:
+ case GIT_OBJ_TREE:
if ((error = mark_tree_uninteresting(pb, entry_id)) < 0)
goto cleanup;
break;
- case GIT_OBJECT_BLOB:
+ case GIT_OBJ_BLOB:
if ((error = mark_blob_uninteresting(pb, entry_id)) < 0)
goto cleanup;
break;
default:
/* it's a submodule or something unknown, we don't want it */
@@ -1635,11 +1634,11 @@
int insert_tree(git_packbuilder *pb, git_tree *tree)
{
size_t i;
int error;
git_tree *subtree;
- struct walk_object *obj;
+ git_walk_object *obj;
const char *name;
if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
return error;
@@ -1653,22 +1652,22 @@
for (i = 0; i < git_tree_entrycount(tree); i++) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
const git_oid *entry_id = git_tree_entry_id(entry);
switch (git_tree_entry_type(entry)) {
- case GIT_OBJECT_TREE:
+ case GIT_OBJ_TREE:
if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0)
return error;
error = insert_tree(pb, subtree);
git_tree_free(subtree);
if (error < 0)
return error;
break;
- case GIT_OBJECT_BLOB:
+ case GIT_OBJ_BLOB:
if ((error = retrieve_object(&obj, pb, entry_id)) < 0)
return error;
if (obj->uninteresting)
continue;
name = git_tree_entry_name(entry);
@@ -1683,11 +1682,11 @@
return error;
}
-int insert_commit(git_packbuilder *pb, struct walk_object *obj)
+int insert_commit(git_packbuilder *pb, git_walk_object *obj)
{
int error;
git_commit *commit = NULL;
git_tree *tree = NULL;
@@ -1713,10 +1712,10 @@
int git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk)
{
int error;
git_oid id;
- struct walk_object *obj;
+ git_walk_object *obj;
assert(pb && walk);
if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
return error;