Merge pull request #234 from Romain-Geissler/entry-count-API-uniformisation [Tree | Index] API uniformisation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
diff --git a/include/git2/index.h b/include/git2/index.h
index fa1cade..83a18e1 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -257,7 +257,7 @@ GIT_EXTERN(int) git_index_remove(git_index *index, int position);
* @param n the position of the entry
* @return a pointer to the entry; NULL if out of bounds
*/
-GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n);
+GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, unsigned int n);
/**
* Get the count of entries currently in the index
@@ -285,7 +285,19 @@ GIT_EXTERN(unsigned int) git_index_entrycount_unmerged(git_index *index);
* @param path path to search
* @return the unmerged entry; NULL if not found
*/
-GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged(git_index *index, const char *path);
+GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_bypath(git_index *index, const char *path);
+
+/**
+ * Get an unmerged entry from the index.
+ *
+ * The returned entry is read-only and should not be modified
+ * of freed by the caller.
+ *
+ * @param index an existing index object
+ * @param n the position of the entry
+ * @return a pointer to the unmerged entry; NULL if out of bounds
+ */
+GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_index *index, unsigned int n);
/**
* Return the stage number from a git index entry
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 0caf60a..2a4522b 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -84,7 +84,7 @@ GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree);
* @param tree a previously loaded tree.
* @return the number of entries in the tree
*/
-GIT_EXTERN(size_t) git_tree_entrycount(git_tree *tree);
+GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree);
/**
* Lookup a tree entry by its filename
@@ -102,7 +102,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname(git_tree *tree, const c
* @param idx the position in the entry list
* @return the tree entry; NULL if not found
*/
-GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(git_tree *tree, int idx);
+GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(git_tree *tree, unsigned int idx);
/**
* Get the UNIX file attributes of a tree entry
diff --git a/src/index.c b/src/index.c
index c86d37a..e25c899 100644
--- a/src/index.c
+++ b/src/index.c
@@ -322,11 +322,11 @@ unsigned int git_index_entrycount_unmerged(git_index *index)
return index->unmerged.length;
}
-git_index_entry *git_index_get(git_index *index, int n)
+git_index_entry *git_index_get(git_index *index, unsigned int n)
{
assert(index);
sort_index(index);
- return git_vector_get(&index->entries, (unsigned int)n);
+ return git_vector_get(&index->entries, n);
}
static void sort_index(git_index *index)
@@ -479,7 +479,7 @@ int git_index_find(git_index *index, const char *path)
return git_vector_bsearch2(&index->entries, index_srch, path);
}
-const git_index_entry_unmerged *git_index_get_unmerged(git_index *index, const char *path)
+const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index, const char *path)
{
int pos;
assert(index && path);
@@ -493,6 +493,12 @@ const git_index_entry_unmerged *git_index_get_unmerged(git_index *index, const c
return git_vector_get(&index->unmerged, pos);
}
+const git_index_entry_unmerged *git_index_get_unmerged_byindex(git_index *index, unsigned int n)
+{
+ assert(index);
+ return git_vector_get(&index->unmerged, n);
+}
+
static int read_tree_internal(git_index_tree **out,
const char **buffer_in, const char *buffer_end, git_index_tree *parent)
diff --git a/src/tree.c b/src/tree.c
index 60413e2..9d26b8c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -119,13 +119,13 @@ const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename
return git_vector_get(&tree->entries, idx);
}
-const git_tree_entry *git_tree_entry_byindex(git_tree *tree, int idx)
+const git_tree_entry *git_tree_entry_byindex(git_tree *tree, unsigned int idx)
{
assert(tree);
- return git_vector_get(&tree->entries, (unsigned int)idx);
+ return git_vector_get(&tree->entries, idx);
}
-size_t git_tree_entrycount(git_tree *tree)
+unsigned int git_tree_entrycount(git_tree *tree)
{
assert(tree);
return tree->entries.length;
@@ -288,7 +288,7 @@ static void sort_entries(git_treebuilder *bld)
int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source)
{
git_treebuilder *bld;
- size_t i, source_entries = DEFAULT_TREE_SIZE;
+ unsigned int i, source_entries = DEFAULT_TREE_SIZE;
assert(builder_p);
@@ -409,7 +409,7 @@ int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld)
{
- size_t i, size = 0;
+ unsigned int i, size = 0;
char filemode[MAX_FILEMODE_BYTES + 1 + 1];
git_odb_stream *stream;
int error;
@@ -443,7 +443,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b
stream->write(stream, filemode, strlen(filemode));
stream->write(stream, entry->filename, entry->filename_len + 1);
stream->write(stream, (char *)entry->oid.id, GIT_OID_RAWSZ);
- }
+ }
error = stream->finalize_write(oid, stream);
stream->free(stream);
@@ -453,7 +453,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b
void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload)
{
- size_t i;
+ unsigned int i;
assert(bld && filter);
@@ -466,7 +466,7 @@ void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_e
void git_treebuilder_clear(git_treebuilder *bld)
{
- size_t i;
+ unsigned int i;
assert(bld);
for (i = 0; i < bld->entries.length; ++i) {