summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/attr.c2
-rw-r--r--src/blob.c6
-rw-r--r--src/branch.c21
-rw-r--r--src/checkout.c2
-rw-r--r--src/clone.c14
-rw-r--r--src/commit.c53
-rw-r--r--src/commit.h4
-rw-r--r--src/commit_list.c190
-rw-r--r--src/commit_list.h49
-rw-r--r--src/config.c74
-rw-r--r--src/config.h2
-rw-r--r--src/config_file.c24
-rw-r--r--src/config_file.h14
-rw-r--r--src/delta.c21
-rw-r--r--src/delta.h36
-rw-r--r--src/diff.c4
-rw-r--r--src/diff_output.c189
-rw-r--r--src/diff_output.h16
-rw-r--r--src/hash/hash_win32.c4
-rw-r--r--src/index.c71
-rw-r--r--src/index.h2
-rw-r--r--src/indexer.c4
-rw-r--r--src/iterator.c14
-rw-r--r--src/merge.c196
-rw-r--r--src/merge.h3
-rw-r--r--src/notes.c54
-rw-r--r--src/object.c6
-rw-r--r--src/odb.c4
-rw-r--r--src/odb_loose.c4
-rw-r--r--src/odb_pack.c2
-rw-r--r--src/pack-objects.c30
-rw-r--r--src/pack.c2
-rw-r--r--src/pack.h2
-rw-r--r--src/reflog.c41
-rw-r--r--src/refs.c50
-rw-r--r--src/remote.c46
-rw-r--r--src/remote.h8
-rw-r--r--src/repository.c32
-rw-r--r--src/reset.c8
-rw-r--r--src/revparse.c51
-rw-r--r--src/revwalk.c507
-rw-r--r--src/revwalk.h44
-rw-r--r--src/stash.c22
-rw-r--r--src/status.c18
-rw-r--r--src/submodule.c40
-rw-r--r--src/tag.c32
-rw-r--r--src/transports/cred.c6
-rw-r--r--src/transports/local.c4
-rw-r--r--src/transports/smart.c6
-rw-r--r--src/transports/smart.h2
-rw-r--r--src/transports/smart_protocol.c12
-rw-r--r--src/transports/winhttp.c2
-rw-r--r--src/tree.c91
-rw-r--r--src/tree.h3
-rw-r--r--src/util.c2
-rw-r--r--src/vector.c37
-rw-r--r--src/vector.h22
-rw-r--r--src/win32/posix_w32.c8
58 files changed, 1139 insertions, 1074 deletions
diff --git a/src/attr.c b/src/attr.c
index b5757446f..95d63bea8 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -295,7 +295,7 @@ static int load_attr_blob_from_index(
{
int error;
git_index *index;
- git_index_entry *entry;
+ const git_index_entry *entry;
if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
(error = git_index_find(index, relfile)) < 0)
diff --git a/src/blob.c b/src/blob.c
index 76d265faa..b168df137 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -19,10 +19,10 @@ const void *git_blob_rawcontent(git_blob *blob)
return blob->odb_object->raw.data;
}
-size_t git_blob_rawsize(git_blob *blob)
+git_off_t git_blob_rawsize(git_blob *blob)
{
assert(blob);
- return blob->odb_object->raw.len;
+ return (git_off_t)blob->odb_object->raw.len;
}
int git_blob__getbuf(git_buf *buffer, git_blob *blob)
@@ -205,7 +205,7 @@ static int blob_create_internal(git_oid *oid, git_repository *repo, const char *
return error;
}
-int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path)
+int git_blob_create_fromworkdir(git_oid *oid, git_repository *repo, const char *path)
{
git_buf full_path = GIT_BUF_INIT;
const char *workdir;
diff --git a/src/branch.c b/src/branch.c
index c6173caca..5d7d443dc 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -44,12 +44,6 @@ cleanup:
return error;
}
-static int create_error_invalid(const char *msg)
-{
- giterr_set(GITERR_INVALID, "Cannot create branch - %s", msg);
- return -1;
-}
-
static int not_a_local_branch(git_reference *ref)
{
giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
@@ -60,31 +54,26 @@ int git_branch_create(
git_reference **ref_out,
git_repository *repository,
const char *branch_name,
- const git_object *target,
+ const git_commit *commit,
int force)
{
- git_object *commit = NULL;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT;
int error = -1;
- assert(branch_name && target && ref_out);
- assert(git_object_owner(target) == repository);
-
- if (git_object_peel(&commit, (git_object *)target, GIT_OBJ_COMMIT) < 0)
- return create_error_invalid("The given target does not resolve to a commit");
+ assert(branch_name && commit && ref_out);
+ assert(git_object_owner((const git_object *)commit) == repository);
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
goto cleanup;
- error = git_reference_create_oid(&branch, repository,
- git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);
+ error = git_reference_create(&branch, repository,
+ git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force);
if (!error)
*ref_out = branch;
cleanup:
- git_object_free(commit);
git_buf_free(&canonical_branch_name);
return error;
}
diff --git a/src/checkout.c b/src/checkout.c
index c4e4f999a..a3166bfa5 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -693,7 +693,7 @@ cleanup:
int git_checkout_tree(
git_repository *repo,
- git_object *treeish,
+ const git_object *treeish,
git_checkout_opts *opts)
{
int error = 0;
diff --git a/src/clone.c b/src/clone.c
index 9ef6f8100..7d49b398b 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -28,18 +28,18 @@ static int create_branch(
const git_oid *target,
const char *name)
{
- git_object *head_obj = NULL;
+ git_commit *head_obj = NULL;
git_reference *branch_ref;
int error;
/* Find the target commit */
- if ((error = git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY)) < 0)
+ if ((error = git_commit_lookup(&head_obj, repo, target)) < 0)
return error;
/* Create the new branch */
error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
- git_object_free(head_obj);
+ git_commit_free(head_obj);
if (!error)
*branch = branch_ref;
@@ -122,7 +122,7 @@ static int reference_matches_remote_head(
if (git_buf_len(&head_info->branchname) > 0)
return 0;
- if (git_reference_name_to_oid(
+ if (git_reference_name_to_id(
&oid,
head_info->repo,
reference_name) < 0) {
@@ -278,7 +278,7 @@ static int setup_remotes_and_fetch(
git_remote_set_update_fetchhead(origin, 0);
/* Connect and download everything */
- if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
+ if (!git_remote_connect(origin, GIT_DIRECTION_FETCH)) {
if (!git_remote_download(origin, progress_cb, progress_payload)) {
/* Create "origin/foo" branches for all remote branches */
if (!git_remote_update_tips(origin)) {
@@ -381,9 +381,9 @@ int git_clone(
git_repository **out,
const char *origin_url,
const char *workdir_path,
+ git_checkout_opts *checkout_opts,
git_transfer_progress_callback fetch_progress_cb,
- void *fetch_progress_payload,
- git_checkout_opts *checkout_opts)
+ void *fetch_progress_payload)
{
assert(out && origin_url && workdir_path);
diff --git a/src/commit.c b/src/commit.c
index b66978aff..4072518ff 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -22,18 +22,18 @@ static void clear_parents(git_commit *commit)
{
unsigned int i;
- for (i = 0; i < commit->parent_oids.length; ++i) {
- git_oid *parent = git_vector_get(&commit->parent_oids, i);
+ for (i = 0; i < commit->parent_ids.length; ++i) {
+ git_oid *parent = git_vector_get(&commit->parent_ids, i);
git__free(parent);
}
- git_vector_clear(&commit->parent_oids);
+ git_vector_clear(&commit->parent_ids);
}
void git_commit__free(git_commit *commit)
{
clear_parents(commit);
- git_vector_free(&commit->parent_oids);
+ git_vector_free(&commit->parent_ids);
git_signature_free(commit->author);
git_signature_free(commit->committer);
@@ -43,11 +43,6 @@ void git_commit__free(git_commit *commit)
git__free(commit);
}
-const git_oid *git_commit_id(git_commit *c)
-{
- return git_object_id((git_object *)c);
-}
-
int git_commit_create_v(
git_oid *oid,
git_repository *repo,
@@ -141,26 +136,26 @@ int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
const char *buffer = data;
const char *buffer_end = (const char *)data + len;
- git_oid parent_oid;
+ git_oid parent_id;
- git_vector_init(&commit->parent_oids, 4, NULL);
+ git_vector_init(&commit->parent_ids, 4, NULL);
- if (git_oid__parse(&commit->tree_oid, &buffer, buffer_end, "tree ") < 0)
+ if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0)
goto bad_buffer;
/*
* TODO: commit grafts!
*/
- while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == 0) {
- git_oid *new_oid;
+ while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) {
+ git_oid *new_id;
- new_oid = git__malloc(sizeof(git_oid));
- GITERR_CHECK_ALLOC(new_oid);
+ new_id = git__malloc(sizeof(git_oid));
+ GITERR_CHECK_ALLOC(new_id);
- git_oid_cpy(new_oid, &parent_oid);
+ git_oid_cpy(new_id, &parent_id);
- if (git_vector_insert(&commit->parent_oids, new_oid) < 0)
+ if (git_vector_insert(&commit->parent_ids, new_id) < 0)
return -1;
}
@@ -214,7 +209,7 @@ int git_commit__parse(git_commit *commit, git_odb_object *obj)
}
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
- _rvalue git_commit_##_name(git_commit *commit) \
+ _rvalue git_commit_##_name(const git_commit *commit) \
{\
assert(commit); \
return _return; \
@@ -226,34 +221,34 @@ GIT_COMMIT_GETTER(const char *, message, commit->message)
GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding)
GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
-GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_oids.length)
-GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid);
+GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_ids.length)
+GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id);
-int git_commit_tree(git_tree **tree_out, git_commit *commit)
+int git_commit_tree(git_tree **tree_out, const git_commit *commit)
{
assert(commit);
- return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_oid);
+ return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_id);
}
-const git_oid *git_commit_parent_oid(git_commit *commit, unsigned int n)
+const git_oid *git_commit_parent_id(git_commit *commit, unsigned int n)
{
assert(commit);
- return git_vector_get(&commit->parent_oids, n);
+ return git_vector_get(&commit->parent_ids, n);
}
int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
{
- const git_oid *parent_oid;
+ const git_oid *parent_id;
assert(commit);
- parent_oid = git_commit_parent_oid(commit, n);
- if (parent_oid == NULL) {
+ parent_id = git_commit_parent_id(commit, n);
+ if (parent_id == NULL) {
giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
return GIT_ENOTFOUND;
}
- return git_commit_lookup(parent, commit->object.repo, parent_oid);
+ return git_commit_lookup(parent, commit->object.repo, parent_id);
}
int git_commit_nth_gen_ancestor(
diff --git a/src/commit.h b/src/commit.h
index d9f492862..1d1dc0ddb 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -17,8 +17,8 @@
struct git_commit {
git_object object;
- git_vector parent_oids;
- git_oid tree_oid;
+ git_vector parent_ids;
+ git_oid tree_id;
git_signature *author;
git_signature *committer;
diff --git a/src/commit_list.c b/src/commit_list.c
new file mode 100644
index 000000000..c1a7b223f
--- /dev/null
+++ b/src/commit_list.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "commit_list.h"
+#include "common.h"
+#include "revwalk.h"
+#include "pool.h"
+#include "odb.h"
+
+int git_commit_list_time_cmp(void *a, void *b)
+{
+ git_commit_list_node *commit_a = (git_commit_list_node *)a;
+ git_commit_list_node *commit_b = (git_commit_list_node *)b;
+
+ return (commit_a->time < commit_b->time);
+}
+
+git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p)
+{
+ git_commit_list *new_list = git__malloc(sizeof(git_commit_list));
+ if (new_list != NULL) {
+ new_list->item = item;
+ new_list->next = *list_p;
+ }
+ *list_p = new_list;
+ return new_list;
+}
+
+git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p)
+{
+ git_commit_list **pp = list_p;
+ git_commit_list *p;
+
+ while ((p = *pp) != NULL) {
+ if (git_commit_list_time_cmp(p->item, item) < 0)
+ break;
+
+ pp = &p->next;
+ }
+
+ return git_commit_list_insert(item, pp);
+}
+
+git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
+{
+ return (git_commit_list_node *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
+}
+
+static int commit_error(git_commit_list_node *commit, const char *msg)
+{
+ char commit_oid[GIT_OID_HEXSZ + 1];
+ git_oid_fmt(commit_oid, &commit->oid);
+ commit_oid[GIT_OID_HEXSZ] = '\0';
+
+ giterr_set(GITERR_ODB, "Failed to parse commit %s - %s", commit_oid, msg);
+
+ return -1;
+}
+
+static git_commit_list_node **alloc_parents(
+ git_revwalk *walk, git_commit_list_node *commit, size_t n_parents)
+{
+ if (n_parents <= PARENTS_PER_COMMIT)
+ return (git_commit_list_node **)((char *)commit + sizeof(git_commit_list_node));
+
+ return (git_commit_list_node **)git_pool_malloc(
+ &walk->commit_pool, (uint32_t)(n_parents * sizeof(git_commit_list_node *)));
+}
+
+
+void git_commit_list_free(git_commit_list **list_p)
+{
+ git_commit_list *list = *list_p;
+
+ if (list == NULL)
+ return;
+
+ while (list) {
+ git_commit_list *temp = list;
+ list = temp->next;
+ git__free(temp);
+ }
+
+ *list_p = NULL;
+}
+
+git_commit_list_node *git_commit_list_pop(git_commit_list **stack)
+{
+ git_commit_list *top = *stack;
+ git_commit_list_node *item = top ? top->item : NULL;
+
+ if (top) {
+ *stack = top->next;
+ git__free(top);
+ }
+ return item;
+}
+
+static int commit_quick_parse(git_revwalk *walk, git_commit_list_node *commit, git_rawobj *raw)
+{
+ const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
+ unsigned char *buffer = raw->data;
+ unsigned char *buffer_end = buffer + raw->len;
+ unsigned char *parents_start, *committer_start;
+ int i, parents = 0;
+ int commit_time;
+
+ buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
+
+ parents_start = buffer;
+ while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
+ parents++;
+ buffer += parent_len;
+ }
+
+ commit->parents = alloc_parents(walk, commit, parents);
+ GITERR_CHECK_ALLOC(commit->parents);
+
+ buffer = parents_start;
+ for (i = 0; i < parents; ++i) {
+ git_oid oid;
+
+ if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0)
+ return -1;
+
+ commit->parents[i] = commit_lookup(walk, &oid);
+ if (commit->parents[i] == NULL)
+ return -1;
+
+ buffer += parent_len;
+ }
+
+ commit->out_degree = (unsigned short)parents;
+
+ if ((committer_start = buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
+ return commit_error(commit, "object is corrupted");
+
+ buffer++;
+
+ if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
+ return commit_error(commit, "object is corrupted");
+
+ /* Skip trailing spaces */
+ while (buffer > committer_start && git__isspace(*buffer))
+ buffer--;
+
+ /* Seek for the begining of the pack of digits */
+ while (buffer > committer_start && git__isdigit(*buffer))
+ buffer--;
+
+ /* Skip potential timezone offset */
+ if ((buffer > committer_start) && (*buffer == '+' || *buffer == '-')) {
+ buffer--;
+
+ while (buffer > committer_start && git__isspace(*buffer))
+ buffer--;
+
+ while (buffer > committer_start && git__isdigit(*buffer))
+ buffer--;
+ }
+
+ if ((buffer == committer_start) || (git__strtol32(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
+ return commit_error(commit, "cannot parse commit time");
+
+ commit->time = (time_t)commit_time;
+ commit->parsed = 1;
+ return 0;
+}
+
+int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
+{
+ git_odb_object *obj;
+ int error;
+
+ if (commit->parsed)
+ return 0;
+
+ if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
+ return error;
+ assert(obj->raw.type == GIT_OBJ_COMMIT);
+
+ error = commit_quick_parse(walk, commit, &obj->raw);
+ git_odb_object_free(obj);
+ return error;
+}
+
diff --git a/src/commit_list.h b/src/commit_list.h
new file mode 100644
index 000000000..ba809c901
--- /dev/null
+++ b/src/commit_list.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_commit_list_h__
+#define INCLUDE_commit_list_h__
+
+#include "git2/oid.h"
+
+#define PARENT1 (1 << 0)
+#define PARENT2 (1 << 1)
+#define RESULT (1 << 2)
+#define STALE (1 << 3)
+
+#define PARENTS_PER_COMMIT 2
+#define COMMIT_ALLOC \
+ (sizeof(git_commit_list_node) + PARENTS_PER_COMMIT * sizeof(git_commit_list_node *))
+
+typedef struct git_commit_list_node {
+ git_oid oid;
+ uint32_t time;
+ unsigned int seen:1,
+ uninteresting:1,
+ topo_delay:1,
+ parsed:1,
+ flags : 4;
+
+ unsigned short in_degree;
+ unsigned short out_degree;
+
+ struct git_commit_list_node **parents;
+} git_commit_list_node;
+
+typedef struct git_commit_list {
+ git_commit_list_node *item;
+ struct git_commit_list *next;
+} git_commit_list;
+
+git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk);
+int git_commit_list_time_cmp(void *a, void *b);
+void git_commit_list_free(git_commit_list **list_p);
+git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p);
+git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_commit_list **list_p);
+int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit);
+git_commit_list_node *git_commit_list_pop(git_commit_list **stack);
+
+#endif
diff --git a/src/config.c b/src/config.c
index fc9ea65fe..5ee0d39ff 100644
--- a/src/config.c
+++ b/src/config.c
@@ -19,13 +19,13 @@
typedef struct {
git_refcount rc;
- git_config_file *file;
+ git_config_backend *file;
unsigned int level;
} file_internal;
static void file_internal_free(file_internal *internal)
{
- git_config_file *file;
+ git_config_backend *file;
file = internal->file;
file->free(file);
@@ -87,7 +87,7 @@ int git_config_add_file_ondisk(
unsigned int level,
int force)
{
- git_config_file *file = NULL;
+ git_config_backend *file = NULL;
int res;
assert(cfg && path);
@@ -100,7 +100,7 @@ int git_config_add_file_ondisk(
if (git_config_file__ondisk(&file, path) < 0)
return -1;
- if ((res = git_config_add_file(cfg, file, level, force)) < 0) {
+ if ((res = git_config_add_backend(cfg, file, level, force)) < 0) {
/*
* free manually; the file is not owned by the config
* instance yet and will not be freed on cleanup
@@ -132,7 +132,7 @@ int git_config_open_ondisk(git_config **out, const char *path)
static int find_internal_file_by_level(
file_internal **internal_out,
- git_config *cfg,
+ const git_config *cfg,
int level)
{
int pos = -1;
@@ -224,7 +224,7 @@ static int git_config__add_internal(
int git_config_open_level(
git_config **cfg_out,
- git_config *cfg_parent,
+ const git_config *cfg_parent,
unsigned int level)
{
git_config *cfg;
@@ -247,9 +247,9 @@ int git_config_open_level(
return 0;
}
-int git_config_add_file(
+int git_config_add_backend(
git_config *cfg,
- git_config_file *file,
+ git_config_backend *file,
unsigned int level,
int force)
{
@@ -284,7 +284,7 @@ int git_config_refresh(git_config *cfg)
for (i = 0; i < cfg->files.length && !error; ++i) {
file_internal *internal = git_vector_get(&cfg->files, i);
- git_config_file *file = internal->file;
+ git_config_backend *file = internal->file;
error = file->refresh(file);
}
@@ -296,34 +296,34 @@ int git_config_refresh(git_config *cfg)
*/
int git_config_foreach(
- git_config *cfg, int (*fn)(const git_config_entry *, void *), void *data)
+ const git_config *cfg, git_config_foreach_cb cb, void *payload)
{
- return git_config_foreach_match(cfg, NULL, fn, data);
+ return git_config_foreach_match(cfg, NULL, cb, payload);
}
int git_config_foreach_match(
- git_config *cfg,
+ const git_config *cfg,
const char *regexp,
- int (*fn)(const git_config_entry *, void *),
- void *data)
+ git_config_foreach_cb cb,
+ void *payload)
{
int ret = 0;
unsigned int i;
file_internal *internal;
- git_config_file *file;
+ git_config_backend *file;
for (i = 0; i < cfg->files.length && ret == 0; ++i) {
internal = git_vector_get(&cfg->files, i);
file = internal->file;
- ret = file->foreach(file, regexp, fn, data);
+ ret = file->foreach(file, regexp, cb, payload);
}
return ret;
}
-int git_config_delete(git_config *cfg, const char *name)
+int git_config_delete_entry(git_config *cfg, const char *name)
{
- git_config_file *file;
+ git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
@@ -355,7 +355,7 @@ int git_config_set_bool(git_config *cfg, const char *name, int value)
int git_config_set_string(git_config *cfg, const char *name, const char *value)
{
- git_config_file *file;
+ git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
@@ -369,9 +369,9 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
***********/
int git_config_get_mapped(
int *out,
- git_config *cfg,
+ const git_config *cfg,
const char *name,
- git_cvar_map *maps,
+ const git_cvar_map *maps,
size_t map_n)
{
const char *value;
@@ -383,7 +383,7 @@ int git_config_get_mapped(
return git_config_lookup_map_value(out, maps, map_n, value);
}
-int git_config_get_int64(int64_t *out, git_config *cfg, const char *name)
+int git_config_get_int64(int64_t *out, const git_config *cfg, const char *name)
{
const char *value;
int ret;
@@ -394,7 +394,7 @@ int git_config_get_int64(int64_t *out, git_config *cfg, const char *name)
return git_config_parse_int64(out, value);
}
-int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
+int git_config_get_int32(int32_t *out, const git_config *cfg, const char *name)
{
const char *value;
int ret;
@@ -405,7 +405,7 @@ int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
return git_config_parse_int32(out, value);
}
-static int get_string_at_file(const char **out, git_config_file *file, const char *name)
+static int get_string_at_file(const char **out, const git_config_backend *file, const char *name)
{
const git_config_entry *entry;
int res;
@@ -417,7 +417,7 @@ static int get_string_at_file(const char **out, git_config_file *file, const cha
return res;
}
-static int get_string(const char **out, git_config *cfg, const char *name)
+static int get_string(const char **out, const git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
@@ -434,7 +434,7 @@ static int get_string(const char **out, git_config *cfg, const char *name)
return GIT_ENOTFOUND;
}
-int git_config_get_bool(int *out, git_config *cfg, const char *name)
+int git_config_get_bool(int *out, const git_config *cfg, const char *name)
{
const char *value = NULL;
int ret;
@@ -445,7 +445,7 @@ int git_config_get_bool(int *out, git_config *cfg, const char *name)
return git_config_parse_bool(out, value);
}
-int git_config_get_string(const char **out, git_config *cfg, const char *name)
+int git_config_get_string(const char **out, const git_config *cfg, const char *name)
{
int ret;
const char *str = NULL;
@@ -457,7 +457,7 @@ int git_config_get_string(const char **out, git_config *cfg, const char *name)
return 0;
}
-int git_config_get_entry(const git_config_entry **out, git_config *cfg, const char *name)
+int git_config_get_entry(const git_config_entry **out, const git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
@@ -467,7 +467,7 @@ int git_config_get_entry(const git_config_entry **out, git_config *cfg, const ch
*out = NULL;
git_vector_foreach(&cfg->files, i, internal) {
- git_config_file *file = internal->file;
+ git_config_backend *file = internal->file;
int ret = file->get(file, name, out);
if (ret != GIT_ENOTFOUND)
return ret;
@@ -476,11 +476,11 @@ int git_config_get_entry(const git_config_entry **out, git_config *cfg, const ch
return GIT_ENOTFOUND;
}
-int git_config_get_multivar(git_config *cfg, const char *name, const char *regexp,
- int (*fn)(const git_config_entry *entry, void *data), void *data)
+int git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp,
+ git_config_foreach_cb cb, void *payload)
{
file_internal *internal;
- git_config_file *file;
+ git_config_backend *file;
int ret = GIT_ENOTFOUND;
size_t i;
@@ -493,7 +493,7 @@ int git_config_get_multivar(git_config *cfg, const char *name, const char *regex
for (i = cfg->files.length; i > 0; --i) {
internal = git_vector_get(&cfg->files, i - 1);
file = internal->file;
- ret = file->get_multivar(file, name, regexp, fn, data);
+ ret = file->get_multivar(file, name, regexp, cb, payload);
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
}
@@ -503,7 +503,7 @@ int git_config_get_multivar(git_config *cfg, const char *name, const char *regex
int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value)
{
- git_config_file *file;
+ git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
@@ -634,7 +634,7 @@ int git_config_open_default(git_config **out)
***********/
int git_config_lookup_map_value(
int *out,
- git_cvar_map *maps,
+ const git_cvar_map *maps,
size_t map_n,
const char *value)
{
@@ -644,7 +644,7 @@ int git_config_lookup_map_value(
goto fail_parse;
for (i = 0; i < map_n; ++i) {
- git_cvar_map *m = maps + i;
+ const git_cvar_map *m = maps + i;
switch (m->cvar_type) {
case GIT_CVAR_FALSE:
@@ -790,7 +790,7 @@ static int rename_config_entries_cb(
return error;
}
- return git_config_delete(data->config, entry->name);
+ return git_config_delete_entry(data->config, entry->name);
}
int git_config_rename_section(
diff --git a/src/config.h b/src/config.h
index c7595ee79..ac8da6ff2 100644
--- a/src/config.h
+++ b/src/config.h
@@ -43,6 +43,6 @@ extern int git_config_rename_section(
* @param out the new backend
* @param path where the config file is located
*/
-extern int git_config_file__ondisk(struct git_config_file **out, const char *path);
+extern int git_config_file__ondisk(struct git_config_backend **out, const char *path);
#endif
diff --git a/src/config_file.c b/src/config_file.c
index 1209c53df..7cc812aa4 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -64,7 +64,7 @@ typedef struct cvar_t {
(iter) = (tmp))
typedef struct {
- git_config_file parent;
+ git_config_backend parent;
git_strmap *values;
@@ -149,7 +149,7 @@ static void free_vars(git_strmap *values)
git_strmap_free(values);
}
-static int config_open(git_config_file *cfg, unsigned int level)
+static int config_open(git_config_backend *cfg, unsigned int level)
{
int res;
diskfile_backend *b = (diskfile_backend *)cfg;
@@ -176,7 +176,7 @@ static int config_open(git_config_file *cfg, unsigned int level)
return res;
}
-static int config_refresh(git_config_file *cfg)
+static int config_refresh(git_config_backend *cfg)
{
int res, updated = 0;
diskfile_backend *b = (diskfile_backend *)cfg;
@@ -203,7 +203,7 @@ static int config_refresh(git_config_file *cfg)
return res;
}
-static void backend_free(git_config_file *_backend)
+static void backend_free(git_config_backend *_backend)
{
diskfile_backend *backend = (diskfile_backend *)_backend;
@@ -216,7 +216,7 @@ static void backend_free(git_config_file *_backend)
}
static int file_foreach(
- git_config_file *backend,
+ git_config_backend *backend,
const char *regexp,
int (*fn)(const git_config_entry *, void *),
void *data)
@@ -262,7 +262,7 @@ cleanup:
return result;
}
-static int config_set(git_config_file *cfg, const char *name, const char *value)
+static int config_set(git_config_backend *cfg, const char *name, const char *value)
{
cvar_t *var = NULL, *old_var;
diskfile_backend *b = (diskfile_backend *)cfg;
@@ -346,7 +346,7 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
/*
* Internal function that actually gets the value in string form
*/
-static int config_get(git_config_file *cfg, const char *name, const git_config_entry **out)
+static int config_get(const git_config_backend *cfg, const char *name, const git_config_entry **out)
{
diskfile_backend *b = (diskfile_backend *)cfg;
char *key;
@@ -368,7 +368,7 @@ static int config_get(git_config_file *cfg, const char *name, const git_config_e
}
static int config_get_multivar(
- git_config_file *cfg,
+ git_config_backend *cfg,
const char *name,
const char *regex_str,
int (*fn)(const git_config_entry *, void *),
@@ -431,7 +431,7 @@ static int config_get_multivar(
}
static int config_set_multivar(
- git_config_file *cfg, const char *name, const char *regexp, const char *value)
+ git_config_backend *cfg, const char *name, const char *regexp, const char *value)
{
int replaced = 0;
cvar_t *var, *newvar;
@@ -506,7 +506,7 @@ static int config_set_multivar(
return result;
}
-static int config_delete(git_config_file *cfg, const char *name)
+static int config_delete(git_config_backend *cfg, const char *name)
{
cvar_t *var;
diskfile_backend *b = (diskfile_backend *)cfg;
@@ -540,7 +540,7 @@ static int config_delete(git_config_file *cfg, const char *name)
return result;
}
-int git_config_file__ondisk(git_config_file **out, const char *path)
+int git_config_file__ondisk(git_config_backend **out, const char *path)
{
diskfile_backend *backend;
@@ -562,7 +562,7 @@ int git_config_file__ondisk(git_config_file **out, const char *path)
backend->parent.refresh = config_refresh;
backend->parent.free = backend_free;
- *out = (git_config_file *)backend;
+ *out = (git_config_backend *)backend;
return 0;
}
diff --git a/src/config_file.h b/src/config_file.h
index b500dd64f..a9671b68d 100644
--- a/src/config_file.h
+++ b/src/config_file.h
@@ -9,36 +9,36 @@
#include "git2/config.h"
-GIT_INLINE(int) git_config_file_open(git_config_file *cfg, unsigned int level)
+GIT_INLINE(int) git_config_file_open(git_config_backend *cfg, unsigned int level)
{
return cfg->open(cfg, level);
}
-GIT_INLINE(void) git_config_file_free(git_config_file *cfg)
+GIT_INLINE(void) git_config_file_free(git_config_backend *cfg)
{
cfg->free(cfg);
}
GIT_INLINE(int) git_config_file_get_string(
- const git_config_entry **out, git_config_file *cfg, const char *name)
+ const git_config_entry **out, git_config_backend *cfg, const char *name)
{
return cfg->get(cfg, name, out);
}
GIT_INLINE(int) git_config_file_set_string(
- git_config_file *cfg, const char *name, const char *value)
+ git_config_backend *cfg, const char *name, const char *value)
{
return cfg->set(cfg, name, value);
}
GIT_INLINE(int) git_config_file_delete(
- git_config_file *cfg, const char *name)
+ git_config_backend *cfg, const char *name)
{
return cfg->del(cfg, name);
}
GIT_INLINE(int) git_config_file_foreach(
- git_config_file *cfg,
+ git_config_backend *cfg,
int (*fn)(const git_config_entry *entry, void *data),
void *data)
{
@@ -46,7 +46,7 @@ GIT_INLINE(int) git_config_file_foreach(
}
GIT_INLINE(int) git_config_file_foreach_match(
- git_config_file *cfg,
+ git_config_backend *cfg,
const char *regexp,
int (*fn)(const git_config_entry *entry, void *data),
void *data)
diff --git a/src/delta.c b/src/delta.c
index 49f7df017..2514dccaf 100644
--- a/src/delta.c
+++ b/src/delta.c
@@ -148,7 +148,7 @@ git_delta_create_index(const void *buf, unsigned long bufsize)
/* Determine index hash size. Note that indexing skips the
first byte to allow for optimizing the Rabin's polynomial
initialization in create_delta(). */
- entries = (bufsize - 1) / RABIN_WINDOW;
+ entries = (unsigned int)(bufsize - 1) / RABIN_WINDOW;
if (bufsize >= 0xffffffffUL) {
/*
* Current delta format can't encode offsets into
@@ -317,9 +317,12 @@ unsigned long git_delta_sizeof_index(struct git_delta_index *index)
#define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7)
void *
-git_delta_create(const struct git_delta_index *index,
- const void *trg_buf, unsigned long trg_size,
- unsigned long *delta_size, unsigned long max_size)
+git_delta_create(
+ const struct git_delta_index *index,
+ const void *trg_buf,
+ unsigned long trg_size,
+ unsigned long *delta_size,
+ unsigned long max_size)
{
unsigned int i, outpos, outsize, moff, msize, val;
int inscnt;
@@ -332,7 +335,7 @@ git_delta_create(const struct git_delta_index *index,
outpos = 0;
outsize = 8192;
if (max_size && outsize >= max_size)
- outsize = max_size + MAX_OP_SIZE + 1;
+ outsize = (unsigned int)(max_size + MAX_OP_SIZE + 1);
out = git__malloc(outsize);
if (!out)
return NULL;
@@ -377,19 +380,19 @@ git_delta_create(const struct git_delta_index *index,
for (entry = index->hash[i]; entry < index->hash[i+1]; entry++) {
const unsigned char *ref = entry->ptr;
const unsigned char *src = data;
- unsigned int ref_size = ref_top - ref;
+ unsigned int ref_size = (unsigned int)(ref_top - ref);
if (entry->val != val)
continue;
if (ref_size > (unsigned int)(top - src))
- ref_size = top - src;
+ ref_size = (unsigned int)(top - src);
if (ref_size <= msize)
break;
while (ref_size-- && *src++ == *ref)
ref++;
if (msize < (unsigned int)(ref - entry->ptr)) {
/* this is our best match so far */
- msize = ref - entry->ptr;
- moff = entry->ptr - ref_data;
+ msize = (unsigned int)(ref - entry->ptr);
+ moff = (unsigned int)(entry->ptr - ref_data);
if (msize >= 4096) /* good enough */
break;
}
diff --git a/src/delta.h b/src/delta.h
index b0b8e4183..4ca327992 100644
--- a/src/delta.h
+++ b/src/delta.h
@@ -46,11 +46,12 @@ extern unsigned long git_delta_sizeof_index(struct git_delta_index *index);
* returned and *delta_size is updated with its size. The returned buffer
* must be freed by the caller.
*/
-extern void *
-git_delta_create(const struct git_delta_index *index,
- const void *buf, unsigned long bufsize,
- unsigned long *delta_size,
- unsigned long max_delta_size);
+extern void *git_delta_create(
+ const struct git_delta_index *index,
+ const void *buf,
+ unsigned long bufsize,
+ unsigned long *delta_size,
+ unsigned long max_delta_size);
/*
* diff_delta: create a delta from source buffer to target buffer
@@ -60,15 +61,16 @@ git_delta_create(const struct git_delta_index *index,
* pointer to the buffer with the delta data is returned and *delta_size is
* updated with its size. The returned buffer must be freed by the caller.
*/
-GIT_INLINE(void *)
-git_delta(const void *src_buf, unsigned long src_bufsize,
- const void *trg_buf, unsigned long trg_bufsize,
- unsigned long *delta_size, unsigned long max_delta_size)
+GIT_INLINE(void *) git_delta(
+ const void *src_buf, unsigned long src_bufsize,
+ const void *trg_buf, unsigned long trg_bufsize,
+ unsigned long *delta_size,
+ unsigned long max_delta_size)
{
struct git_delta_index *index = git_delta_create_index(src_buf, src_bufsize);
if (index) {
- void *delta = git_delta_create(index, trg_buf, trg_bufsize,
- delta_size, max_delta_size);
+ void *delta = git_delta_create(
+ index, trg_buf, trg_bufsize, delta_size, max_delta_size);
git_delta_free_index(index);
return delta;
}
@@ -82,9 +84,10 @@ git_delta(const void *src_buf, unsigned long src_bufsize,
* *trg_bufsize is updated with its size. On failure a NULL pointer is
* returned. The returned buffer must be freed by the caller.
*/
-extern void *git_delta_patch(const void *src_buf, unsigned long src_size,
- const void *delta_buf, unsigned long delta_size,
- unsigned long *dst_size);
+extern void *git_delta_patch(
+ const void *src_buf, unsigned long src_size,
+ const void *delta_buf, unsigned long delta_size,
+ unsigned long *dst_size);
/* the smallest possible delta size is 4 bytes */
#define GIT_DELTA_SIZE_MIN 4
@@ -93,9 +96,8 @@ extern void *git_delta_patch(const void *src_buf, unsigned long src_size,
* This must be called twice on the delta data buffer, first to get the
* expected source buffer size, and again to get the target buffer size.
*/
-GIT_INLINE(unsigned long)
-git_delta_get_hdr_size(const unsigned char **datap,
- const unsigned char *top)
+GIT_INLINE(unsigned long) git_delta_get_hdr_size(
+ const unsigned char **datap, const unsigned char *top)
{
const unsigned char *data = *datap;
unsigned long cmd, size = 0;
diff --git a/src/diff.c b/src/diff.c
index d6f5bd454..86f76f9c0 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -363,7 +363,7 @@ int git_diff__oid_for_file(
const git_oid *sm_oid;
if (!git_submodule_lookup(&sm, repo, path) &&
- (sm_oid = git_submodule_wd_oid(sm)) != NULL)
+ (sm_oid = git_submodule_wd_id(sm)) != NULL)
git_oid_cpy(oid, sm_oid);
else {
/* if submodule lookup failed probably just in an intermediate
@@ -496,7 +496,7 @@ static int maybe_modified(
/* grab OID while we are here */
if (git_oid_iszero(&nitem->oid)) {
- const git_oid *sm_oid = git_submodule_wd_oid(sub);
+ const git_oid *sm_oid = git_submodule_wd_id(sub);
if (sm_oid != NULL) {
git_oid_cpy(&noid, sm_oid);
use_noid = &noid;
diff --git a/src/diff_output.c b/src/diff_output.c
index 46a9e02bf..3d5e03a29 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -262,7 +262,7 @@ static int get_blob_content(
return error;
map->data = (void *)git_blob_rawcontent(*blob);
- map->len = git_blob_rawsize(*blob);
+ map->len = (size_t)git_blob_rawsize(*blob);
return diff_delta_is_binary_by_content(ctxt, delta, file, map);
}
@@ -287,8 +287,8 @@ static int get_workdir_sm_content(
if ((file->flags & GIT_DIFF_FILE_VALID_OID) == 0) {
const git_oid* sm_head;
- if ((sm_head = git_submodule_wd_oid(sm)) != NULL ||
- (sm_head = git_submodule_head_oid(sm)) != NULL)
+ if ((sm_head = git_submodule_wd_id(sm)) != NULL ||
+ (sm_head = git_submodule_head_id(sm)) != NULL)
{
git_oid_cpy(&file->oid, sm_head);
file->flags |= GIT_DIFF_FILE_VALID_OID;
@@ -440,10 +440,10 @@ static void diff_context_init(
git_diff_list *diff,
git_repository *repo,
const git_diff_options *opts,
- void *data,
- git_diff_file_fn file_cb,
- git_diff_hunk_fn hunk_cb,
- git_diff_data_fn data_cb)
+ git_diff_file_cb file_cb,
+ git_diff_hunk_cb hunk_cb,
+ git_diff_data_cb data_cb,
+ void *payload)
{
memset(ctxt, 0, sizeof(diff_context));
@@ -453,8 +453,8 @@ static void diff_context_init(
ctxt->file_cb = file_cb;
ctxt->hunk_cb = hunk_cb;
ctxt->data_cb = data_cb;
- ctxt->cb_data = data;
- ctxt->cb_error = 0;
+ ctxt->payload = payload;
+ ctxt->error = 0;
setup_xdiff_options(ctxt->opts, &ctxt->xdiff_config, &ctxt->xdiff_params);
}
@@ -469,10 +469,10 @@ static int diff_delta_file_callback(
progress = ctxt->diff ? ((float)idx / ctxt->diff->deltas.length) : 1.0f;
- if (ctxt->file_cb(ctxt->cb_data, delta, progress) != 0)
- ctxt->cb_error = GIT_EUSER;
+ if (ctxt->file_cb(delta, progress, ctxt->payload) != 0)
+ ctxt->error = GIT_EUSER;
- return ctxt->cb_error;
+ return ctxt->error;
}
static void diff_patch_init(
@@ -643,14 +643,14 @@ static int diff_patch_cb(void *priv, mmbuffer_t *bufs, int len)
diff_context *ctxt = patch->ctxt;
if (len == 1) {
- ctxt->cb_error = parse_hunk_header(&ctxt->cb_range, bufs[0].ptr);
- if (ctxt->cb_error < 0)
- return ctxt->cb_error;
+ ctxt->error = parse_hunk_header(&ctxt->range, bufs[0].ptr);
+ if (ctxt->error < 0)
+ return ctxt->error;
if (ctxt->hunk_cb != NULL &&
- ctxt->hunk_cb(ctxt->cb_data, patch->delta, &ctxt->cb_range,
- bufs[0].ptr, bufs[0].size))
- ctxt->cb_error = GIT_EUSER;
+ ctxt->hunk_cb(patch->delta, &ctxt->range,
+ bufs[0].ptr, bufs[0].size, ctxt->payload))
+ ctxt->error = GIT_EUSER;
}
if (len == 2 || len == 3) {
@@ -661,12 +661,12 @@ static int diff_patch_cb(void *priv, mmbuffer_t *bufs, int len)
GIT_DIFF_LINE_CONTEXT;
if (ctxt->data_cb != NULL &&
- ctxt->data_cb(ctxt->cb_data, patch->delta, &ctxt->cb_range,
- origin, bufs[1].ptr, bufs[1].size))
- ctxt->cb_error = GIT_EUSER;
+ ctxt->data_cb(patch->delta, &ctxt->range,
+ origin, bufs[1].ptr, bufs[1].size, ctxt->payload))
+ ctxt->error = GIT_EUSER;
}
- if (len == 3 && !ctxt->cb_error) {
+ if (len == 3 && !ctxt->error) {
/* If we have a '+' and a third buf, then we have added a line
* without a newline and the old code had one, so DEL_EOFNL.
* If we have a '-' and a third buf, then we have removed a line
@@ -678,12 +678,12 @@ static int diff_patch_cb(void *priv, mmbuffer_t *bufs, int len)
GIT_DIFF_LINE_CONTEXT;
if (ctxt->data_cb != NULL &&
- ctxt->data_cb(ctxt->cb_data, patch->delta, &ctxt->cb_range,
- origin, bufs[2].ptr, bufs[2].size))
- ctxt->cb_error = GIT_EUSER;
+ ctxt->data_cb(patch->delta, &ctxt->range,
+ origin, bufs[2].ptr, bufs[2].size, ctxt->payload))
+ ctxt->error = GIT_EUSER;
}
- return ctxt->cb_error;
+ return ctxt->error;
}
static int diff_patch_generate(
@@ -720,7 +720,7 @@ static int diff_patch_generate(
xdl_diff(&old_xdiff_data, &new_xdiff_data,
&ctxt->xdiff_params, &ctxt->xdiff_config, &xdiff_callback);
- error = ctxt->cb_error;
+ error = ctxt->error;
if (!error)
patch->flags |= GIT_DIFF_PATCH_DIFFED;
@@ -775,13 +775,13 @@ static void diff_patch_free(git_diff_patch *patch)
#define MIN_LINE_STEP 8
static int diff_patch_hunk_cb(
- void *cb_data,
const git_diff_delta *delta,
const git_diff_range *range,
const char *header,
- size_t header_len)
+ size_t header_len,
+ void *payload)
{
- git_diff_patch *patch = cb_data;
+ git_diff_patch *patch = payload;
diff_patch_hunk *hunk;
GIT_UNUSED(delta);
@@ -822,14 +822,14 @@ static int diff_patch_hunk_cb(
}
static int diff_patch_line_cb(
- void *cb_data,
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
- size_t content_len)
+ size_t content_len,
+ void *payload)
{
- git_diff_patch *patch = cb_data;
+ git_diff_patch *patch = payload;
diff_patch_hunk *hunk;
diff_patch_line *last, *line;
@@ -904,10 +904,10 @@ static int diff_patch_line_cb(
int git_diff_foreach(
git_diff_list *diff,
- void *cb_data,
- git_diff_file_fn file_cb,
- git_diff_hunk_fn hunk_cb,
- git_diff_data_fn data_cb)
+ git_diff_file_cb file_cb,
+ git_diff_hunk_cb hunk_cb,
+ git_diff_data_cb data_cb,
+ void *payload)
{
int error = 0;
diff_context ctxt;
@@ -916,7 +916,7 @@ int git_diff_foreach(
diff_context_init(
&ctxt, diff, diff->repo, &diff->opts,
- cb_data, file_cb, hunk_cb, data_cb);
+ file_cb, hunk_cb, data_cb, payload);
diff_patch_init(&ctxt, &patch);
@@ -951,8 +951,8 @@ int git_diff_foreach(
typedef struct {
git_diff_list *diff;
- git_diff_data_fn print_cb;
- void *cb_data;
+ git_diff_data_cb print_cb;
+ void *payload;
git_buf *buf;
} diff_print_info;
@@ -986,7 +986,7 @@ char git_diff_status_char(git_delta_t status)
}
static int print_compact(
- void *data, const git_diff_delta *delta, float progress)
+ const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
@@ -1017,8 +1017,8 @@ static int print_compact(
if (git_buf_oom(pi->buf))
return -1;
- if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR,
- git_buf_cstr(pi->buf), git_buf_len(pi->buf)))
+ if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
+ git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
{
giterr_clear();
return GIT_EUSER;
@@ -1029,8 +1029,8 @@ static int print_compact(
int git_diff_print_compact(
git_diff_list *diff,
- void *cb_data,
- git_diff_data_fn print_cb)
+ git_diff_data_cb print_cb,
+ void *payload)
{
int error;
git_buf buf = GIT_BUF_INIT;
@@ -1038,10 +1038,10 @@ int git_diff_print_compact(
pi.diff = diff;
pi.print_cb = print_cb;
- pi.cb_data = cb_data;
+ pi.payload = payload;
pi.buf = &buf;
- error = git_diff_foreach(diff, &pi, print_compact, NULL, NULL);
+ error = git_diff_foreach(diff, print_compact, NULL, NULL, &pi);
git_buf_free(&buf);
@@ -1079,7 +1079,7 @@ static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
}
static int print_patch_file(
- void *data, const git_diff_delta *delta, float progress)
+ const git_diff_delta *delta, float progress, void *data)
{
diff_print_info *pi = data;
const char *oldpfx = pi->diff->opts.old_prefix;
@@ -1121,7 +1121,8 @@ static int print_patch_file(
if (git_buf_oom(pi->buf))
return -1;
- if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf)))
+ if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
+ git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
{
giterr_clear();
return GIT_EUSER;
@@ -1137,8 +1138,8 @@ static int print_patch_file(
if (git_buf_oom(pi->buf))
return -1;
- if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_BINARY,
- git_buf_cstr(pi->buf), git_buf_len(pi->buf)))
+ if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_BINARY,
+ git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
{
giterr_clear();
return GIT_EUSER;
@@ -1148,11 +1149,11 @@ static int print_patch_file(
}
static int print_patch_hunk(
- void *data,
const git_diff_delta *d,
const git_diff_range *r,
const char *header,
- size_t header_len)
+ size_t header_len,
+ void *data)
{
diff_print_info *pi = data;
@@ -1163,8 +1164,8 @@ static int print_patch_hunk(
if (git_buf_printf(pi->buf, "%.*s", (int)header_len, header) < 0)
return -1;
- if (pi->print_cb(pi->cb_data, d, r, GIT_DIFF_LINE_HUNK_HDR,
- git_buf_cstr(pi->buf), git_buf_len(pi->buf)))
+ if (pi->print_cb(d, r, GIT_DIFF_LINE_HUNK_HDR,
+ git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
{
giterr_clear();
return GIT_EUSER;
@@ -1174,12 +1175,12 @@ static int print_patch_hunk(
}
static int print_patch_line(
- void *data,
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin, /* GIT_DIFF_LINE value from above */
const char *content,
- size_t content_len)
+ size_t content_len,
+ void *data)
{
diff_print_info *pi = data;
@@ -1198,8 +1199,8 @@ static int print_patch_line(
if (git_buf_oom(pi->buf))
return -1;
- if (pi->print_cb(pi->cb_data, delta, range, line_origin,
- git_buf_cstr(pi->buf), git_buf_len(pi->buf)))
+ if (pi->print_cb(delta, range, line_origin,
+ git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload))
{
giterr_clear();
return GIT_EUSER;
@@ -1210,8 +1211,8 @@ static int print_patch_line(
int git_diff_print_patch(
git_diff_list *diff,
- void *cb_data,
- git_diff_data_fn print_cb)
+ git_diff_data_cb print_cb,
+ void *payload)
{
int error;
git_buf buf = GIT_BUF_INIT;
@@ -1219,11 +1220,11 @@ int git_diff_print_patch(
pi.diff = diff;
pi.print_cb = print_cb;
- pi.cb_data = cb_data;
+ pi.payload = payload;
pi.buf = &buf;
error = git_diff_foreach(
- diff, &pi, print_patch_file, print_patch_hunk, print_patch_line);
+ diff, print_patch_file, print_patch_hunk, print_patch_line, &pi);
git_buf_free(&buf);
@@ -1235,14 +1236,18 @@ static void set_data_from_blob(
git_blob *blob, git_map *map, git_diff_file *file)
{
if (blob) {
- map->data = (char *)git_blob_rawcontent(blob);
- file->size = map->len = git_blob_rawsize(blob);
+ file->size = git_blob_rawsize(blob);
git_oid_cpy(&file->oid, git_object_id((const git_object *)blob));
file->mode = 0644;
+
+ map->len = (size_t)file->size;
+ map->data = (char *)git_blob_rawcontent(blob);
} else {
- map->data = "";
- file->size = map->len = 0;
+ file->size = 0;
file->flags |= GIT_DIFF_FILE_NO_DATA;
+
+ map->len = 0;
+ map->data = "";
}
}
@@ -1250,10 +1255,10 @@ int git_diff_blobs(
git_blob *old_blob,
git_blob *new_blob,
const git_diff_options *options,
- void *cb_data,
- git_diff_file_fn file_cb,
- git_diff_hunk_fn hunk_cb,
- git_diff_data_fn data_cb)
+ git_diff_file_cb file_cb,
+ git_diff_hunk_cb hunk_cb,
+ git_diff_data_cb data_cb,
+ void *payload)
{
int error;
git_repository *repo;
@@ -1276,7 +1281,7 @@ int git_diff_blobs(
diff_context_init(
&ctxt, NULL, repo, options,
- cb_data, file_cb, hunk_cb, data_cb);
+ file_cb, hunk_cb, data_cb, payload);
diff_patch_init(&ctxt, &patch);
@@ -1374,7 +1379,7 @@ int git_diff_get_patch(
diff_context_init(
&ctxt, diff, diff->repo, &diff->opts,
- NULL, NULL, diff_patch_hunk_cb, diff_patch_line_cb);
+ NULL, diff_patch_hunk_cb, diff_patch_line_cb, NULL);
if (git_diff_delta__should_skip(ctxt.opts, delta))
return 0;
@@ -1384,12 +1389,12 @@ int git_diff_get_patch(
return -1;
if (!(error = diff_patch_load(&ctxt, patch))) {
- ctxt.cb_data = patch;
+ ctxt.payload = patch;
error = diff_patch_generate(&ctxt, patch);
if (error == GIT_EUSER)
- error = ctxt.cb_error;
+ error = ctxt.error;
}
if (error)
@@ -1503,22 +1508,22 @@ notfound:
}
static int print_to_buffer_cb(
- void *cb_data,
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
- size_t content_len)
+ size_t content_len,
+ void *payload)
{
- git_buf *output = cb_data;
+ git_buf *output = payload;
GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
return git_buf_put(output, content, content_len);
}
int git_diff_patch_print(
git_diff_patch *patch,
- void *cb_data,
- git_diff_data_fn print_cb)
+ git_diff_data_cb print_cb,
+ void *payload)
{
int error;
git_buf temp = GIT_BUF_INIT;
@@ -1529,23 +1534,23 @@ int git_diff_patch_print(
pi.diff = patch->diff;
pi.print_cb = print_cb;
- pi.cb_data = cb_data;
+ pi.payload = payload;
pi.buf = &temp;
- error = print_patch_file(&pi, patch->delta, 0);
+ error = print_patch_file(patch->delta, 0, &pi);
for (h = 0; h < patch->hunks_size && !error; ++h) {
diff_patch_hunk *hunk = &patch->hunks[h];
- error = print_patch_hunk(&pi, patch->delta,
- &hunk->range, hunk->header, hunk->header_len);
+ error = print_patch_hunk(
+ patch->delta, &hunk->range, hunk->header, hunk->header_len, &pi);
for (l = 0; l < hunk->line_count && !error; ++l) {
diff_patch_line *line = &patch->lines[hunk->line_start + l];
error = print_patch_line(
- &pi, patch->delta, &hunk->range,
- line->origin, line->ptr, line->len);
+ patch->delta, &hunk->range,
+ line->origin, line->ptr, line->len, &pi);
}
}
@@ -1561,7 +1566,7 @@ int git_diff_patch_to_str(
int error;
git_buf output = GIT_BUF_INIT;
- error = git_diff_patch_print(patch, &output, print_to_buffer_cb);
+ error = git_diff_patch_print(patch, print_to_buffer_cb, &output);
/* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
* meaning a memory allocation failure, so just map to -1...
@@ -1577,8 +1582,8 @@ int git_diff_patch_to_str(
int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
- int (*cb)(void *cbref, git_diff_delta *i2h, git_diff_delta *w2i),
- void *cbref)
+ int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
+ void *payload)
{
int cmp;
git_diff_delta *i2h, *w2i;
@@ -1611,15 +1616,15 @@ int git_diff__paired_foreach(
STRCMP_CASESELECT(icase, i2h->old_file.path, w2i->old_file.path);
if (cmp < 0) {
- if (cb(cbref, i2h, NULL))
+ if (cb(i2h, NULL, payload))
return GIT_EUSER;
i++;
} else if (cmp > 0) {
- if (cb(cbref, NULL, w2i))
+ if (cb(NULL, w2i, payload))
return GIT_EUSER;
j++;
} else {
- if (cb(cbref, i2h, w2i))
+ if (cb(i2h, w2i, payload))
return GIT_EUSER;
i++; j++;
}
diff --git a/src/diff_output.h b/src/diff_output.h
index f74dd3a71..13f2a120d 100644
--- a/src/diff_output.h
+++ b/src/diff_output.h
@@ -27,12 +27,12 @@ typedef struct {
git_repository *repo;
git_diff_list *diff;
const git_diff_options *opts;
- git_diff_file_fn file_cb;
- git_diff_hunk_fn hunk_cb;
- git_diff_data_fn data_cb;
- void *cb_data;
- int cb_error;
- git_diff_range cb_range;
+ git_diff_file_cb file_cb;
+ git_diff_hunk_cb hunk_cb;
+ git_diff_data_cb data_cb;
+ void *payload;
+ int error;
+ git_diff_range range;
xdemitconf_t xdiff_config;
xpparam_t xdiff_params;
} diff_context;
@@ -86,7 +86,7 @@ typedef struct {
extern int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
- int (*cb)(void *cbref, git_diff_delta *i2h, git_diff_delta *w2i),
- void *cbref);
+ int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
+ void *payload);
#endif
diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c
index a89dffa7c..469ce7807 100644
--- a/src/hash/hash_win32.c
+++ b/src/hash/hash_win32.c
@@ -155,7 +155,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *data, size_
{
assert(ctx->ctx.cryptoapi.valid);
- if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, (const BYTE *)data, len, 0))
+ if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, (const BYTE *)data, (DWORD)len, 0))
return -1;
return 0;
@@ -219,7 +219,7 @@ GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *data, size_t len)
{
- if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, (PBYTE)data, len, 0) < 0)
+ if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, (PBYTE)data, (ULONG)len, 0) < 0)
return -1;
return 0;
diff --git a/src/index.c b/src/index.c
index 128dd18cf..f3ced9e39 100644
--- a/src/index.c
+++ b/src/index.c
@@ -94,7 +94,7 @@ static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffe
static int read_header(struct index_header *dest, const void *buffer);
static int parse_index(git_index *index, const char *buffer, size_t buffer_size);
-static int is_index_extended(git_index *index);
+static bool is_index_extended(git_index *index);
static int write_index(git_index *index, git_filebuf *file);
static int index_find(git_index *index, const char *path, int stage);
@@ -298,7 +298,7 @@ static void index_free(git_index *index)
{
git_index_entry *e;
git_index_reuc_entry *reuc;
- unsigned int i;
+ size_t i;
git_index_clear(index);
git_vector_foreach(&index->entries, i, e) {
@@ -488,20 +488,22 @@ int git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo
return git_tree__write_index(oid, index, repo);
}
-unsigned int git_index_entrycount(git_index *index)
+size_t git_index_entrycount(const git_index *index)
{
assert(index);
- return (unsigned int)index->entries.length;
+ return index->entries.length;
}
-git_index_entry *git_index_get_byindex(git_index *index, size_t n)
+const git_index_entry *git_index_get_byindex(
+ git_index *index, size_t n)
{
assert(index);
git_vector_sort(&index->entries);
return git_vector_get(&index->entries, n);
}
-git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage)
+const git_index_entry *git_index_get_bypath(
+ git_index *index, const char *path, int stage)
{
int pos;
@@ -580,7 +582,7 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
*/
/* write the blob to disk and get the oid */
- if ((error = git_blob_create_fromfile(&oid, INDEX_OWNER(index), rel_path)) < 0)
+ if ((error = git_blob_create_fromworkdir(&oid, INDEX_OWNER(index), rel_path)) < 0)
return error;
entry = git__calloc(1, sizeof(git_index_entry));
@@ -810,13 +812,15 @@ int git_index_find(git_index *index, const char *path)
assert(index && path);
- if ((pos = git_vector_bsearch2(&index->entries, index->entries_search_path, path)) < 0)
+ if ((pos = git_vector_bsearch2(
+ &index->entries, index->entries_search_path, path)) < 0)
return pos;
/* Since our binary search only looked at path, we may be in the
- * middle of a list of stages. */
+ * middle of a list of stages.
+ */
while (pos > 0) {
- git_index_entry *prev = git_vector_get(&index->entries, pos-1);
+ const git_index_entry *prev = git_vector_get(&index->entries, pos-1);
if (index->entries_cmp_path(prev->path, path) != 0)
break;
@@ -827,10 +831,10 @@ int git_index_find(git_index *index, const char *path)
return pos;
}
-unsigned int git_index__prefix_position(git_index *index, const char *path)
+size_t git_index__prefix_position(git_index *index, const char *path)
{
struct entry_srch_key srch_key;
- unsigned int pos;
+ size_t pos;
srch_key.path = path;
srch_key.stage = 0;
@@ -848,7 +852,7 @@ int git_index_conflict_add(git_index *index,
const git_index_entry *their_entry)
{
git_index_entry *entries[3] = { 0 };
- size_t i;
+ unsigned short i;
int ret = 0;
assert (index);
@@ -886,7 +890,7 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
git_index_entry **their_out,
git_index *index, const char *path)
{
- int pos, stage;
+ int pos, posmax, stage;
git_index_entry *conflict_entry;
int error = GIT_ENOTFOUND;
@@ -899,7 +903,8 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
if ((pos = git_index_find(index, path)) < 0)
return pos;
- while ((unsigned int)pos < git_index_entrycount(index)) {
+ for (posmax = (int)git_index_entrycount(index); pos < posmax; ++pos) {
+
conflict_entry = git_vector_get(&index->entries, pos);
if (index->entries_cmp_path(conflict_entry->path, path) != 0)
@@ -923,8 +928,6 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
default:
break;
};
-
- ++pos;
}
return error;
@@ -932,7 +935,7 @@ int git_index_conflict_get(git_index_entry **ancestor_out,
int git_index_conflict_remove(git_index *index, const char *path)
{
- int pos;
+ int pos, posmax;
git_index_entry *conflict_entry;
int error = 0;
@@ -941,7 +944,9 @@ int git_index_conflict_remove(git_index *index, const char *path)
if ((pos = git_index_find(index, path)) < 0)
return pos;
- while ((unsigned int)pos < git_index_entrycount(index)) {
+ posmax = (int)git_index_entrycount(index);
+
+ while (pos < posmax) {
conflict_entry = git_vector_get(&index->entries, pos);
if (index->entries_cmp_path(conflict_entry->path, path) != 0)
@@ -961,7 +966,7 @@ int git_index_conflict_remove(git_index *index, const char *path)
return error;
}
-static int index_conflicts_match(git_vector *v, size_t idx)
+static int index_conflicts_match(const git_vector *v, size_t idx)
{
git_index_entry *entry = git_vector_get(v, idx);
@@ -979,9 +984,9 @@ void git_index_conflict_cleanup(git_index *index)
git_vector_remove_matching(&index->entries, index_conflicts_match);
}
-int git_index_has_conflicts(git_index *index)
+int git_index_has_conflicts(const git_index *index)
{
- unsigned int i;
+ size_t i;
git_index_entry *entry;
assert(index);
@@ -1072,7 +1077,7 @@ const git_index_reuc_entry *git_index_reuc_get_byindex(
return git_vector_get(&index->reuc, n);
}
-int git_index_reuc_remove(git_index *index, int position)
+int git_index_reuc_remove(git_index *index, size_t position)
{
int error;
git_index_reuc_entry *reuc;
@@ -1359,9 +1364,9 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
return 0;
}
-static int is_index_extended(git_index *index)
+static bool is_index_extended(git_index *index)
{
- unsigned int i, extended;
+ size_t i, extended;
git_index_entry *entry;
extended = 0;
@@ -1374,7 +1379,7 @@ static int is_index_extended(git_index *index)
}
}
- return extended;
+ return (extended > 0);
}
static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
@@ -1440,7 +1445,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
static int write_entries(git_index *index, git_filebuf *file)
{
int error = 0;
- unsigned int i;
+ size_t i;
git_vector case_sorted;
git_index_entry *entry;
git_vector *out = &index->entries;
@@ -1506,7 +1511,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
git_vector *out = &index->reuc;
git_index_reuc_entry *reuc;
struct index_extension extension;
- unsigned int i;
+ size_t i;
int error = 0;
git_vector_foreach(out, i, reuc) {
@@ -1516,7 +1521,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
memset(&extension, 0x0, sizeof(struct index_extension));
memcpy(&extension.signature, INDEX_EXT_UNMERGED_SIG, 4);
- extension.extension_size = reuc_buf.size;
+ extension.extension_size = (uint32_t)reuc_buf.size;
error = write_extension(file, &extension, &reuc_buf);
@@ -1529,10 +1534,8 @@ done:
static int write_index(git_index *index, git_filebuf *file)
{
git_oid hash_final;
-
struct index_header header;
-
- int is_extended;
+ bool is_extended;
assert(index && file);
@@ -1599,11 +1602,11 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da
return 0;
}
-int git_index_read_tree(git_index *index, git_tree *tree)
+int git_index_read_tree(git_index *index, const git_tree *tree)
{
git_index_clear(index);
- return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index);
+ return git_tree_walk(tree, GIT_TREEWALK_POST, read_tree_cb, index);
}
git_repository *git_index_owner(const git_index *index)
diff --git a/src/index.h b/src/index.h
index f0dcd64d5..05123b580 100644
--- a/src/index.h
+++ b/src/index.h
@@ -43,7 +43,7 @@ struct git_index {
extern void git_index_entry__init_from_stat(git_index_entry *entry, struct stat *st);
-extern unsigned int git_index__prefix_position(git_index *index, const char *path);
+extern size_t git_index__prefix_position(git_index *index, const char *path);
extern int git_index_entry__cmp(const void *a, const void *b);
extern int git_index_entry__cmp_icase(const void *a, const void *b);
diff --git a/src/indexer.c b/src/indexer.c
index d8939f03d..a51d903ed 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -56,12 +56,12 @@ struct delta_info {
git_off_t delta_off;
};
-const git_oid *git_indexer_hash(git_indexer *idx)
+const git_oid *git_indexer_hash(const git_indexer *idx)
{
return &idx->hash;
}
-const git_oid *git_indexer_stream_hash(git_indexer_stream *idx)
+const git_oid *git_indexer_stream_hash(const git_indexer_stream *idx)
{
return &idx->hash;
}
diff --git a/src/iterator.c b/src/iterator.c
index ee83a4fda..6be45a4bb 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -85,7 +85,7 @@ struct tree_iterator_frame {
tree_iterator_frame *next, *prev;
git_tree *tree;
char *start;
- unsigned int index;
+ size_t index;
};
typedef struct {
@@ -329,7 +329,7 @@ int git_iterator_for_tree_range(
typedef struct {
git_iterator base;
git_index *index;
- unsigned int current;
+ size_t current;
bool free_index;
} index_iterator;
@@ -337,7 +337,7 @@ static int index_iterator__current(
git_iterator *self, const git_index_entry **entry)
{
index_iterator *ii = (index_iterator *)self;
- git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
+ const git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
if (ie != NULL &&
ii->base.end != NULL &&
@@ -434,7 +434,7 @@ typedef struct workdir_iterator_frame workdir_iterator_frame;
struct workdir_iterator_frame {
workdir_iterator_frame *next;
git_vector entries;
- unsigned int index;
+ size_t index;
char *start;
};
@@ -761,7 +761,8 @@ static int spoolandsort_iterator__current(
spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length)
- *entry = (const git_index_entry *)git_vector_get_const(&si->entries, si->position);
+ *entry = (const git_index_entry *)git_vector_get(
+ &si->entries, si->position);
else
*entry = NULL;
@@ -781,7 +782,8 @@ static int spoolandsort_iterator__advance(
spoolandsort_iterator *si = (spoolandsort_iterator *)self;
if (si->position < si->entries.length)
- *entry = (const git_index_entry *)git_vector_get_const(&si->entries, ++si->position);
+ *entry = (const git_index_entry *)git_vector_get(
+ &si->entries, ++si->position);
else
*entry = NULL;
diff --git a/src/merge.c b/src/merge.c
index 135af6a8c..c795b808b 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -6,12 +6,14 @@
*/
#include "repository.h"
+#include "revwalk.h"
#include "buffer.h"
#include "merge.h"
#include "refs.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "git2/reset.h"
+#include "commit_list.h"
int git_merge__cleanup(git_repository *repo)
{
@@ -46,3 +48,197 @@ cleanup:
return error;
}
+int git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_array[], size_t length)
+{
+ git_revwalk *walk;
+ git_vector list;
+ git_commit_list *result = NULL;
+ int error = -1;
+ unsigned int i;
+ git_commit_list_node *commit;
+
+ assert(out && repo && input_array);
+
+ if (length < 2) {
+ giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %u.", length);
+ return -1;
+ }
+
+ if (git_vector_init(&list, length - 1, NULL) < 0)
+ return -1;
+
+ if (git_revwalk_new(&walk, repo) < 0)
+ goto cleanup;
+
+ for (i = 1; i < length; i++) {
+ commit = commit_lookup(walk, &input_array[i]);
+ if (commit == NULL)
+ goto cleanup;
+
+ git_vector_insert(&list, commit);
+ }
+
+ commit = commit_lookup(walk, &input_array[0]);
+ if (commit == NULL)
+ goto cleanup;
+
+ if (git_merge__bases_many(&result, walk, commit, &list) < 0)
+ goto cleanup;
+
+ if (!result) {
+ error = GIT_ENOTFOUND;
+ goto cleanup;
+ }
+
+ git_oid_cpy(out, &result->item->oid);
+
+ error = 0;
+
+cleanup:
+ git_commit_list_free(&result);
+ git_revwalk_free(walk);
+ git_vector_free(&list);
+ return error;
+}
+
+int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two)
+{
+ git_revwalk *walk;
+ git_vector list;
+ git_commit_list *result = NULL;
+ git_commit_list_node *commit;
+ void *contents[1];
+
+ if (git_revwalk_new(&walk, repo) < 0)
+ return -1;
+
+ commit = commit_lookup(walk, two);
+ if (commit == NULL)
+ goto on_error;
+
+ /* This is just one value, so we can do it on the stack */
+ memset(&list, 0x0, sizeof(git_vector));
+ contents[0] = commit;
+ list.length = 1;
+ list.contents = contents;
+
+ commit = commit_lookup(walk, one);
+ if (commit == NULL)
+ goto on_error;
+
+ if (git_merge__bases_many(&result, walk, commit, &list) < 0)
+ goto on_error;
+
+ if (!result) {
+ git_revwalk_free(walk);
+ giterr_clear();
+ return GIT_ENOTFOUND;
+ }
+
+ git_oid_cpy(out, &result->item->oid);
+ git_commit_list_free(&result);
+ git_revwalk_free(walk);
+
+ return 0;
+
+on_error:
+ git_revwalk_free(walk);
+ return -1;
+}
+
+static int interesting(git_pqueue *list)
+{
+ unsigned int i;
+ /* element 0 isn't used - we need to start at 1 */
+ for (i = 1; i < list->size; i++) {
+ git_commit_list_node *commit = list->d[i];
+ if ((commit->flags & STALE) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
+int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_list_node *one, git_vector *twos)
+{
+ int error;
+ unsigned int i;
+ git_commit_list_node *two;
+ git_commit_list *result = NULL, *tmp = NULL;
+ git_pqueue list;
+
+ /* if the commit is repeated, we have a our merge base already */
+ git_vector_foreach(twos, i, two) {
+ if (one == two)
+ return git_commit_list_insert(one, out) ? 0 : -1;
+ }
+
+ if (git_pqueue_init(&list, twos->length * 2, git_commit_list_time_cmp) < 0)
+ return -1;
+
+ if (git_commit_list_parse(walk, one) < 0)
+ return -1;
+
+ one->flags |= PARENT1;
+ if (git_pqueue_insert(&list, one) < 0)
+ return -1;
+
+ git_vector_foreach(twos, i, two) {
+ git_commit_list_parse(walk, two);
+ two->flags |= PARENT2;
+ if (git_pqueue_insert(&list, two) < 0)
+ return -1;
+ }
+
+ /* as long as there are non-STALE commits */
+ while (interesting(&list)) {
+ git_commit_list_node *commit;
+ int flags;
+
+ commit = git_pqueue_pop(&list);
+
+ flags = commit->flags & (PARENT1 | PARENT2 | STALE);
+ if (flags == (PARENT1 | PARENT2)) {
+ if (!(commit->flags & RESULT)) {
+ commit->flags |= RESULT;
+ if (git_commit_list_insert(commit, &result) == NULL)
+ return -1;
+ }
+ /* we mark the parents of a merge stale */
+ flags |= STALE;
+ }
+
+ for (i = 0; i < commit->out_degree; i++) {
+ git_commit_list_node *p = commit->parents[i];
+ if ((p->flags & flags) == flags)
+ continue;
+
+ if ((error = git_commit_list_parse(walk, p)) < 0)
+ return error;
+
+ p->flags |= flags;
+ if (git_pqueue_insert(&list, p) < 0)
+ return -1;
+ }
+ }
+
+ git_pqueue_free(&list);
+
+ /* filter out any stale commits in the results */
+ tmp = result;
+ result = NULL;
+
+ while (tmp) {
+ struct git_commit_list *next = tmp->next;
+ if (!(tmp->item->flags & STALE))
+ if (git_commit_list_insert_by_date(tmp->item, &result) == NULL)
+ return -1;
+
+ git__free(tmp);
+ tmp = next;
+ }
+
+ *out = result;
+ return 0;
+}
+
diff --git a/src/merge.h b/src/merge.h
index 2117d9214..3681e24b7 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -8,6 +8,8 @@
#define INCLUDE_merge_h__
#include "git2/types.h"
+#include "git2/merge.h"
+#include "commit_list.h"
#define GIT_MERGE_MSG_FILE "MERGE_MSG"
#define GIT_MERGE_MODE_FILE "MERGE_MODE"
@@ -15,5 +17,6 @@
#define MERGE_CONFIG_FILE_MODE 0666
int git_merge__cleanup(git_repository *repo);
+int git_merge__bases_many(git_commit_list **out, git_revwalk *walk, git_commit_list_node *one, git_vector *twos);
#endif
diff --git a/src/notes.c b/src/notes.c
index 81e4e5073..dd36cc2fe 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -19,11 +19,11 @@ static int find_subtree_in_current_level(
const char *annotated_object_sha,
int fanout)
{
- unsigned int i;
+ size_t i;
const git_tree_entry *entry;
*out = NULL;
-
+
if (parent == NULL)
return GIT_ENOTFOUND;
@@ -34,12 +34,12 @@ static int find_subtree_in_current_level(
continue;
if (S_ISDIR(git_tree_entry_filemode(entry))
- && strlen(git_tree_entry_name(entry)) == 2
+ && strlen(git_tree_entry_name(entry)) == 2
&& !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2))
return git_tree_lookup(out, repo, git_tree_entry_id(entry));
/* Not a DIR, so do we have an already existing blob? */
- if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
+ if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout))
return GIT_EEXISTS;
}
@@ -71,7 +71,7 @@ static int find_subtree_r(git_tree **out, git_tree *root,
static int find_blob(git_oid *blob, git_tree *tree, const char *target)
{
- unsigned int i;
+ size_t i;
const git_tree_entry *entry;
for (i=0; i<git_tree_entrycount(tree); i++) {
@@ -263,8 +263,8 @@ static int insert_note_in_tree_enotfound_cb(git_tree **out,
static int note_write(git_oid *out,
git_repository *repo,
- git_signature *author,
- git_signature *committer,
+ const git_signature *author,
+ const git_signature *committer,
const char *notes_ref,
const char *note,
git_tree *commit_tree,
@@ -343,9 +343,9 @@ cleanup:
}
static int note_remove(git_repository *repo,
- git_signature *author, git_signature *committer,
- const char *notes_ref, git_tree *tree,
- const char *target, git_commit **parents)
+ const git_signature *author, const git_signature *committer,
+ const char *notes_ref, git_tree *tree,
+ const char *target, git_commit **parents)
{
int error;
git_tree *tree_after_removal = NULL;
@@ -406,7 +406,7 @@ static int retrieve_note_tree_and_commit(
if ((error = normalize_namespace(notes_ref, repo)) < 0)
return error;
- if ((error = git_reference_name_to_oid(&oid, repo, *notes_ref)) < 0)
+ if ((error = git_reference_name_to_id(&oid, repo, *notes_ref)) < 0)
return error;
if (git_commit_lookup(commit_out, repo, &oid) < 0)
@@ -442,9 +442,12 @@ cleanup:
}
int git_note_create(
- git_oid *out, git_repository *repo,
- git_signature *author, git_signature *committer,
- const char *notes_ref, const git_oid *oid,
+ git_oid *out,
+ git_repository *repo,
+ const git_signature *author,
+ const git_signature *committer,
+ const char *notes_ref,
+ const git_oid *oid,
const char *note)
{
int error;
@@ -461,7 +464,7 @@ int git_note_create(
goto cleanup;
error = note_write(out, repo, author, committer, notes_ref,
- note, tree, target, &commit);
+ note, tree, target, &commit);
cleanup:
git__free(target);
@@ -471,8 +474,8 @@ cleanup:
}
int git_note_remove(git_repository *repo, const char *notes_ref,
- git_signature *author, git_signature *committer,
- const git_oid *oid)
+ const git_signature *author, const git_signature *committer,
+ const git_oid *oid)
{
int error;
char *target = NULL;
@@ -501,13 +504,13 @@ int git_note_default_ref(const char **out, git_repository *repo)
return note_get_default_ref(out, repo);
}
-const char * git_note_message(git_note *note)
+const char * git_note_message(const git_note *note)
{
assert(note);
return note->message;
}
-const git_oid * git_note_oid(git_note *note)
+const git_oid * git_note_oid(const git_note *note)
{
assert(note);
return &note->oid;
@@ -525,13 +528,13 @@ void git_note_free(git_note *note)
static int process_entry_path(
const char* entry_path,
const git_oid *note_oid,
- int (*note_cb)(git_note_data *note_data, void *payload),
+ git_note_foreach_cb note_cb,
void *payload)
{
int error = -1;
size_t i = 0, j = 0, len;
git_buf buf = GIT_BUF_INIT;
- git_note_data note_data;
+ git_oid annotated_object_id;
if ((error = git_buf_puts(&buf, entry_path)) < 0)
goto cleanup;
@@ -564,13 +567,10 @@ static int process_entry_path(
goto cleanup;
}
- if ((error = git_oid_fromstr(
- &note_data.annotated_object_oid, buf.ptr)) < 0)
+ if ((error = git_oid_fromstr(&annotated_object_id, buf.ptr)) < 0)
goto cleanup;
- git_oid_cpy(&note_data.blob_oid, note_oid);
-
- if (note_cb(&note_data, payload))
+ if (note_cb(note_oid, &annotated_object_id, payload))
error = GIT_EUSER;
cleanup:
@@ -581,7 +581,7 @@ cleanup:
int git_note_foreach(
git_repository *repo,
const char *notes_ref,
- int (*note_cb)(git_note_data *note_data, void *payload),
+ git_note_foreach_cb note_cb,
void *payload)
{
int error;
diff --git a/src/object.c b/src/object.c
index 3d953039c..f71ee48d3 100644
--- a/src/object.c
+++ b/src/object.c
@@ -334,7 +334,7 @@ static int dereference_object(git_object **dereferenced, git_object *obj)
int git_object_peel(
git_object **peeled,
- git_object *object,
+ const git_object *object,
git_otype target_type)
{
git_object *source, *deref = NULL;
@@ -342,9 +342,9 @@ int git_object_peel(
assert(object && peeled);
if (git_object_type(object) == target_type)
- return git_object__dup(peeled, object);
+ return git_object__dup(peeled, (git_object *)object);
- source = object;
+ source = (git_object *)object;
while (!dereference_object(&deref, source)) {
diff --git a/src/odb.c b/src/odb.c
index 9c602d1d2..e622eb076 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -683,14 +683,14 @@ int git_odb_read_prefix(
return 0;
}
-int git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data), void *data)
+int git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload)
{
unsigned int i;
backend_internal *internal;
git_vector_foreach(&db->backends, i, internal) {
git_odb_backend *b = internal->backend;
- int error = b->foreach(b, cb, data);
+ int error = b->foreach(b, cb, payload);
if (error < 0)
return error;
}
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 41121ae10..e2f1aec32 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -678,7 +678,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
struct foreach_state {
size_t dir_len;
- int (*cb)(git_oid *oid, void *data);
+ git_odb_foreach_cb cb;
void *data;
int cb_error;
};
@@ -734,7 +734,7 @@ static int foreach_cb(void *_state, git_buf *path)
return git_path_direach(path, foreach_object_dir_cb, state);
}
-static int loose_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
+static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
{
char *objects_dir;
int error;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 9f7a6ee1f..35bf1580d 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -458,7 +458,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0;
}
-static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
+static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
{
int error;
struct git_pack_file *p;
diff --git a/src/pack-objects.c b/src/pack-objects.c
index a146dc048..008d8f288 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -136,10 +136,11 @@ on_error:
return -1;
}
-void git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
+unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
{
assert(pb);
pb->nr_threads = n;
+ return pb->nr_threads;
}
static void rehash(git_packbuilder *pb)
@@ -228,7 +229,7 @@ static int gen_pack_object_header(
}
*hdr++ = c;
- return hdr - hdr_base;
+ return (int)(hdr - hdr_base);
}
static int get_delta(void **out, git_odb *odb, git_pobject *po)
@@ -243,9 +244,10 @@ static int get_delta(void **out, git_odb *odb, git_pobject *po)
git_odb_read(&trg, odb, &po->id) < 0)
goto on_error;
- delta_buf = git_delta(git_odb_object_data(src), git_odb_object_size(src),
- git_odb_object_data(trg), git_odb_object_size(trg),
- &delta_size, 0);
+ delta_buf = git_delta(
+ git_odb_object_data(src), (unsigned long)git_odb_object_size(src),
+ git_odb_object_data(trg), (unsigned long)git_odb_object_size(trg),
+ &delta_size, 0);
if (!delta_buf || delta_size != po->delta_size) {
giterr_set(GITERR_INVALID, "Delta size changed");
@@ -286,7 +288,7 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
goto on_error;
data = (void *)git_odb_object_data(obj);
- size = git_odb_object_size(obj);
+ size = (unsigned long)git_odb_object_size(obj);
type = git_odb_object_type(obj);
}
@@ -314,7 +316,7 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
if (po->delta)
git__free(data);
data = zbuf.ptr;
- size = zbuf.size;
+ size = (unsigned long)zbuf.size;
}
if (git_buf_put(buf, data, size) < 0 ||
@@ -706,7 +708,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
return 0;
/* Now some size filtering heuristics. */
- trg_size = trg_object->size;
+ trg_size = (unsigned long)trg_object->size;
if (!trg_object->delta) {
max_size = trg_size/2 - 20;
ref_depth = 1;
@@ -720,7 +722,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
if (max_size == 0)
return 0;
- src_size = src_object->size;
+ src_size = (unsigned long)src_object->size;
sizediff = src_size < trg_size ? trg_size - src_size : 0;
if (sizediff >= max_size)
return 0;
@@ -732,7 +734,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
return -1;
- sz = git_odb_object_size(obj);
+ sz = (unsigned long)git_odb_object_size(obj);
trg->data = git__malloc(sz);
GITERR_CHECK_ALLOC(trg->data);
memcpy(trg->data, git_odb_object_data(obj), sz);
@@ -751,7 +753,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
if (git_odb_read(&obj, pb->odb, &src_object->id) < 0)
return -1;
- sz = git_odb_object_size(obj);
+ sz = (unsigned long)git_odb_object_size(obj);
src->data = git__malloc(sz);
GITERR_CHECK_ALLOC(src->data);
memcpy(src->data, git_odb_object_data(obj), sz);
@@ -834,7 +836,7 @@ static unsigned long free_unpacked(struct unpacked *n)
git_delta_free_index(n->index);
n->index = NULL;
if (n->data) {
- freed_mem += n->object->size;
+ freed_mem += (unsigned long)n->object->size;
git__free(n->data);
n->data = NULL;
}
@@ -940,7 +942,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
GITERR_CHECK_ALLOC(po->delta_data);
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
- po->z_delta_size = zbuf.size;
+ po->z_delta_size = (unsigned long)zbuf.size;
git_buf_clear(&zbuf);
git_packbuilder__cache_lock(pb);
@@ -1283,7 +1285,7 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
git_packbuilder_insert(pb, oid, NULL) < 0)
return -1;
- if (git_tree_walk(tree, cb_tree_walk, GIT_TREEWALK_PRE, pb) < 0) {
+ if (git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, pb) < 0) {
git_tree_free(tree);
return -1;
}
diff --git a/src/pack.c b/src/pack.c
index a2a2fbcd1..6cb46d37b 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -698,7 +698,7 @@ static int git__memcmp4(const void *a, const void *b) {
int git_pack_foreach_entry(
struct git_pack_file *p,
- int (*cb)(git_oid *oid, void *data),
+ git_odb_foreach_cb cb,
void *data)
{
const unsigned char *index = p->index_map.data, *current;
diff --git a/src/pack.h b/src/pack.h
index af87b7cd5..9fb26b6a9 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -105,7 +105,7 @@ int git_pack_entry_find(
size_t len);
int git_pack_foreach_entry(
struct git_pack_file *p,
- int (*cb)(git_oid *oid, void *data),
+ git_odb_foreach_cb cb,
void *data);
#endif
diff --git a/src/reflog.c b/src/reflog.c
index 7b07c6a9f..ac481fb81 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -10,7 +10,7 @@
#include "filebuf.h"
#include "signature.h"
-static int reflog_init(git_reflog **reflog, git_reference *ref)
+static int reflog_init(git_reflog **reflog, const git_reference *ref)
{
git_reflog *log;
@@ -180,7 +180,7 @@ void git_reflog_free(git_reflog *reflog)
git__free(reflog);
}
-static int retrieve_reflog_path(git_buf *path, git_reference *ref)
+static int retrieve_reflog_path(git_buf *path, const git_reference *ref)
{
return git_buf_join_n(path, '/', 3,
git_reference_owner(ref)->path_repository, GIT_REFLOG_DIR, ref->name);
@@ -201,7 +201,7 @@ static int create_new_reflog_file(const char *filepath)
return p_close(fd);
}
-int git_reflog_read(git_reflog **reflog, git_reference *ref)
+int git_reflog_read(git_reflog **reflog, const git_reference *ref)
{
int error = -1;
git_buf log_path = GIT_BUF_INIT;
@@ -275,7 +275,7 @@ int git_reflog_write(git_reflog *reflog)
if ((error = git_filebuf_write(&fbuf, log.ptr, log.size)) < 0)
goto cleanup;
}
-
+
error = git_filebuf_commit(&fbuf, GIT_REFLOG_FILE_MODE);
goto success;
@@ -405,45 +405,47 @@ int git_reflog_delete(git_reference *ref)
return error;
}
-unsigned int git_reflog_entrycount(git_reflog *reflog)
+size_t git_reflog_entrycount(git_reflog *reflog)
{
assert(reflog);
- return (unsigned int)reflog->entries.length;
+ return reflog->entries.length;
}
-const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, size_t idx)
+GIT_INLINE(size_t) reflog_inverse_index(size_t idx, size_t total)
{
- int pos;
+ return (total - 1) - idx;
+}
+const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, size_t idx)
+{
assert(reflog);
- pos = git_reflog_entrycount(reflog) - (idx + 1);
-
- if (pos < 0)
+ if (idx >= reflog->entries.length)
return NULL;
- return git_vector_get(&reflog->entries, pos);
+ return git_vector_get(
+ &reflog->entries, reflog_inverse_index(idx, reflog->entries.length));
}
-const git_oid * git_reflog_entry_oidold(const git_reflog_entry *entry)
+const git_oid * git_reflog_entry_id_old(const git_reflog_entry *entry)
{
assert(entry);
return &entry->oid_old;
}
-const git_oid * git_reflog_entry_oidnew(const git_reflog_entry *entry)
+const git_oid * git_reflog_entry_id_new(const git_reflog_entry *entry)
{
assert(entry);
return &entry->oid_cur;
}
-git_signature * git_reflog_entry_committer(const git_reflog_entry *entry)
+const git_signature * git_reflog_entry_committer(const git_reflog_entry *entry)
{
assert(entry);
return entry->committer;
}
-char * git_reflog_entry_msg(const git_reflog_entry *entry)
+const char * git_reflog_entry_message(const git_reflog_entry *entry)
{
assert(entry);
return entry->msg;
@@ -454,7 +456,7 @@ int git_reflog_drop(
size_t idx,
int rewrite_previous_entry)
{
- unsigned int entrycount;
+ size_t entrycount;
git_reflog_entry *entry, *previous;
assert(reflog);
@@ -468,7 +470,8 @@ int git_reflog_drop(
reflog_entry_free(entry);
- if (git_vector_remove(&reflog->entries, entrycount - (idx + 1)) < 0)
+ if (git_vector_remove(
+ &reflog->entries, reflog_inverse_index(idx, entrycount)) < 0)
return -1;
if (!rewrite_previous_entry)
@@ -489,7 +492,7 @@ int git_reflog_drop(
/* ...clear the oid_old member of the "new" oldest entry */
if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0)
return -1;
-
+
return 0;
}
diff --git a/src/refs.c b/src/refs.c
index 97c97563e..76c9f42ba 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -647,7 +647,7 @@ static int packed_find_peel(git_repository *repo, struct packref *ref)
/*
* Find the object pointed at by this tag
*/
- git_oid_cpy(&ref->peel, git_tag_target_oid(tag));
+ git_oid_cpy(&ref->peel, git_tag_target_id(tag));
ref->flags |= GIT_PACKREF_HAS_PEEL;
/*
@@ -1074,7 +1074,7 @@ int git_reference_lookup(git_reference **ref_out,
return git_reference_lookup_resolved(ref_out, repo, name, 0);
}
-int git_reference_name_to_oid(
+int git_reference_name_to_id(
git_oid *out, git_repository *repo, const char *name)
{
int error;
@@ -1083,7 +1083,7 @@ int git_reference_name_to_oid(
if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0)
return error;
- git_oid_cpy(out, git_reference_oid(ref));
+ git_oid_cpy(out, git_reference_target(ref));
git_reference_free(ref);
return 0;
}
@@ -1153,7 +1153,7 @@ int git_reference_lookup_resolved(
/**
* Getters
*/
-git_ref_t git_reference_type(git_reference *ref)
+git_ref_t git_reference_type(const git_reference *ref)
{
assert(ref);
@@ -1172,19 +1172,19 @@ int git_reference_is_packed(git_reference *ref)
return !!(ref->flags & GIT_REF_PACKED);
}
-const char *git_reference_name(git_reference *ref)
+const char *git_reference_name(const git_reference *ref)
{
assert(ref);
return ref->name;
}
-git_repository *git_reference_owner(git_reference *ref)
+git_repository *git_reference_owner(const git_reference *ref)
{
assert(ref);
return ref->owner;
}
-const git_oid *git_reference_oid(git_reference *ref)
+const git_oid *git_reference_target(const git_reference *ref)
{
assert(ref);
@@ -1194,7 +1194,7 @@ const git_oid *git_reference_oid(git_reference *ref)
return &ref->target.oid;
}
-const char *git_reference_target(git_reference *ref)
+const char *git_reference_symbolic_target(const git_reference *ref)
{
assert(ref);
@@ -1204,7 +1204,7 @@ const char *git_reference_target(git_reference *ref)
return ref->target.symbolic;
}
-int git_reference_create_symbolic(
+int git_reference_symbolic_create(
git_reference **ref_out,
git_repository *repo,
const char *name,
@@ -1231,7 +1231,7 @@ int git_reference_create_symbolic(
/* set the target; this will normalize the name automatically
* and write the reference on disk */
- if (git_reference_set_target(ref, target) < 0) {
+ if (git_reference_symbolic_set_target(ref, target) < 0) {
git_reference_free(ref);
return -1;
}
@@ -1244,7 +1244,7 @@ int git_reference_create_symbolic(
return 0;
}
-int git_reference_create_oid(
+int git_reference_create(
git_reference **ref_out,
git_repository *repo,
const char *name,
@@ -1270,7 +1270,7 @@ int git_reference_create_oid(
ref->flags |= GIT_REF_OID;
/* set the oid; this will write the reference on disk */
- if (git_reference_set_oid(ref, id) < 0) {
+ if (git_reference_set_target(ref, id) < 0) {
git_reference_free(ref);
return -1;
}
@@ -1292,7 +1292,7 @@ int git_reference_create_oid(
* We do not repack packed references because of performance
* reasons.
*/
-int git_reference_set_oid(git_reference *ref, const git_oid *id)
+int git_reference_set_target(git_reference *ref, const git_oid *id)
{
git_odb *odb = NULL;
@@ -1328,7 +1328,7 @@ int git_reference_set_oid(git_reference *ref, const git_oid *id)
* a pack. We just change the target in memory
* and overwrite the file on disk.
*/
-int git_reference_set_target(git_reference *ref, const char *target)
+int git_reference_symbolic_set_target(git_reference *ref, const char *target)
{
char normalized[GIT_REFNAME_MAX];
@@ -1397,10 +1397,10 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
* Finally we can create the new reference.
*/
if (ref->flags & GIT_REF_SYMBOLIC) {
- result = git_reference_create_symbolic(
+ result = git_reference_symbolic_create(
NULL, ref->owner, new_name, ref->target.symbolic, force);
} else {
- result = git_reference_create_oid(
+ result = git_reference_create(
NULL, ref->owner, new_name, &ref->target.oid, force);
}
@@ -1444,10 +1444,10 @@ rollback:
* Try to create the old reference again, ignore failures
*/
if (ref->flags & GIT_REF_SYMBOLIC)
- git_reference_create_symbolic(
+ git_reference_symbolic_create(
NULL, ref->owner, ref->name, ref->target.symbolic, 0);
else
- git_reference_create_oid(
+ git_reference_create(
NULL, ref->owner, ref->name, &ref->target.oid, 0);
/* The reference is no longer packed */
@@ -1457,7 +1457,7 @@ rollback:
return -1;
}
-int git_reference_resolve(git_reference **ref_out, git_reference *ref)
+int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
{
if (ref->flags & GIT_REF_OID)
return git_reference_lookup(ref_out, ref->owner, ref->name);
@@ -1478,7 +1478,7 @@ int git_reference_packall(git_repository *repo)
int git_reference_foreach(
git_repository *repo,
unsigned int list_flags,
- int (*callback)(const char *, void *),
+ git_reference_foreach_cb callback,
void *payload)
{
int result;
@@ -1797,7 +1797,7 @@ int git_reference__update(git_repository *repo, const git_oid *oid, const char *
* a new reference and that's it */
if (res == GIT_ENOTFOUND) {
giterr_clear();
- return git_reference_create_oid(NULL, repo, ref_name, oid, 1);
+ return git_reference_create(NULL, repo, ref_name, oid, 1);
}
if (res < 0)
@@ -1810,7 +1810,7 @@ int git_reference__update(git_repository *repo, const git_oid *oid, const char *
const char *sym_target;
/* The target pointed at by this reference */
- sym_target = git_reference_target(ref);
+ sym_target = git_reference_symbolic_target(ref);
/* resolve the reference to the target it points to */
res = git_reference_resolve(&aux, ref);
@@ -1822,7 +1822,7 @@ int git_reference__update(git_repository *repo, const git_oid *oid, const char *
*/
if (res == GIT_ENOTFOUND) {
giterr_clear();
- res = git_reference_create_oid(NULL, repo, sym_target, oid, 1);
+ res = git_reference_create(NULL, repo, sym_target, oid, 1);
git_reference_free(ref);
return res;
}
@@ -1840,7 +1840,7 @@ int git_reference__update(git_repository *repo, const git_oid *oid, const char *
/* ref is made to point to `oid`: ref is either the original reference,
* or the target of the symbolic reference we've looked up */
- res = git_reference_set_oid(ref, oid);
+ res = git_reference_set_target(ref, oid);
git_reference_free(ref);
return res;
}
@@ -1923,7 +1923,7 @@ static int reference_target(git_object **object, git_reference *ref)
{
const git_oid *oid;
- oid = git_reference_oid(ref);
+ oid = git_reference_target(ref);
return git_object_lookup(object, git_reference_owner(ref), oid, GIT_OBJ_ANY);
}
diff --git a/src/remote.c b/src/remote.c
index 4a4d160eb..bdec3c1f4 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -252,7 +252,7 @@ static int update_config_refspec(
&name,
"remote.%s.%s",
remote_name,
- git_direction == GIT_DIR_FETCH ? "fetch" : "push") < 0)
+ git_direction == GIT_DIRECTION_FETCH ? "fetch" : "push") < 0)
goto cleanup;
if (git_refspec__serialize(&value, refspec) < 0)
@@ -303,7 +303,7 @@ int git_remote_save(const git_remote *remote)
return -1;
}
} else {
- int error = git_config_delete(config, git_buf_cstr(&buf));
+ int error = git_config_delete_entry(config, git_buf_cstr(&buf));
if (error == GIT_ENOTFOUND) {
error = 0;
giterr_clear();
@@ -318,14 +318,14 @@ int git_remote_save(const git_remote *remote)
config,
remote->name,
&remote->fetch,
- GIT_DIR_FETCH) < 0)
+ GIT_DIRECTION_FETCH) < 0)
goto on_error;
if (update_config_refspec(
config,
remote->name,
&remote->push,
- GIT_DIR_PUSH) < 0)
+ GIT_DIRECTION_PUSH) < 0)
goto on_error;
/*
@@ -356,7 +356,7 @@ int git_remote_save(const git_remote *remote)
if (git_config_set_string(config, git_buf_cstr(&buf), "--no-tags") < 0)
goto on_error;
} else if (tagopt) {
- if (git_config_delete(config, git_buf_cstr(&buf)) < 0)
+ if (git_config_delete_entry(config, git_buf_cstr(&buf)) < 0)
goto on_error;
}
@@ -369,13 +369,13 @@ on_error:
return -1;
}
-const char *git_remote_name(git_remote *remote)
+const char *git_remote_name(const git_remote *remote)
{
assert(remote);
return remote->name;
}
-const char *git_remote_url(git_remote *remote)
+const char *git_remote_url(const git_remote *remote)
{
assert(remote);
return remote->url;
@@ -393,7 +393,7 @@ int git_remote_set_url(git_remote *remote, const char* url)
return 0;
}
-const char *git_remote_pushurl(git_remote *remote)
+const char *git_remote_pushurl(const git_remote *remote)
{
assert(remote);
return remote->pushurl;
@@ -429,7 +429,7 @@ int git_remote_set_fetchspec(git_remote *remote, const char *spec)
return 0;
}
-const git_refspec *git_remote_fetchspec(git_remote *remote)
+const git_refspec *git_remote_fetchspec(const git_remote *remote)
{
assert(remote);
return &remote->fetch;
@@ -451,7 +451,7 @@ int git_remote_set_pushspec(git_remote *remote, const char *spec)
return 0;
}
-const git_refspec *git_remote_pushspec(git_remote *remote)
+const git_refspec *git_remote_pushspec(const git_remote *remote)
{
assert(remote);
return &remote->push;
@@ -461,18 +461,18 @@ const char* git_remote__urlfordirection(git_remote *remote, int direction)
{
assert(remote);
- if (direction == GIT_DIR_FETCH) {
+ if (direction == GIT_DIRECTION_FETCH) {
return remote->url;
}
- if (direction == GIT_DIR_PUSH) {
+ if (direction == GIT_DIRECTION_PUSH) {
return remote->pushurl ? remote->pushurl : remote->url;
}
return NULL;
}
-int git_remote_connect(git_remote *remote, int direction)
+int git_remote_connect(git_remote *remote, git_direction direction)
{
git_transport *t;
const char *url;
@@ -492,7 +492,7 @@ int git_remote_connect(git_remote *remote, int direction)
return -1;
if (t->set_callbacks &&
- t->set_callbacks(t, remote->callbacks.progress, NULL, remote->callbacks.data) < 0)
+ t->set_callbacks(t, remote->callbacks.progress, NULL, remote->callbacks.payload) < 0)
goto on_error;
if (!remote->check_cert)
@@ -695,7 +695,7 @@ int git_remote_update_tips(git_remote *remote)
head = (git_remote_head *)refs.contents[0];
if (!strcmp(head->name, GIT_HEAD_FILE)) {
- if (git_reference_create_oid(&ref, remote->repo, GIT_FETCH_HEAD_FILE, &head->oid, 1) < 0)
+ if (git_reference_create(&ref, remote->repo, GIT_FETCH_HEAD_FILE, &head->oid, 1) < 0)
goto on_error;
i = 1;
@@ -735,7 +735,7 @@ int git_remote_update_tips(git_remote *remote)
if (git_vector_insert(&update_heads, head) < 0)
goto on_error;
- error = git_reference_name_to_oid(&old, remote->repo, refname.ptr);
+ error = git_reference_name_to_id(&old, remote->repo, refname.ptr);
if (error < 0 && error != GIT_ENOTFOUND)
goto on_error;
@@ -746,14 +746,14 @@ int git_remote_update_tips(git_remote *remote)
continue;
/* In autotag mode, don't overwrite any locally-existing tags */
- error = git_reference_create_oid(&ref, remote->repo, refname.ptr, &head->oid, !autotag);
+ error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag);
if (error < 0 && error != GIT_EEXISTS)
goto on_error;
git_reference_free(ref);
if (remote->callbacks.update_tips != NULL) {
- if (remote->callbacks.update_tips(refname.ptr, &old, &head->oid, remote->callbacks.data) < 0)
+ if (remote->callbacks.update_tips(refname.ptr, &old, &head->oid, remote->callbacks.payload) < 0)
goto on_error;
}
}
@@ -936,7 +936,7 @@ void git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callback
remote->transport->set_callbacks(remote->transport,
remote->callbacks.progress,
NULL,
- remote->callbacks.data);
+ remote->callbacks.payload);
}
void git_remote_set_cred_acquire_cb(
@@ -967,12 +967,12 @@ const git_transfer_progress* git_remote_stats(git_remote *remote)
return &remote->stats;
}
-int git_remote_autotag(git_remote *remote)
+git_remote_autotag_option_t git_remote_autotag(git_remote *remote)
{
return remote->download_tags;
}
-void git_remote_set_autotag(git_remote *remote, int value)
+void git_remote_set_autotag(git_remote *remote, git_remote_autotag_option_t value)
{
remote->download_tags = value;
}
@@ -1194,7 +1194,7 @@ static int rename_fetch_refspecs(
if (git_repository_config__weakptr(&config, remote->repo) < 0)
goto cleanup;
- error = update_config_refspec(config, new_name, &remote->fetch, GIT_DIR_FETCH);
+ error = update_config_refspec(config, new_name, &remote->fetch, GIT_DIRECTION_FETCH);
cleanup:
git_buf_free(&serialized);
@@ -1205,7 +1205,7 @@ cleanup:
int git_remote_rename(
git_remote *remote,
const char *new_name,
- int (*callback)(const char *problematic_refspec, void *payload),
+ git_remote_rename_problem_cb callback,
void *payload)
{
int error;
diff --git a/src/remote.h b/src/remote.h
index 840c9a905..448a9e9a9 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -27,10 +27,10 @@ struct git_remote {
git_repository *repo;
git_remote_callbacks callbacks;
git_transfer_progress stats;
- unsigned int need_pack:1,
- download_tags:2, /* There are four possible values */
- check_cert:1,
- update_fetchhead:1;
+ unsigned int need_pack;
+ git_remote_autotag_option_t download_tags;
+ unsigned int check_cert;
+ unsigned int update_fetchhead;
};
const char* git_remote__urlfordirection(struct git_remote *remote, int direction);
diff --git a/src/repository.c b/src/repository.c
index deab77192..b49b49b7a 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -361,7 +361,7 @@ static int find_repo(
int git_repository_open_ext(
git_repository **repo_ptr,
const char *start_path,
- uint32_t flags,
+ unsigned int flags,
const char *ceiling_dirs)
{
int error;
@@ -824,7 +824,7 @@ static int repo_init_config(
SET_REPO_CONFIG(string, "core.worktree", work_dir);
}
else if ((opts->flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0) {
- if (git_config_delete(config, "core.worktree") < 0)
+ if (git_config_delete_entry(config, "core.worktree") < 0)
giterr_clear();
}
} else {
@@ -1162,14 +1162,14 @@ int git_repository_init(
}
int git_repository_init_ext(
- git_repository **repo_out,
+ git_repository **out,
const char *given_repo,
git_repository_init_options *opts)
{
int error;
git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT;
- assert(repo_out && given_repo && opts);
+ assert(out && given_repo && opts);
error = repo_init_directories(&repo_path, &wd_path, given_repo, opts);
if (error < 0)
@@ -1202,10 +1202,10 @@ int git_repository_init_ext(
if (error < 0)
goto cleanup;
- error = git_repository_open(repo_out, git_buf_cstr(&repo_path));
+ error = git_repository_open(out, git_buf_cstr(&repo_path));
if (!error && opts->origin_url)
- error = repo_init_create_origin(*repo_out, opts->origin_url);
+ error = repo_init_create_origin(*out, opts->origin_url);
cleanup:
git_buf_free(&repo_path);
@@ -1231,7 +1231,7 @@ int git_repository_head_detached(git_repository *repo)
return 0;
}
- exists = git_odb_exists(odb, git_reference_oid(ref));
+ exists = git_odb_exists(odb, git_reference_target(ref));
git_reference_free(ref);
return exists;
@@ -1250,7 +1250,7 @@ int git_repository_head(git_reference **head_out, git_repository *repo)
return 0;
}
- error = git_reference_lookup_resolved(head_out, repo, git_reference_target(head), -1);
+ error = git_reference_lookup_resolved(head_out, repo, git_reference_symbolic_target(head), -1);
git_reference_free(head);
return error == GIT_ENOTFOUND ? GIT_EORPHANEDHEAD : error;
@@ -1305,7 +1305,7 @@ int git_repository_is_empty(git_repository *repo)
goto cleanup;
if (!(error = strcmp(
- git_reference_target(head),
+ git_reference_symbolic_target(head),
GIT_REFS_HEADS_DIR "master") == 0))
goto cleanup;
@@ -1356,7 +1356,7 @@ int git_repository_set_workdir(
/* passthrough error means gitlink is unnecessary */
if (error == GIT_PASSTHROUGH)
- error = git_config_delete(config, "core.worktree");
+ error = git_config_delete_entry(config, "core.worktree");
else if (!error)
error = git_config_set_string(config, "core.worktree", path.ptr);
@@ -1531,11 +1531,11 @@ int git_repository_set_head(
if (!error) {
if (git_reference_is_branch(ref))
- error = git_reference_create_symbolic(&new_head, repo, GIT_HEAD_FILE, git_reference_name(ref), 1);
+ error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, git_reference_name(ref), 1);
else
- error = git_repository_set_head_detached(repo, git_reference_oid(ref));
+ error = git_repository_set_head_detached(repo, git_reference_target(ref));
} else if (looks_like_a_branch(refname))
- error = git_reference_create_symbolic(&new_head, repo, GIT_HEAD_FILE, refname, 1);
+ error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname, 1);
git_reference_free(ref);
git_reference_free(new_head);
@@ -1559,7 +1559,7 @@ int git_repository_set_head_detached(
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create_oid(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), 1);
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), 1);
cleanup:
git_object_free(object);
@@ -1581,10 +1581,10 @@ int git_repository_detach_head(
if ((error = git_repository_head(&old_head, repo)) < 0)
return error;
- if ((error = git_object_lookup(&object, repo, git_reference_oid(old_head), GIT_OBJ_COMMIT)) < 0)
+ if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0)
goto cleanup;
- error = git_reference_create_oid(&new_head, repo, GIT_HEAD_FILE, git_reference_oid(old_head), 1);
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head), 1);
cleanup:
git_object_free(object);
diff --git a/src/reset.c b/src/reset.c
index 8f470b26a..d410a8806 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -41,14 +41,14 @@ static int update_head(git_repository *repo, git_object *commit)
if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
goto cleanup;
- if ((error = git_reference_create_oid(
+ if ((error = git_reference_create(
&target,
repo,
- git_reference_target(head),
+ git_reference_symbolic_target(head),
git_object_id(commit), 0)) < 0)
goto cleanup;
} else {
- if ((error = git_reference_set_oid(head, git_object_id(commit))) < 0)
+ if ((error = git_reference_set_target(head, git_object_id(commit))) < 0)
goto cleanup;
}
@@ -63,7 +63,7 @@ cleanup:
int git_reset(
git_repository *repo,
git_object *target,
- git_reset_type reset_type)
+ git_reset_t reset_type)
{
git_object *commit = NULL;
git_index *index = NULL;
diff --git a/src/revparse.c b/src/revparse.c
index 6b49402c4..308b92923 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -140,7 +140,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
error = disambiguate_refname(&ref, repo, spec);
if (!error) {
- error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY);
+ error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJ_ANY);
git_reference_free(ref);
return error;
}
@@ -161,7 +161,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
static int try_parse_numeric(int *n, const char *curly_braces_content)
{
- int content;
+ int32_t content;
const char *end_ptr;
if (git__strtol32(&content, curly_braces_content, &end_ptr, 10) < 0)
@@ -170,16 +170,17 @@ static int try_parse_numeric(int *n, const char *curly_braces_content)
if (*end_ptr != '\0')
return -1;
- *n = content;
+ *n = (int)content;
return 0;
}
-static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *spec, const char *identifier, unsigned int position)
+static int retrieve_previously_checked_out_branch_or_revision(git_object **out, git_reference **base_ref, git_repository *repo, const char *spec, const char *identifier, size_t position)
{
git_reference *ref = NULL;
git_reflog *reflog = NULL;
regex_t preg;
- int numentries, i, cur, error = -1;
+ int error = -1;
+ size_t i, numentries, cur;
const git_reflog_entry *entry;
const char *msg;
regmatch_t regexmatches[2];
@@ -203,8 +204,8 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
for (i = 0; i < numentries; i++) {
entry = git_reflog_entry_byindex(reflog, i);
- msg = git_reflog_entry_msg(entry);
-
+ msg = git_reflog_entry_message(entry);
+
if (regexec(&preg, msg, 2, regexmatches, 0))
continue;
@@ -212,7 +213,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if (cur > 0)
continue;
-
+
git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);
if ((error = disambiguate_refname(base_ref, repo, git_buf_cstr(&buf))) == 0)
@@ -225,7 +226,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
goto cleanup;
}
-
+
error = GIT_ENOTFOUND;
cleanup:
@@ -236,49 +237,47 @@ cleanup:
return error;
}
-static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, unsigned int identifier)
+static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier)
{
git_reflog *reflog;
int error = -1;
- unsigned int numentries;
+ size_t numentries;
const git_reflog_entry *entry;
bool search_by_pos = (identifier <= 100000000);
if (git_reflog_read(&reflog, ref) < 0)
return -1;
- numentries = git_reflog_entrycount(reflog);
+ numentries = git_reflog_entrycount(reflog);
if (search_by_pos) {
if (numentries < identifier + 1) {
giterr_set(
GITERR_REFERENCE,
- "Reflog for '%s' has only %d entries, asked for %d",
- git_reference_name(ref),
- numentries,
- identifier);
+ "Reflog for '%s' has only "PRIuZ" entries, asked for "PRIuZ,
+ git_reference_name(ref), numentries, identifier);
error = GIT_ENOTFOUND;
goto cleanup;
}
entry = git_reflog_entry_byindex(reflog, identifier);
- git_oid_cpy(oid, git_reflog_entry_oidnew(entry));
+ git_oid_cpy(oid, git_reflog_entry_id_new(entry));
error = 0;
goto cleanup;
} else {
- unsigned int i;
+ size_t i;
git_time commit_time;
for (i = 0; i < numentries; i++) {
entry = git_reflog_entry_byindex(reflog, i);
commit_time = git_reflog_entry_committer(entry)->when;
-
- if (commit_time.time - identifier > 0)
+
+ if (commit_time.time > (git_time_t)identifier)
continue;
- git_oid_cpy(oid, git_reflog_entry_oidnew(entry));
+ git_oid_cpy(oid, git_reflog_entry_id_new(entry));
error = 0;
goto cleanup;
}
@@ -291,7 +290,7 @@ cleanup:
return error;
}
-static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, unsigned int position)
+static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position)
{
git_reference *ref;
git_oid oid;
@@ -306,7 +305,7 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base
}
if (position == 0) {
- error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY);
+ error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJ_ANY);
goto cleanup;
}
@@ -380,7 +379,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
if (git__date_parse(&timestamp, curly_braces_content) < 0)
goto cleanup;
- error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), (unsigned int)timestamp);
+ error = retrieve_revobject_from_reflog(out, ref, repo, git_buf_cstr(&identifier), (size_t)timestamp);
cleanup:
git_buf_free(&identifier);
@@ -394,7 +393,7 @@ static git_otype parse_obj_type(const char *str)
if (!strcmp(str, "tree"))
return GIT_OBJ_TREE;
-
+
if (!strcmp(str, "blob"))
return GIT_OBJ_BLOB;
@@ -632,7 +631,7 @@ static int object_from_reference(git_object **object, git_reference *reference)
if (git_reference_resolve(&resolved, reference) < 0)
return -1;
- error = git_object_lookup(object, reference->owner, git_reference_oid(resolved), GIT_OBJ_ANY);
+ error = git_object_lookup(object, reference->owner, git_reference_target(resolved), GIT_OBJ_ANY);
git_reference_free(resolved);
return error;
diff --git a/src/revwalk.c b/src/revwalk.c
index 4fff238ca..bdbbdbd17 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -8,149 +8,16 @@
#include "common.h"
#include "commit.h"
#include "odb.h"
-#include "pqueue.h"
#include "pool.h"
-#include "oidmap.h"
-#include "git2/revwalk.h"
-#include "git2/merge.h"
+#include "revwalk.h"
+#include "merge.h"
#include <regex.h>
-GIT__USE_OIDMAP;
-
-#define PARENT1 (1 << 0)
-#define PARENT2 (1 << 1)
-#define RESULT (1 << 2)
-#define STALE (1 << 3)
-
-typedef struct commit_object {
- git_oid oid;
- uint32_t time;
- unsigned int seen:1,
- uninteresting:1,
- topo_delay:1,
- parsed:1,
- flags : 4;
-
- unsigned short in_degree;
- unsigned short out_degree;
-
- struct commit_object **parents;
-} commit_object;
-
-typedef struct commit_list {
- commit_object *item;
- struct commit_list *next;
-} commit_list;
-
-struct git_revwalk {
- git_repository *repo;
- git_odb *odb;
-
- git_oidmap *commits;
- git_pool commit_pool;
-
- commit_list *iterator_topo;
- commit_list *iterator_rand;
- commit_list *iterator_reverse;
- git_pqueue iterator_time;
-
- int (*get_next)(commit_object **, git_revwalk *);
- int (*enqueue)(git_revwalk *, commit_object *);
-
- unsigned walking:1;
- unsigned int sorting;
-
- /* merge base calculation */
- commit_object *one;
- git_vector twos;
-};
-
-static int commit_time_cmp(void *a, void *b)
-{
- commit_object *commit_a = (commit_object *)a;
- commit_object *commit_b = (commit_object *)b;
-
- return (commit_a->time < commit_b->time);
-}
-
-static commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
-{
- commit_list *new_list = git__malloc(sizeof(commit_list));
- if (new_list != NULL) {
- new_list->item = item;
- new_list->next = *list_p;
- }
- *list_p = new_list;
- return new_list;
-}
-
-static commit_list *commit_list_insert_by_date(commit_object *item, commit_list **list_p)
-{
- commit_list **pp = list_p;
- commit_list *p;
-
- while ((p = *pp) != NULL) {
- if (commit_time_cmp(p->item, item) < 0)
- break;
-
- pp = &p->next;
- }
-
- return commit_list_insert(item, pp);
-}
-static void commit_list_free(commit_list **list_p)
-{
- commit_list *list = *list_p;
-
- if (list == NULL)
- return;
-
- while (list) {
- commit_list *temp = list;
- list = temp->next;
- git__free(temp);
- }
-
- *list_p = NULL;
-}
-
-static commit_object *commit_list_pop(commit_list **stack)
-{
- commit_list *top = *stack;
- commit_object *item = top ? top->item : NULL;
-
- if (top) {
- *stack = top->next;
- git__free(top);
- }
- return item;
-}
-
-#define PARENTS_PER_COMMIT 2
-#define COMMIT_ALLOC \
- (sizeof(commit_object) + PARENTS_PER_COMMIT * sizeof(commit_object *))
-
-static commit_object *alloc_commit(git_revwalk *walk)
-{
- return (commit_object *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
-}
-
-static commit_object **alloc_parents(
- git_revwalk *walk, commit_object *commit, size_t n_parents)
-{
- if (n_parents <= PARENTS_PER_COMMIT)
- return (commit_object **)((char *)commit + sizeof(commit_object));
-
- return (commit_object **)git_pool_malloc(
- &walk->commit_pool, (uint32_t)(n_parents * sizeof(commit_object *)));
-}
-
-
-static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
+git_commit_list_node *commit_lookup(git_revwalk *walk, const git_oid *oid)
{
- commit_object *commit;
+ git_commit_list_node *commit;
khiter_t pos;
int ret;
@@ -159,7 +26,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
if (pos != kh_end(walk->commits))
return kh_value(walk->commits, pos);
- commit = alloc_commit(walk);
+ commit = git_commit_list_alloc_node(walk);
if (commit == NULL)
return NULL;
@@ -172,300 +39,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
return commit;
}
-static int commit_error(commit_object *commit, const char *msg)
-{
- char commit_oid[GIT_OID_HEXSZ + 1];
- git_oid_fmt(commit_oid, &commit->oid);
- commit_oid[GIT_OID_HEXSZ] = '\0';
-
- giterr_set(GITERR_ODB, "Failed to parse commit %s - %s", commit_oid, msg);
-
- return -1;
-}
-
-static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
-{
- const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
- unsigned char *buffer = raw->data;
- unsigned char *buffer_end = buffer + raw->len;
- unsigned char *parents_start, *committer_start;
- int i, parents = 0;
- int commit_time;
-
- buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
-
- parents_start = buffer;
- while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
- parents++;
- buffer += parent_len;
- }
-
- commit->parents = alloc_parents(walk, commit, parents);
- GITERR_CHECK_ALLOC(commit->parents);
-
- buffer = parents_start;
- for (i = 0; i < parents; ++i) {
- git_oid oid;
-
- if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < 0)
- return -1;
-
- commit->parents[i] = commit_lookup(walk, &oid);
- if (commit->parents[i] == NULL)
- return -1;
-
- buffer += parent_len;
- }
-
- commit->out_degree = (unsigned short)parents;
-
- if ((committer_start = buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
- return commit_error(commit, "object is corrupted");
-
- buffer++;
-
- if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
- return commit_error(commit, "object is corrupted");
-
- /* Skip trailing spaces */
- while (buffer > committer_start && git__isspace(*buffer))
- buffer--;
-
- /* Seek for the begining of the pack of digits */
- while (buffer > committer_start && git__isdigit(*buffer))
- buffer--;
-
- /* Skip potential timezone offset */
- if ((buffer > committer_start) && (*buffer == '+' || *buffer == '-')) {
- buffer--;
-
- while (buffer > committer_start && git__isspace(*buffer))
- buffer--;
-
- while (buffer > committer_start && git__isdigit(*buffer))
- buffer--;
- }
-
- if ((buffer == committer_start) || (git__strtol32(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
- return commit_error(commit, "cannot parse commit time");
-
- commit->time = (time_t)commit_time;
- commit->parsed = 1;
- return 0;
-}
-
-static int commit_parse(git_revwalk *walk, commit_object *commit)
-{
- git_odb_object *obj;
- int error;
-
- if (commit->parsed)
- return 0;
-
- if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
- return error;
- assert(obj->raw.type == GIT_OBJ_COMMIT);
-
- error = commit_quick_parse(walk, commit, &obj->raw);
- git_odb_object_free(obj);
- return error;
-}
-
-static int interesting(git_pqueue *list)
-{
- unsigned int i;
- /* element 0 isn't used - we need to start at 1 */
- for (i = 1; i < list->size; i++) {
- commit_object *commit = list->d[i];
- if ((commit->flags & STALE) == 0)
- return 1;
- }
-
- return 0;
-}
-
-static int merge_bases_many(commit_list **out, git_revwalk *walk, commit_object *one, git_vector *twos)
-{
- int error;
- unsigned int i;
- commit_object *two;
- commit_list *result = NULL, *tmp = NULL;
- git_pqueue list;
-
- /* if the commit is repeated, we have a our merge base already */
- git_vector_foreach(twos, i, two) {
- if (one == two)
- return commit_list_insert(one, out) ? 0 : -1;
- }
-
- if (git_pqueue_init(&list, twos->length * 2, commit_time_cmp) < 0)
- return -1;
-
- if (commit_parse(walk, one) < 0)
- return -1;
-
- one->flags |= PARENT1;
- if (git_pqueue_insert(&list, one) < 0)
- return -1;
-
- git_vector_foreach(twos, i, two) {
- commit_parse(walk, two);
- two->flags |= PARENT2;
- if (git_pqueue_insert(&list, two) < 0)
- return -1;
- }
-
- /* as long as there are non-STALE commits */
- while (interesting(&list)) {
- commit_object *commit;
- int flags;
-
- commit = git_pqueue_pop(&list);
-
- flags = commit->flags & (PARENT1 | PARENT2 | STALE);
- if (flags == (PARENT1 | PARENT2)) {
- if (!(commit->flags & RESULT)) {
- commit->flags |= RESULT;
- if (commit_list_insert(commit, &result) == NULL)
- return -1;
- }
- /* we mark the parents of a merge stale */
- flags |= STALE;
- }
-
- for (i = 0; i < commit->out_degree; i++) {
- commit_object *p = commit->parents[i];
- if ((p->flags & flags) == flags)
- continue;
-
- if ((error = commit_parse(walk, p)) < 0)
- return error;
-
- p->flags |= flags;
- if (git_pqueue_insert(&list, p) < 0)
- return -1;
- }
- }
-
- git_pqueue_free(&list);
-
- /* filter out any stale commits in the results */
- tmp = result;
- result = NULL;
-
- while (tmp) {
- struct commit_list *next = tmp->next;
- if (!(tmp->item->flags & STALE))
- if (commit_list_insert_by_date(tmp->item, &result) == NULL)
- return -1;
-
- git__free(tmp);
- tmp = next;
- }
-
- *out = result;
- return 0;
-}
-
-int git_merge_base_many(git_oid *out, git_repository *repo, const git_oid input_array[], size_t length)
-{
- git_revwalk *walk;
- git_vector list;
- commit_list *result = NULL;
- int error = -1;
- unsigned int i;
- commit_object *commit;
-
- assert(out && repo && input_array);
-
- if (length < 2) {
- giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %u.", length);
- return -1;
- }
-
- if (git_vector_init(&list, length - 1, NULL) < 0)
- return -1;
-
- if (git_revwalk_new(&walk, repo) < 0)
- goto cleanup;
-
- for (i = 1; i < length; i++) {
- commit = commit_lookup(walk, &input_array[i]);
- if (commit == NULL)
- goto cleanup;
-
- git_vector_insert(&list, commit);
- }
-
- commit = commit_lookup(walk, &input_array[0]);
- if (commit == NULL)
- goto cleanup;
-
- if (merge_bases_many(&result, walk, commit, &list) < 0)
- goto cleanup;
-
- if (!result) {
- error = GIT_ENOTFOUND;
- goto cleanup;
- }
-
- git_oid_cpy(out, &result->item->oid);
-
- error = 0;
-
-cleanup:
- commit_list_free(&result);
- git_revwalk_free(walk);
- git_vector_free(&list);
- return error;
-}
-
-int git_merge_base(git_oid *out, git_repository *repo, const git_oid *one, const git_oid *two)
-{
- git_revwalk *walk;
- git_vector list;
- commit_list *result = NULL;
- commit_object *commit;
- void *contents[1];
-
- if (git_revwalk_new(&walk, repo) < 0)
- return -1;
-
- commit = commit_lookup(walk, two);
- if (commit == NULL)
- goto on_error;
-
- /* This is just one value, so we can do it on the stack */
- memset(&list, 0x0, sizeof(git_vector));
- contents[0] = commit;
- list.length = 1;
- list.contents = contents;
-
- commit = commit_lookup(walk, one);
- if (commit == NULL)
- goto on_error;
-
- if (merge_bases_many(&result, walk, commit, &list) < 0)
- goto on_error;
-
- if (!result) {
- git_revwalk_free(walk);
- giterr_clear();
- return GIT_ENOTFOUND;
- }
-
- git_oid_cpy(out, &result->item->oid);
- commit_list_free(&result);
- git_revwalk_free(walk);
-
- return 0;
-
-on_error:
- git_revwalk_free(walk);
- return -1;
-}
-
-static void mark_uninteresting(commit_object *commit)
+static void mark_uninteresting(git_commit_list_node *commit)
{
unsigned short i;
assert(commit);
@@ -481,7 +55,7 @@ static void mark_uninteresting(commit_object *commit)
mark_uninteresting(commit->parents[i]);
}
-static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
+static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int hide)
{
int error;
@@ -493,13 +67,13 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
commit->seen = 1;
- if ((error = commit_parse(walk, commit)) < 0)
+ if ((error = git_commit_list_parse(walk, commit)) < 0)
return error;
return walk->enqueue(walk, commit);
}
-static int process_commit_parents(git_revwalk *walk, commit_object *commit)
+static int process_commit_parents(git_revwalk *walk, git_commit_list_node *commit)
{
unsigned short i;
int error = 0;
@@ -514,7 +88,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
{
git_object *obj;
git_otype type;
- commit_object *commit;
+ git_commit_list_node *commit;
if (git_object_lookup(&obj, walk->repo, oid, GIT_OBJ_ANY) < 0)
return -1;
@@ -559,7 +133,7 @@ static int push_ref(git_revwalk *walk, const char *refname, int hide)
{
git_oid oid;
- if (git_reference_name_to_oid(&oid, walk->repo, refname) < 0)
+ if (git_reference_name_to_id(&oid, walk->repo, refname) < 0)
return -1;
return push_commit(walk, &oid, hide);
@@ -659,20 +233,20 @@ int git_revwalk_hide_ref(git_revwalk *walk, const char *refname)
return push_ref(walk, refname, 1);
}
-static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit)
+static int revwalk_enqueue_timesort(git_revwalk *walk, git_commit_list_node *commit)
{
return git_pqueue_insert(&walk->iterator_time, commit);
}
-static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit)
+static int revwalk_enqueue_unsorted(git_revwalk *walk, git_commit_list_node *commit)
{
- return commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
+ return git_commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
}
-static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
+static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk *walk)
{
int error;
- commit_object *next;
+ git_commit_list_node *next;
while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0)
@@ -688,12 +262,12 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
return GIT_ITEROVER;
}
-static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
+static int revwalk_next_unsorted(git_commit_list_node **object_out, git_revwalk *walk)
{
int error;
- commit_object *next;
+ git_commit_list_node *next;
- while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) {
+ while ((next = git_commit_list_pop(&walk->iterator_rand)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0)
return error;
@@ -707,13 +281,13 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
return GIT_ITEROVER;
}
-static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
+static int revwalk_next_toposort(git_commit_list_node **object_out, git_revwalk *walk)
{
- commit_object *next;
+ git_commit_list_node *next;
unsigned short i;
for (;;) {
- next = commit_list_pop(&walk->iterator_topo);
+ next = git_commit_list_pop(&walk->iterator_topo);
if (next == NULL) {
giterr_clear();
return GIT_ITEROVER;
@@ -725,11 +299,11 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
}
for (i = 0; i < next->out_degree; ++i) {
- commit_object *parent = next->parents[i];
+ git_commit_list_node *parent = next->parents[i];
if (--parent->in_degree == 0 && parent->topo_delay) {
parent->topo_delay = 0;
- if (commit_list_insert(parent, &walk->iterator_topo) == NULL)
+ if (git_commit_list_insert(parent, &walk->iterator_topo) == NULL)
return -1;
}
}
@@ -739,9 +313,9 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
}
}
-static int revwalk_next_reverse(commit_object **object_out, git_revwalk *walk)
+static int revwalk_next_reverse(git_commit_list_node **object_out, git_revwalk *walk)
{
- *object_out = commit_list_pop(&walk->iterator_reverse);
+ *object_out = git_commit_list_pop(&walk->iterator_reverse);
return *object_out ? 0 : GIT_ITEROVER;
}
@@ -750,8 +324,8 @@ static int prepare_walk(git_revwalk *walk)
{
int error;
unsigned int i;
- commit_object *next, *two;
- commit_list *bases = NULL;
+ git_commit_list_node *next, *two;
+ git_commit_list *bases = NULL;
/*
* If walk->one is NULL, there were no positive references,
@@ -763,10 +337,10 @@ static int prepare_walk(git_revwalk *walk)
}
/* first figure out what the merge bases are */
- if (merge_bases_many(&bases, walk, walk->one, &walk->twos) < 0)
+ if (git_merge__bases_many(&bases, walk, walk->one, &walk->twos) < 0)
return -1;
- commit_list_free(&bases);
+ git_commit_list_free(&bases);
if (process_commit(walk, walk->one, walk->one->uninteresting) < 0)
return -1;
@@ -780,11 +354,11 @@ static int prepare_walk(git_revwalk *walk)
while ((error = walk->get_next(&next, walk)) == 0) {
for (i = 0; i < next->out_degree; ++i) {
- commit_object *parent = next->parents[i];
+ git_commit_list_node *parent = next->parents[i];
parent->in_degree++;
}
- if (commit_list_insert(next, &walk->iterator_topo) == NULL)
+ if (git_commit_list_insert(next, &walk->iterator_topo) == NULL)
return -1;
}
@@ -797,7 +371,7 @@ static int prepare_walk(git_revwalk *walk)
if (walk->sorting & GIT_SORT_REVERSE) {
while ((error = walk->get_next(&next, walk)) == 0)
- if (commit_list_insert(next, &walk->iterator_reverse) == NULL)
+ if (git_commit_list_insert(next, &walk->iterator_reverse) == NULL)
return -1;
if (error != GIT_ITEROVER)
@@ -811,9 +385,6 @@ static int prepare_walk(git_revwalk *walk)
}
-
-
-
int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
{
git_revwalk *walk;
@@ -826,7 +397,7 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
walk->commits = git_oidmap_alloc();
GITERR_CHECK_ALLOC(walk->commits);
- if (git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp) < 0 ||
+ if (git_pqueue_init(&walk->iterator_time, 8, git_commit_list_time_cmp) < 0 ||
git_vector_init(&walk->twos, 4, NULL) < 0 ||
git_pool_init(&walk->commit_pool, 1,
git_pool__suggest_items_per_page(COMMIT_ALLOC) * COMMIT_ALLOC) < 0)
@@ -888,7 +459,7 @@ void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
int git_revwalk_next(git_oid *oid, git_revwalk *walk)
{
int error;
- commit_object *next;
+ git_commit_list_node *next;
assert(walk && oid);
@@ -913,7 +484,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
void git_revwalk_reset(git_revwalk *walk)
{
- commit_object *commit;
+ git_commit_list_node *commit;
assert(walk);
@@ -925,9 +496,9 @@ void git_revwalk_reset(git_revwalk *walk)
});
git_pqueue_clear(&walk->iterator_time);
- commit_list_free(&walk->iterator_topo);
- commit_list_free(&walk->iterator_rand);
- commit_list_free(&walk->iterator_reverse);
+ git_commit_list_free(&walk->iterator_topo);
+ git_commit_list_free(&walk->iterator_rand);
+ git_commit_list_free(&walk->iterator_reverse);
walk->walking = 0;
walk->one = NULL;
diff --git a/src/revwalk.h b/src/revwalk.h
new file mode 100644
index 000000000..2d482cfcc
--- /dev/null
+++ b/src/revwalk.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_revwalk_h__
+#define INCLUDE_revwalk_h__
+
+#include "git2/revwalk.h"
+#include "oidmap.h"
+#include "commit_list.h"
+#include "pqueue.h"
+#include "pool.h"
+#include "vector.h"
+
+GIT__USE_OIDMAP;
+
+struct git_revwalk {
+ git_repository *repo;
+ git_odb *odb;
+
+ git_oidmap *commits;
+ git_pool commit_pool;
+
+ git_commit_list *iterator_topo;
+ git_commit_list *iterator_rand;
+ git_commit_list *iterator_reverse;
+ git_pqueue iterator_time;
+
+ int (*get_next)(git_commit_list_node **, git_revwalk *);
+ int (*enqueue)(git_revwalk *, git_commit_list_node *);
+
+ unsigned walking:1;
+ unsigned int sorting;
+
+ /* merge base calculation */
+ git_commit_list_node *one;
+ git_vector twos;
+};
+
+git_commit_list_node *commit_lookup(git_revwalk *walk, const git_oid *oid);
+
+#endif
diff --git a/src/stash.c b/src/stash.c
index b74429aca..107cbe3ca 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -56,7 +56,7 @@ static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit)
static int append_commit_description(git_buf *out, git_commit* commit)
{
const char *message;
- int pos = 0, len;
+ size_t pos = 0, len;
if (append_abbreviated_oid(out, git_commit_id(commit)) < 0)
return -1;
@@ -98,7 +98,7 @@ static int retrieve_base_commit_and_message(
"%s: ",
git_reference_name(head) + strlen(GIT_REFS_HEADS_DIR));
- if (git_commit_lookup(b_commit, repo, git_reference_oid(head)) < 0)
+ if (git_commit_lookup(b_commit, repo, git_reference_target(head)) < 0)
goto cleanup;
if (append_commit_description(stash_message, *b_commit) < 0)
@@ -169,12 +169,12 @@ struct cb_data {
};
static int update_index_cb(
- void *cb_data,
const git_diff_delta *delta,
- float progress)
+ float progress,
+ void *payload)
{
int pos;
- struct cb_data *data = (struct cb_data *)cb_data;
+ struct cb_data *data = (struct cb_data *)payload;
GIT_UNUSED(progress);
@@ -253,7 +253,7 @@ static int build_untracked_tree(
if (git_diff_workdir_to_tree(&diff, git_index_owner(index), i_tree, &opts) < 0)
goto cleanup;
- if (git_diff_foreach(diff, &data, update_index_cb, NULL, NULL) < 0)
+ if (git_diff_foreach(diff, update_index_cb, NULL, NULL, &data) < 0)
goto cleanup;
if (build_tree_from_index(tree_out, index) < 0)
@@ -334,7 +334,7 @@ static int build_workdir_tree(
data.index = index;
data.include_changed = true;
- if (git_diff_foreach(diff, &data, update_index_cb, NULL, NULL) < 0)
+ if (git_diff_foreach(diff, update_index_cb, NULL, NULL, &data) < 0)
goto cleanup;
if (build_tree_from_index(tree_out, index) < 0)
@@ -436,7 +436,7 @@ static int update_reflog(
git_reflog *reflog = NULL;
int error;
- if ((error = git_reference_create_oid(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0)
+ if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0)
goto cleanup;
if ((error = git_reflog_read(&reflog, stash)) < 0)
@@ -579,7 +579,7 @@ cleanup:
int git_stash_foreach(
git_repository *repo,
- stash_cb callback,
+ git_stash_cb callback,
void *payload)
{
git_reference *stash;
@@ -603,8 +603,8 @@ int git_stash_foreach(
entry = git_reflog_entry_byindex(reflog, i);
if (callback(i,
- git_reflog_entry_msg(entry),
- git_reflog_entry_oidnew(entry),
+ git_reflog_entry_message(entry),
+ git_reflog_entry_id_new(entry),
payload)) {
error = GIT_EUSER;
goto cleanup;
diff --git a/src/status.c b/src/status.c
index b832cfe64..c7dea2c71 100644
--- a/src/status.c
+++ b/src/status.c
@@ -78,14 +78,14 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
}
typedef struct {
- int (*cb)(const char *, unsigned int, void *);
- void *cbdata;
+ git_status_cb cb;
+ void *payload;
} status_user_callback;
static int status_invoke_cb(
- void *cbref, git_diff_delta *i2h, git_diff_delta *w2i)
+ git_diff_delta *i2h, git_diff_delta *w2i, void *payload)
{
- status_user_callback *usercb = cbref;
+ status_user_callback *usercb = payload;
const char *path = NULL;
unsigned int status = 0;
@@ -98,14 +98,14 @@ static int status_invoke_cb(
status |= index_delta2status(i2h->status);
}
- return usercb->cb(path, status, usercb->cbdata);
+ return usercb->cb(path, status, usercb->payload);
}
int git_status_foreach_ext(
git_repository *repo,
const git_status_options *opts,
- int (*cb)(const char *, unsigned int, void *),
- void *cbdata)
+ git_status_cb cb,
+ void *payload)
{
int err = 0;
git_diff_options diffopt;
@@ -152,7 +152,7 @@ int git_status_foreach_ext(
goto cleanup;
usercb.cb = cb;
- usercb.cbdata = cbdata;
+ usercb.payload = payload;
if (show == GIT_STATUS_SHOW_INDEX_THEN_WORKDIR) {
if ((err = git_diff__paired_foreach(
@@ -178,7 +178,7 @@ cleanup:
int git_status_foreach(
git_repository *repo,
- int (*callback)(const char *, unsigned int, void *),
+ git_status_cb callback,
void *payload)
{
git_status_options opts;
diff --git a/src/submodule.c b/src/submodule.c
index 6eb1c52f7..b6e5c96f6 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -66,7 +66,7 @@ __KHASH_IMPL(
str_hash_no_trailing_slash, str_equal_no_trailing_slash);
static int load_submodule_config(git_repository *repo, bool force);
-static git_config_file *open_gitmodules(git_repository *, bool, const git_oid *);
+static git_config_backend *open_gitmodules(git_repository *, bool, const git_oid *);
static int lookup_head_remote(git_buf *url, git_repository *repo);
static int submodule_get(git_submodule **, git_repository *, const char *, const char *);
static void submodule_release(git_submodule *sm, int decr);
@@ -201,7 +201,7 @@ int git_submodule_add_setup(
int use_gitlink)
{
int error = 0;
- git_config_file *mods = NULL;
+ git_config_backend *mods = NULL;
git_submodule *sm;
git_buf name = GIT_BUF_INIT, real_url = GIT_BUF_INIT;
git_repository_init_options initopt;
@@ -412,7 +412,7 @@ cleanup:
int git_submodule_save(git_submodule *submodule)
{
int error = 0;
- git_config_file *mods;
+ git_config_backend *mods;
git_buf key = GIT_BUF_INIT;
assert(submodule);
@@ -513,7 +513,7 @@ int git_submodule_set_url(git_submodule *submodule, const char *url)
return 0;
}
-const git_oid *git_submodule_index_oid(git_submodule *submodule)
+const git_oid *git_submodule_index_id(git_submodule *submodule)
{
assert(submodule);
@@ -523,7 +523,7 @@ const git_oid *git_submodule_index_oid(git_submodule *submodule)
return NULL;
}
-const git_oid *git_submodule_head_oid(git_submodule *submodule)
+const git_oid *git_submodule_head_id(git_submodule *submodule)
{
assert(submodule);
@@ -533,7 +533,7 @@ const git_oid *git_submodule_head_oid(git_submodule *submodule)
return NULL;
}
-const git_oid *git_submodule_wd_oid(git_submodule *submodule)
+const git_oid *git_submodule_wd_id(git_submodule *submodule)
{
assert(submodule);
@@ -695,7 +695,7 @@ int git_submodule_open(
/* if we have opened the submodule successfully, let's grab the HEAD OID */
if (!error && !(submodule->flags & GIT_SUBMODULE_STATUS__WD_OID_VALID)) {
- if (!git_reference_name_to_oid(
+ if (!git_reference_name_to_id(
&submodule->wd_oid, *subrepo, GIT_HEAD_FILE))
submodule->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID;
else
@@ -717,7 +717,7 @@ int git_submodule_reload(git_submodule *submodule)
git_index *index;
int pos, error;
git_tree *head;
- git_config_file *mods;
+ git_config_backend *mods;
assert(submodule);
@@ -733,7 +733,7 @@ int git_submodule_reload(git_submodule *submodule)
pos = git_index_find(index, submodule->path);
if (pos >= 0) {
- git_index_entry *entry = git_index_get_byindex(index, pos);
+ const git_index_entry *entry = git_index_get_byindex(index, pos);
if (S_ISGITLINK(entry->mode)) {
if ((error = submodule_load_from_index(repo, entry)) < 0)
@@ -1187,14 +1187,14 @@ static int load_submodule_config_from_head(
return error;
}
-static git_config_file *open_gitmodules(
+static git_config_backend *open_gitmodules(
git_repository *repo,
bool okay_to_create,
const git_oid *gitmodules_oid)
{
const char *workdir = git_repository_workdir(repo);
git_buf path = GIT_BUF_INIT;
- git_config_file *mods = NULL;
+ git_config_backend *mods = NULL;
if (workdir != NULL) {
if (git_buf_joinpath(&path, workdir, GIT_MODULES_FILE) != 0)
@@ -1230,7 +1230,7 @@ static int load_submodule_config(git_repository *repo, bool force)
int error;
git_oid gitmodules_oid;
git_buf path = GIT_BUF_INIT;
- git_config_file *mods = NULL;
+ git_config_backend *mods = NULL;
if (repo->submodules && !force)
return 0;
@@ -1316,7 +1316,7 @@ static int lookup_head_remote(git_buf *url, git_repository *repo)
/* remote should refer to something like refs/remotes/ORIGIN/BRANCH */
if (git_reference_type(remote) != GIT_REF_SYMBOLIC ||
- git__prefixcmp(git_reference_target(remote), GIT_REFS_REMOTES_DIR) != 0)
+ git__prefixcmp(git_reference_symbolic_target(remote), GIT_REFS_REMOTES_DIR) != 0)
{
giterr_set(GITERR_SUBMODULE,
"Cannot resolve relative URL when HEAD is not symbolic");
@@ -1324,7 +1324,7 @@ static int lookup_head_remote(git_buf *url, git_repository *repo)
goto cleanup;
}
- scan = tgt = git_reference_target(remote) + strlen(GIT_REFS_REMOTES_DIR);
+ scan = tgt = git_reference_symbolic_target(remote) + strlen(GIT_REFS_REMOTES_DIR);
while (*scan && (*scan != '/' || (scan > tgt && scan[-1] != '\\')))
scan++; /* find non-escaped slash to end ORIGIN name */
@@ -1378,7 +1378,7 @@ static int submodule_update_config(
goto cleanup;
if (!value)
- error = git_config_delete(config, key.ptr);
+ error = git_config_delete_entry(config, key.ptr);
else
error = git_config_set_string(config, key.ptr, value);
@@ -1389,8 +1389,8 @@ cleanup:
static int submodule_index_status(unsigned int *status, git_submodule *sm)
{
- const git_oid *head_oid = git_submodule_head_oid(sm);
- const git_oid *index_oid = git_submodule_index_oid(sm);
+ const git_oid *head_oid = git_submodule_head_id(sm);
+ const git_oid *index_oid = git_submodule_index_id(sm);
if (!head_oid) {
if (index_oid)
@@ -1410,7 +1410,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
const git_oid *wd_oid, *index_oid;
git_repository *sm_repo = NULL;
- /* open repo now if we need it (so wd_oid() call won't reopen) */
+ /* open repo now if we need it (so wd_id() call won't reopen) */
if ((sm->ignore == GIT_SUBMODULE_IGNORE_NONE ||
sm->ignore == GIT_SUBMODULE_IGNORE_UNTRACKED) &&
(sm->flags & GIT_SUBMODULE_STATUS_IN_WD) != 0)
@@ -1419,8 +1419,8 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
return error;
}
- index_oid = git_submodule_index_oid(sm);
- wd_oid = git_submodule_wd_oid(sm);
+ index_oid = git_submodule_index_id(sm);
+ wd_oid = git_submodule_wd_id(sm);
if (!index_oid) {
if (wd_oid)
diff --git a/src/tag.c b/src/tag.c
index 13369d9fb..606afd657 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -22,41 +22,41 @@ void git_tag__free(git_tag *tag)
git__free(tag);
}
-const git_oid *git_tag_id(git_tag *c)
+const git_oid *git_tag_id(const git_tag *c)
{
- return git_object_id((git_object *)c);
+ return git_object_id((const git_object *)c);
}
-int git_tag_target(git_object **target, git_tag *t)
+int git_tag_target(git_object **target, const git_tag *t)
{
assert(t);
return git_object_lookup(target, t->object.repo, &t->target, t->type);
}
-const git_oid *git_tag_target_oid(git_tag *t)
+const git_oid *git_tag_target_id(const git_tag *t)
{
assert(t);
return &t->target;
}
-git_otype git_tag_target_type(git_tag *t)
+git_otype git_tag_target_type(const git_tag *t)
{
assert(t);
return t->type;
}
-const char *git_tag_name(git_tag *t)
+const char *git_tag_name(const git_tag *t)
{
assert(t);
return t->tag_name;
}
-const git_signature *git_tag_tagger(git_tag *t)
+const git_signature *git_tag_tagger(const git_tag *t)
{
return t->tagger;
}
-const char *git_tag_message(git_tag *t)
+const char *git_tag_message(const git_tag *t)
{
assert(t);
return t->message;
@@ -188,7 +188,7 @@ static int retrieve_tag_reference_oid(
if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0)
return -1;
- return git_reference_name_to_oid(oid, repo, ref_name_out->ptr);
+ return git_reference_name_to_id(oid, repo, ref_name_out->ptr);
}
static int write_tag_annotation(
@@ -267,7 +267,7 @@ static int git_tag_create__internal(
} else
git_oid_cpy(oid, git_object_id(target));
- error = git_reference_create_oid(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite);
+ error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite);
git_reference_free(new_ref);
git_buf_free(&ref_name);
@@ -358,7 +358,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
return -1;
}
- error = git_reference_create_oid(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite);
+ error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite);
git_reference_free(new_ref);
git_buf_free(&ref_name);
@@ -409,7 +409,7 @@ static int tags_cb(const char *ref, void *data)
if (git__prefixcmp(ref, GIT_REFS_TAGS_DIR) != 0)
return 0; /* no tag */
- if (git_reference_name_to_oid(&oid, d->repo, ref) < 0)
+ if (git_reference_name_to_id(&oid, d->repo, ref) < 0)
return -1;
return d->cb(ref, &oid, d->cb_data);
@@ -425,8 +425,8 @@ int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data)
data.cb_data = cb_data;
data.repo = repo;
- return git_reference_foreach(repo, GIT_REF_OID | GIT_REF_PACKED,
- &tags_cb, &data);
+ return git_reference_foreach(
+ repo, GIT_REF_OID | GIT_REF_PACKED, &tags_cb, &data);
}
typedef struct {
@@ -477,7 +477,7 @@ int git_tag_list(git_strarray *tag_names, git_repository *repo)
return git_tag_list_match(tag_names, "", repo);
}
-int git_tag_peel(git_object **tag_target, git_tag *tag)
+int git_tag_peel(git_object **tag_target, const git_tag *tag)
{
- return git_object_peel(tag_target, (git_object *)tag, GIT_OBJ_ANY);
+ return git_object_peel(tag_target, (const git_object *)tag, GIT_OBJ_ANY);
}
diff --git a/src/transports/cred.c b/src/transports/cred.c
index 55295372f..e137ca9ac 100644
--- a/src/transports/cred.c
+++ b/src/transports/cred.c
@@ -11,7 +11,7 @@
static void plaintext_free(struct git_cred *cred)
{
git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
- int pass_len = strlen(c->password);
+ size_t pass_len = strlen(c->password);
git__free(c->username);
@@ -19,6 +19,8 @@ static void plaintext_free(struct git_cred *cred)
memset(c->password, 0x0, pass_len);
git__free(c->password);
+ memset(c, 0, sizeof(*c));
+
git__free(c);
}
@@ -54,4 +56,4 @@ int git_cred_userpass_plaintext_new(
*cred = &c->parent;
return 0;
-} \ No newline at end of file
+}
diff --git a/src/transports/local.c b/src/transports/local.c
index 46c9218c7..51544416d 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -48,7 +48,7 @@ static int add_ref(transport_local *t, const char *name)
head->name = git__strdup(name);
GITERR_CHECK_ALLOC(head->name);
- if (git_reference_name_to_oid(&head->oid, t->repo, name) < 0) {
+ if (git_reference_name_to_id(&head->oid, t->repo, name) < 0) {
git__free(head->name);
git__free(head);
return -1;
@@ -306,7 +306,7 @@ static int local_download_pack(
if (git_odb_exists(odb, &oid)) continue;
if (!git_object_lookup((git_object**)&commit, t->repo, &oid, GIT_OBJ_COMMIT)) {
- const git_oid *tree_oid = git_commit_tree_oid(commit);
+ const git_oid *tree_oid = git_commit_tree_id(commit);
git_commit_free(commit);
/* Add the commit and its tree */
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 8f9715a3f..e8dbbef5c 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -24,7 +24,7 @@ static int git_smart__recv_cb(gitno_buffer *buf)
buf->offset += bytes_read;
if (t->packetsize_cb)
- t->packetsize_cb(bytes_read, t->packetsize_payload);
+ t->packetsize_cb((int)bytes_read, t->packetsize_payload);
return (int)(buf->offset - old_len);
}
@@ -73,7 +73,7 @@ static int git_smart__connect(
t->flags = flags;
t->cred_acquire_cb = cred_acquire_cb;
- if (GIT_DIR_FETCH == direction)
+ if (GIT_DIRECTION_FETCH == direction)
{
if ((error = t->wrapped->action(&stream, t->wrapped, t->url, GIT_SERVICE_UPLOADPACK_LS)) < 0)
return error;
@@ -159,7 +159,7 @@ int git_smart__negotiation_step(git_transport *transport, void *data, size_t len
if (t->rpc)
git_smart__reset_stream(t);
- if (GIT_DIR_FETCH == t->direction) {
+ if (GIT_DIRECTION_FETCH == t->direction) {
if ((error = t->wrapped->action(&stream, t->wrapped, t->url, GIT_SERVICE_UPLOADPACK)) < 0)
return error;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 046bc89a4..b37c4ba96 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -94,7 +94,7 @@ typedef struct transport_smart_caps {
include_tag:1;
} transport_smart_caps;
-typedef void (*packetsize_cb)(int received, void *payload);
+typedef void (*packetsize_cb)(size_t received, void *payload);
typedef struct {
git_transport parent;
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index e24eb2783..99d34e23b 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -188,7 +188,7 @@ static int fetch_setup_walk(git_revwalk **out, git_repository *repo)
if (git_reference_type(ref) == GIT_REF_SYMBOLIC)
continue;
- if (git_revwalk_push(walk, git_reference_oid(ref)) < 0)
+ if (git_revwalk_push(walk, git_reference_target(ref)) < 0)
goto on_error;
git_reference_free(ref);
@@ -367,7 +367,7 @@ static int no_sideband(transport_smart *t, struct git_odb_writepack *writepack,
return 0;
}
-struct network_packetsize_payload
+struct network_packetsize_payload
{
git_transfer_progress_callback callback;
void *payload;
@@ -375,7 +375,7 @@ struct network_packetsize_payload
size_t last_fired_bytes;
};
-static void network_packetsize(int received, void *payload)
+static void network_packetsize(size_t received, void *payload)
{
struct network_packetsize_payload *npp = (struct network_packetsize_payload*)payload;
@@ -384,8 +384,8 @@ static void network_packetsize(int received, void *payload)
/* Fire notification if the threshold is reached */
if ((npp->stats->received_bytes - npp->last_fired_bytes) > NETWORK_XFER_THRESHOLD) {
- npp->last_fired_bytes = npp->stats->received_bytes;
- npp->callback(npp->stats, npp->payload);
+ npp->last_fired_bytes = npp->stats->received_bytes;
+ npp->callback(npp->stats, npp->payload);
}
}
@@ -414,7 +414,7 @@ int git_smart__download_pack(
/* We might have something in the buffer already from negotiate_fetch */
if (t->buffer.offset > 0)
- t->packetsize_cb(t->buffer.offset, t->packetsize_payload);
+ t->packetsize_cb((int)t->buffer.offset, t->packetsize_payload);
}
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index df6cd87ec..f3abe8598 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -376,7 +376,7 @@ replay:
if (!WinHttpReadData(s->request,
(LPVOID)buffer,
- buf_size,
+ (DWORD)buf_size,
&dw_bytes_read))
{
giterr_set(GITERR_OS, "Failed to read data");
diff --git a/src/tree.c b/src/tree.c
index 6f9838880..b3f5c302d 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -98,11 +98,11 @@ static int homing_search_cmp(const void *key, const void *array_member)
* ambiguous because of folder vs file sorting, we look linearly
* around the area for our target file.
*/
-static int tree_key_search(git_vector *entries, const char *filename, size_t filename_len)
+static int tree_key_search(
+ git_vector *entries, const char *filename, size_t filename_len)
{
struct tree_key_search ksearch;
const git_tree_entry *entry;
-
int homing, i;
ksearch.filename = filename;
@@ -166,6 +166,7 @@ git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
return NULL;
memcpy(copy, entry, total_size);
+
return copy;
}
@@ -225,7 +226,8 @@ int git_tree_entry_to_object(
return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY);
}
-static git_tree_entry *entry_fromname(git_tree *tree, const char *name, size_t name_len)
+static const git_tree_entry *entry_fromname(
+ git_tree *tree, const char *name, size_t name_len)
{
int idx = tree_key_search(&tree->entries, name, name_len);
if (idx < 0)
@@ -234,22 +236,25 @@ static git_tree_entry *entry_fromname(git_tree *tree, const char *name, size_t n
return git_vector_get(&tree->entries, idx);
}
-const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename)
+const git_tree_entry *git_tree_entry_byname(
+ git_tree *tree, const char *filename)
{
assert(tree && filename);
return entry_fromname(tree, filename, strlen(filename));
}
-const git_tree_entry *git_tree_entry_byindex(git_tree *tree, size_t idx)
+const git_tree_entry *git_tree_entry_byindex(
+ git_tree *tree, size_t idx)
{
assert(tree);
return git_vector_get(&tree->entries, idx);
}
-const git_tree_entry *git_tree_entry_byoid(git_tree *tree, const git_oid *oid)
+const git_tree_entry *git_tree_entry_byoid(
+ const git_tree *tree, const git_oid *oid)
{
- unsigned int i;
- git_tree_entry *e;
+ size_t i;
+ const git_tree_entry *e;
assert(tree);
@@ -265,7 +270,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
{
git_vector *entries = &tree->entries;
struct tree_key_search ksearch;
- unsigned int at_pos;
+ size_t at_pos;
ksearch.filename = path;
ksearch.filename_len = strlen(path);
@@ -285,13 +290,13 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
break;
}
- return at_pos;
+ return (int)at_pos;
}
-unsigned int git_tree_entrycount(const git_tree *tree)
+size_t git_tree_entrycount(const git_tree *tree)
{
assert(tree);
- return (unsigned int)tree->entries.length;
+ return tree->entries.length;
}
static int tree_error(const char *str)
@@ -348,14 +353,13 @@ int git_tree__parse(git_tree *tree, git_odb_object *obj)
return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len);
}
-static unsigned int find_next_dir(const char *dirname, git_index *index, unsigned int start)
+static size_t find_next_dir(const char *dirname, git_index *index, size_t start)
{
- unsigned int i, entries = git_index_entrycount(index);
- size_t dirlen;
+ size_t dirlen, i, entries = git_index_entrycount(index);
dirlen = strlen(dirname);
for (i = start; i < entries; ++i) {
- git_index_entry *entry = git_index_get_byindex(index, i);
+ const git_index_entry *entry = git_index_get_byindex(index, i);
if (strlen(entry->path) < dirlen ||
memcmp(entry->path, dirname, dirlen) ||
(dirlen > 0 && entry->path[dirlen] != '/')) {
@@ -394,11 +398,10 @@ static int write_tree(
git_repository *repo,
git_index *index,
const char *dirname,
- unsigned int start)
+ size_t start)
{
git_treebuilder *bld = NULL;
-
- unsigned int i, entries = git_index_entrycount(index);
+ size_t i, entries = git_index_entrycount(index);
int error;
size_t dirname_len = strlen(dirname);
const git_tree_cache *cache;
@@ -406,13 +409,11 @@ static int write_tree(
cache = git_tree_cache_get(index->tree, dirname);
if (cache != NULL && cache->entries >= 0){
git_oid_cpy(oid, &cache->oid);
- return find_next_dir(dirname, index, start);
+ return (int)find_next_dir(dirname, index, start);
}
- error = git_treebuilder_create(&bld, NULL);
- if (bld == NULL) {
+ if ((error = git_treebuilder_create(&bld, NULL)) < 0 || bld == NULL)
return -1;
- }
/*
* This loop is unfortunate, but necessary. The index doesn't have
@@ -420,8 +421,8 @@ static int write_tree(
* need to keep track of the current position.
*/
for (i = start; i < entries; ++i) {
- git_index_entry *entry = git_index_get_byindex(index, i);
- char *filename, *next_slash;
+ const git_index_entry *entry = git_index_get_byindex(index, i);
+ const char *filename, *next_slash;
/*
* If we've left our (sub)tree, exit the loop and return. The
@@ -489,14 +490,15 @@ static int write_tree(
goto on_error;
git_treebuilder_free(bld);
- return i;
+ return (int)i;
on_error:
git_treebuilder_free(bld);
return -1;
}
-int git_tree__write_index(git_oid *oid, git_index *index, git_repository *repo)
+int git_tree__write_index(
+ git_oid *oid, git_index *index, git_repository *repo)
{
int ret;
@@ -694,7 +696,10 @@ on_error:
return -1;
}
-void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload)
+void git_treebuilder_filter(
+ git_treebuilder *bld,
+ git_treebuilder_filter_cb filter,
+ void *payload)
{
unsigned int i;
@@ -803,17 +808,17 @@ int git_tree_entry_bypath(
}
static int tree_walk(
- git_tree *tree,
+ const git_tree *tree,
git_treewalk_cb callback,
git_buf *path,
void *payload,
bool preorder)
{
int error = 0;
- unsigned int i;
+ size_t i;
for (i = 0; i < tree->entries.length; ++i) {
- git_tree_entry *entry = tree->entries.contents[i];
+ const git_tree_entry *entry = tree->entries.contents[i];
if (preorder) {
error = callback(path->ptr, entry, payload);
@@ -855,23 +860,27 @@ static int tree_walk(
return error;
}
-int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload)
+int git_tree_walk(
+ const git_tree *tree,
+ git_treewalk_mode mode,
+ git_treewalk_cb callback,
+ void *payload)
{
int error = 0;
git_buf root_path = GIT_BUF_INIT;
switch (mode) {
- case GIT_TREEWALK_POST:
- error = tree_walk(tree, callback, &root_path, payload, false);
- break;
+ case GIT_TREEWALK_POST:
+ error = tree_walk(tree, callback, &root_path, payload, false);
+ break;
- case GIT_TREEWALK_PRE:
- error = tree_walk(tree, callback, &root_path, payload, true);
- break;
+ case GIT_TREEWALK_PRE:
+ error = tree_walk(tree, callback, &root_path, payload, true);
+ break;
- default:
- giterr_set(GITERR_INVALID, "Invalid walking mode for tree walk");
- return -1;
+ default:
+ giterr_set(GITERR_INVALID, "Invalid walking mode for tree walk");
+ return -1;
}
git_buf_free(&root_path);
diff --git a/src/tree.h b/src/tree.h
index b67c55202..e0bcd6acf 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -51,7 +51,8 @@ int git_tree__prefix_position(git_tree *tree, const char *prefix);
/**
* Write a tree to the given repository
*/
-int git_tree__write_index(git_oid *oid, git_index *index, git_repository *repo);
+int git_tree__write_index(
+ git_oid *oid, git_index *index, git_repository *repo);
/**
* Obsolete mode kept for compatibility reasons
diff --git a/src/util.c b/src/util.c
index 3a08d4554..9813eb694 100644
--- a/src/util.c
+++ b/src/util.c
@@ -447,7 +447,7 @@ int git__bsearch(
/**
* A strcmp wrapper
- *
+ *
* We don't want direct pointers to the CRT on Windows, we may
* get stdcall conflicts.
*/
diff --git a/src/vector.c b/src/vector.c
index 4763792f5..5d3bc0887 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -9,14 +9,14 @@
#include "repository.h"
#include "vector.h"
-static const double resize_factor = 1.75;
-static const unsigned int minimum_size = 8;
+static const double git_vector_resize_factor = 1.75;
+static const size_t git_vector_minimum_size = 8;
static int resize_vector(git_vector *v)
{
- v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1;
- if (v->_alloc_size < minimum_size)
- v->_alloc_size = minimum_size;
+ v->_alloc_size = (size_t)(v->_alloc_size * git_vector_resize_factor) + 1;
+ if (v->_alloc_size < git_vector_minimum_size)
+ v->_alloc_size = git_vector_minimum_size;
v->contents = git__realloc(v->contents, v->_alloc_size * sizeof(void *));
GITERR_CHECK_ALLOC(v->contents);
@@ -24,7 +24,7 @@ static int resize_vector(git_vector *v)
return 0;
}
-int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp)
+int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
{
assert(v && src);
@@ -58,7 +58,7 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
memset(v, 0x0, sizeof(git_vector));
if (initial_size == 0)
- initial_size = minimum_size;
+ initial_size = git_vector_minimum_size;
v->_alloc_size = initial_size;
v->_cmp = cmp;
@@ -133,7 +133,7 @@ void git_vector_sort(git_vector *v)
}
int git_vector_bsearch3(
- unsigned int *at_pos,
+ size_t *at_pos,
git_vector *v,
git_vector_cmp key_lookup,
const void *key)
@@ -151,21 +151,21 @@ int git_vector_bsearch3(
rval = git__bsearch(v->contents, v->length, key, key_lookup, &pos);
if (at_pos != NULL)
- *at_pos = (unsigned int)pos;
+ *at_pos = pos;
return (rval >= 0) ? (int)pos : GIT_ENOTFOUND;
}
int git_vector_search2(
- git_vector *v, git_vector_cmp key_lookup, const void *key)
+ const git_vector *v, git_vector_cmp key_lookup, const void *key)
{
- unsigned int i;
+ size_t i;
assert(v && key && key_lookup);
for (i = 0; i < v->length; ++i) {
if (key_lookup(key, v->contents[i]) == 0)
- return i;
+ return (int)i;
}
return GIT_ENOTFOUND;
@@ -176,14 +176,14 @@ static int strict_comparison(const void *a, const void *b)
return (a == b) ? 0 : -1;
}
-int git_vector_search(git_vector *v, const void *entry)
+int git_vector_search(const git_vector *v, const void *entry)
{
return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry);
}
-int git_vector_remove(git_vector *v, unsigned int idx)
+int git_vector_remove(git_vector *v, size_t idx)
{
- unsigned int i;
+ size_t i;
assert(v);
@@ -206,7 +206,7 @@ void git_vector_pop(git_vector *v)
void git_vector_uniq(git_vector *v)
{
git_vector_cmp cmp;
- unsigned int i, j;
+ size_t i, j;
if (v->length <= 1)
return;
@@ -223,9 +223,10 @@ void git_vector_uniq(git_vector *v)
v->length -= j - i - 1;
}
-void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx))
+void git_vector_remove_matching(
+ git_vector *v, int (*match)(const git_vector *v, size_t idx))
{
- unsigned int i, j;
+ size_t i, j;
for (i = 0, j = 0; j < v->length; ++j) {
v->contents[i] = v->contents[j];
diff --git a/src/vector.h b/src/vector.h
index 6d820b8fc..15356ef16 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -24,23 +24,23 @@ typedef struct git_vector {
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
void git_vector_free(git_vector *v);
void git_vector_clear(git_vector *v);
-int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp);
+int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
void git_vector_swap(git_vector *a, git_vector *b);
void git_vector_sort(git_vector *v);
/** Linear search for matching entry using internal comparison function */
-int git_vector_search(git_vector *v, const void *entry);
+int git_vector_search(const git_vector *v, const void *entry);
/** Linear search for matching entry using explicit comparison function */
-int git_vector_search2(git_vector *v, git_vector_cmp cmp, const void *key);
+int git_vector_search2(const git_vector *v, git_vector_cmp cmp, const void *key);
/**
* Binary search for matching entry using explicit comparison function that
* returns position where item would go if not found.
*/
int git_vector_bsearch3(
- unsigned int *at_pos, git_vector *v, git_vector_cmp cmp, const void *key);
+ size_t *at_pos, git_vector *v, git_vector_cmp cmp, const void *key);
/** Binary search for matching entry using internal comparison function */
GIT_INLINE(int) git_vector_bsearch(git_vector *v, const void *key)
@@ -55,19 +55,14 @@ GIT_INLINE(int) git_vector_bsearch2(
return git_vector_bsearch3(NULL, v, cmp, key);
}
-GIT_INLINE(void *) git_vector_get(git_vector *v, size_t position)
-{
- return (position < v->length) ? v->contents[position] : NULL;
-}
-
-GIT_INLINE(const void *) git_vector_get_const(const git_vector *v, size_t position)
+GIT_INLINE(void *) git_vector_get(const git_vector *v, size_t position)
{
return (position < v->length) ? v->contents[position] : NULL;
}
#define GIT_VECTOR_GET(V,I) ((I) < (V)->length ? (V)->contents[(I)] : NULL)
-GIT_INLINE(void *) git_vector_last(git_vector *v)
+GIT_INLINE(void *) git_vector_last(const git_vector *v)
{
return (v->length > 0) ? git_vector_get(v, v->length - 1) : NULL;
}
@@ -81,10 +76,11 @@ GIT_INLINE(void *) git_vector_last(git_vector *v)
int git_vector_insert(git_vector *v, void *element);
int git_vector_insert_sorted(git_vector *v, void *element,
int (*on_dup)(void **old, void *new));
-int git_vector_remove(git_vector *v, unsigned int idx);
+int git_vector_remove(git_vector *v, size_t idx);
void git_vector_pop(git_vector *v);
void git_vector_uniq(git_vector *v);
-void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx));
+void git_vector_remove_matching(
+ git_vector *v, int (*match)(const git_vector *v, size_t idx));
int git_vector_resize_to(git_vector *v, size_t new_length);
int git_vector_set(void **old, git_vector *v, size_t position, void *value);
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 0efcaf597..3a4398bbd 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -520,24 +520,24 @@ int p_inet_pton(int af, const char* src, void* dst)
struct sockaddr_in6 sin6;
struct sockaddr_in sin;
} sa;
- size_t srcsize;
+ int srcsize;
switch(af)
{
case AF_INET:
sa.sin.sin_family = AF_INET;
- srcsize = sizeof (sa.sin);
+ srcsize = (int)sizeof(sa.sin);
break;
case AF_INET6:
sa.sin6.sin6_family = AF_INET6;
- srcsize = sizeof (sa.sin6);
+ srcsize = (int)sizeof(sa.sin6);
break;
default:
errno = WSAEPFNOSUPPORT;
return -1;
}
- if (WSAStringToAddress(src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0)
+ if (WSAStringToAddress((LPSTR)src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0)
{
errno = WSAGetLastError();
return -1;