summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c71
1 files changed, 37 insertions, 34 deletions
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)