vendor/libgit2/src/pack-objects.c in rugged-1.3.2.3 vs vendor/libgit2/src/pack-objects.c in rugged-1.4.2
- old
+ new
@@ -5,10 +5,11 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "pack-objects.h"
+#include "buf.h"
#include "zstream.h"
#include "delta.h"
#include "iterator.h"
#include "netops.h"
#include "pack.h"
@@ -31,11 +32,11 @@
size_t depth;
};
struct tree_walk_context {
git_packbuilder *pb;
- git_buf buf;
+ git_str buf;
};
struct pack_write_context {
git_indexer *indexer;
git_indexer_progress *stats;
@@ -139,11 +140,11 @@
goto on_error;
pb->repo = repo;
pb->nr_threads = 1; /* do not spawn any thread by default */
- if (git_hash_ctx_init(&pb->ctx) < 0 ||
+ if (git_hash_ctx_init(&pb->ctx, GIT_HASH_ALGORITHM_SHA1) < 0 ||
git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
git_repository_odb(&pb->odb, repo) < 0 ||
packbuilder_config(pb) < 0)
goto on_error;
@@ -662,11 +663,11 @@
}
pb->nr_remaining -= pb->nr_written;
} while (pb->nr_remaining && i < pb->nr_objects);
- if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0)
+ if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0)
goto done;
error = write_cb(entry_oid.id, GIT_OID_RAWSZ, cb_data);
done:
@@ -683,12 +684,12 @@
return error;
}
static int write_pack_buf(void *buf, size_t size, void *data)
{
- git_buf *b = (git_buf *)data;
- return git_buf_put(b, buf, size);
+ git_str *b = (git_str *)data;
+ return git_str_put(b, buf, size);
}
static int type_size_sort(const void *_a, const void *_b)
{
const git_pobject *a = (git_pobject *)_a;
@@ -945,11 +946,11 @@
static int find_deltas(git_packbuilder *pb, git_pobject **list,
size_t *list_size, size_t window, size_t depth)
{
git_pobject *po;
- git_buf zbuf = GIT_BUF_INIT;
+ git_str zbuf = GIT_STR_INIT;
struct unpacked *array;
size_t idx = 0, count = 0;
size_t mem_usage = 0;
size_t i;
int error = -1;
@@ -1043,11 +1044,11 @@
po->delta_data = git__malloc(zbuf.size);
GIT_ERROR_CHECK_ALLOC(po->delta_data);
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
po->z_delta_size = zbuf.size;
- git_buf_clear(&zbuf);
+ git_str_clear(&zbuf);
GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
pb->delta_cache_size -= po->delta_size;
pb->delta_cache_size += po->z_delta_size;
GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
@@ -1091,11 +1092,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_str_dispose(&zbuf);
return error;
}
#ifdef GIT_THREADS
@@ -1305,11 +1306,11 @@
#else
#define ll_find_deltas(pb, l, ls, w, d) find_deltas(pb, l, &ls, w, d)
#endif
-static int prepare_pack(git_packbuilder *pb)
+int git_packbuilder__prepare(git_packbuilder *pb)
{
git_pobject **delta_list;
size_t i, n = 0;
if (pb->nr_objects == 0 || pb->done)
@@ -1350,30 +1351,30 @@
pb->done = true;
git__free(delta_list);
return 0;
}
-#define PREPARE_PACK if (prepare_pack(pb) < 0) { return -1; }
+#define PREPARE_PACK if (git_packbuilder__prepare(pb) < 0) { return -1; }
int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t size, void *payload), void *payload)
{
PREPARE_PACK;
return write_pack(pb, cb, payload);
}
-int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+int git_packbuilder__write_buf(git_str *buf, git_packbuilder *pb)
{
- int error;
-
- if ((error = git_buf_sanitize(buf)) < 0)
- return error;
-
PREPARE_PACK;
return write_pack(pb, &write_pack_buf, buf);
}
+int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
+{
+ GIT_BUF_WRAP_PRIVATE(buf, git_packbuilder__write_buf, pb);
+}
+
static int write_cb(void *buf, size_t len, void *payload)
{
struct pack_write_context *ctx = payload;
return git_indexer_append(ctx->indexer, buf, len, ctx->stats);
}
@@ -1384,25 +1385,25 @@
unsigned int mode,
git_indexer_progress_cb progress_cb,
void *progress_cb_payload)
{
int error = -1;
- git_buf object_path = GIT_BUF_INIT;
+ git_str object_path = GIT_STR_INIT;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *indexer = NULL;
git_indexer_progress stats;
struct pack_write_context ctx;
int t;
PREPARE_PACK;
if (path == NULL) {
- if ((error = git_repository_item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
+ if ((error = git_repository__item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
goto cleanup;
- if ((error = git_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
+ if ((error = git_str_joinpath(&object_path, git_str_cstr(&object_path), "pack")) < 0)
goto cleanup;
- path = git_buf_cstr(&object_path);
+ path = git_str_cstr(&object_path);
}
opts.progress_cb = progress_cb;
opts.progress_cb_payload = progress_cb_payload;
@@ -1419,40 +1420,52 @@
goto cleanup;
if ((error = git_indexer_commit(indexer, &stats)) < 0)
goto cleanup;
+#ifndef GIT_DEPRECATE_HARD
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
+#endif
+ pb->pack_name = git__strdup(git_indexer_name(indexer));
+ GIT_ERROR_CHECK_ALLOC(pb->pack_name);
+
cleanup:
git_indexer_free(indexer);
- git_buf_dispose(&object_path);
+ git_str_dispose(&object_path);
return error;
}
#undef PREPARE_PACK
+#ifndef GIT_DEPRECATE_HARD
const git_oid *git_packbuilder_hash(git_packbuilder *pb)
{
return &pb->pack_oid;
}
+#endif
+const char *git_packbuilder_name(git_packbuilder *pb)
+{
+ return pb->pack_name;
+}
+
static int cb_tree_walk(
const char *root, const git_tree_entry *entry, void *payload)
{
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)
return 0;
- if (!(error = git_buf_sets(&ctx->buf, root)) &&
- !(error = git_buf_puts(&ctx->buf, git_tree_entry_name(entry))))
+ if (!(error = git_str_sets(&ctx->buf, root)) &&
+ !(error = git_str_puts(&ctx->buf, git_tree_entry_name(entry))))
error = git_packbuilder_insert(
- ctx->pb, git_tree_entry_id(entry), git_buf_cstr(&ctx->buf));
+ ctx->pb, git_tree_entry_id(entry), git_str_cstr(&ctx->buf));
return error;
}
int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid)
@@ -1472,18 +1485,18 @@
int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
{
int error;
git_tree *tree = NULL;
- struct tree_walk_context context = { pb, GIT_BUF_INIT };
+ struct tree_walk_context context = { pb, GIT_STR_INIT };
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_str_dispose(&context.buf);
return error;
}
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name)
{
@@ -1799,8 +1812,10 @@
git_oidmap_free(pb->walk_objects);
git_pool_clear(&pb->object_pool);
git_hash_ctx_cleanup(&pb->ctx);
git_zstream_free(&pb->zstream);
+
+ git__free(pb->pack_name);
git__free(pb);
}