Commit f45d51ff by Ben Straub

API updates for index.h

parent d9023dbe
......@@ -371,7 +371,7 @@ int main (int argc, char** argv)
// All these properties are exported publicly in the `git_index_entry` struct
ecount = git_index_entrycount(index);
for (i = 0; i < ecount; ++i) {
git_index_entry *e = git_index_get_byindex(index, i);
const git_index_entry *e = git_index_get_byindex(index, i);
printf("path: %s\n", e->path);
printf("mtime: %d\n", (int)e->mtime.seconds);
......
......@@ -119,11 +119,11 @@ enum {
*
* The index must be freed once it's no longer in use.
*
* @param index the pointer for the new index
* @param out the pointer for the new index
* @param index_path the path to the index file in disk
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
/**
* Create an in-memory index object.
......@@ -133,10 +133,10 @@ GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
*
* The index must be freed once it's no longer in use.
*
* @param index the pointer for the new index
* @param out the pointer for the new index
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_new(git_index **index);
GIT_EXTERN(int) git_index_new(git_index **out);
/**
* Free an existing index object.
......@@ -201,7 +201,7 @@ GIT_EXTERN(int) git_index_write(git_index *index);
* @param tree tree to read
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
/**
* Write the index as a tree
......@@ -217,12 +217,12 @@ GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
*
* The index must not contain any file in conflict.
*
* @param oid Pointer where to store the OID of the written tree
* @param out Pointer where to store the OID of the written tree
* @param index Index to write
* @return 0 on success, GIT_EUNMERGED when the index is not clean
* or an error code
*/
GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
/**
* Write the index as a tree to the given repository
......@@ -233,13 +233,13 @@ GIT_EXTERN(int) git_index_write_tree(git_oid *oid, git_index *index);
*
* The index must not contain any file in conflict.
*
* @param oid Pointer where to store OID of the the written tree
* @param out Pointer where to store OID of the the written tree
* @param index Index to write
* @param repo Repository where to write the tree
* @return 0 on success, GIT_EUNMERGED when the index is not clean
* or an error code
*/
GIT_EXTERN(int) git_index_write_tree_to(git_oid *oid, git_index *index, git_repository *repo);
GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
/**@}*/
......@@ -282,7 +282,7 @@ GIT_EXTERN(void) git_index_clear(git_index *index);
* @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_byindex(git_index *index, size_t n);
GIT_EXTERN(const git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
/**
* Get a pointer to one of the entries in the index
......@@ -298,7 +298,7 @@ GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
* @param stage stage to search
* @return a pointer to the entry; NULL if it was not found
*/
GIT_EXTERN(git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
GIT_EXTERN(const git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
/**
* Remove an entry from the index
......@@ -402,7 +402,8 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
* @param their_entry the entry data for their side of the merge conflict
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_conflict_add(git_index *index,
GIT_EXTERN(int) git_index_conflict_add(
git_index *index,
const git_index_entry *ancestor_entry,
const git_index_entry *our_entry,
const git_index_entry *their_entry);
......@@ -475,7 +476,7 @@ GIT_EXTERN(int) git_index_reuc_find(git_index *index, const char *path);
* Get a resolve undo entry from the index.
*
* The returned entry is read-only and should not be modified
* of freed by the caller.
* or freed by the caller.
*
* @param index an existing index object
* @param path path to search
......@@ -487,7 +488,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
* Get a resolve undo entry from the index.
*
* The returned entry is read-only and should not be modified
* of freed by the caller.
* or freed by the caller.
*
* @param index an existing index object
* @param n the position of the entry
......@@ -496,7 +497,7 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *in
GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
/**
* Adds an resolve undo entry for a file based on the given parameters.
* Adds a resolve undo entry for a file based on the given parameters.
*
* The resolve undo entry contains the OIDs of files that were involved
* in a merge conflict after the conflict has been resolved. This allows
......@@ -510,26 +511,26 @@ GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *i
* @param index an existing index object
* @param path filename to add
* @param ancestor_mode mode of the ancestor file
* @param ancestor_oid oid of the ancestor file
* @param ancestor_id oid of the ancestor file
* @param our_mode mode of our file
* @param our_oid oid of our file
* @param our_id oid of our file
* @param their_mode mode of their file
* @param their_oid oid of their file
* @param their_id oid of their file
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
int ancestor_mode, git_oid *ancestor_oid,
int our_mode, git_oid *our_oid,
int their_mode, git_oid *their_oid);
int ancestor_mode, git_oid *ancestor_id,
int our_mode, git_oid *our_id,
int their_mode, git_oid *their_id);
/**
* Remove an resolve undo entry from the index
*
* @param index an existing index object
* @param position position of the resolve undo entry to remove
* @param n position of the resolve undo entry to remove
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, int position);
GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
/**@}*/
......
......@@ -371,7 +371,7 @@ typedef enum {
* @return 0 or an error code
*/
GIT_EXTERN(int) git_tree_walk(
git_tree *tree,
const git_tree *tree,
git_treewalk_mode mode,
git_treewalk_cb callback,
void *payload);
......
......@@ -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)
......
......@@ -494,14 +494,14 @@ unsigned int git_index_entrycount(git_index *index)
return (unsigned int)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;
......@@ -1072,7 +1072,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;
......@@ -1599,7 +1599,7 @@ 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);
......
......@@ -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 &&
......
......@@ -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)
......
......@@ -356,7 +356,7 @@ static unsigned int find_next_dir(const char *dirname, git_index *index, unsigne
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] != '/')) {
......@@ -421,7 +421,7 @@ 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);
const git_index_entry *entry = git_index_get_byindex(index, i);
char *filename, *next_slash;
/*
......@@ -807,7 +807,7 @@ 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,
......@@ -860,7 +860,7 @@ static int tree_walk(
}
int git_tree_walk(
git_tree *tree,
const git_tree *tree,
git_treewalk_mode mode,
git_treewalk_cb callback,
void *payload)
......
......@@ -267,7 +267,7 @@ static void add_to_workdir(const char *filename, const char *content)
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha)
{
int index_pos;
git_index_entry *entry;
const git_index_entry *entry;
add_to_workdir(filename, CONTENT);
cl_git_pass(git_index_add_from_workdir(index, filename));
......
......@@ -132,7 +132,7 @@ void test_index_conflicts__get(void)
void test_index_conflicts__remove(void)
{
git_index_entry *entry;
const git_index_entry *entry;
size_t i;
cl_assert(git_index_entrycount(repo_index) == 8);
......@@ -156,7 +156,7 @@ void test_index_conflicts__remove(void)
void test_index_conflicts__moved_to_reuc(void)
{
git_index_entry *entry;
const git_index_entry *entry;
size_t i;
cl_assert(git_index_entrycount(repo_index) == 8);
......@@ -178,7 +178,7 @@ void test_index_conflicts__moved_to_reuc(void)
void test_index_conflicts__remove_all_conflicts(void)
{
size_t i;
git_index_entry *entry;
const git_index_entry *entry;
cl_assert(git_index_entrycount(repo_index) == 8);
......
......@@ -25,7 +25,7 @@ void test_index_filemodes__read(void)
cl_assert_equal_i(6, git_index_entrycount(index));
for (i = 0; i < 6; ++i) {
git_index_entry *entry = git_index_get_byindex(index, i);
const git_index_entry *entry = git_index_get_byindex(index, i);
cl_assert(entry != NULL);
cl_assert(((entry->mode & 0100) ? 1 : 0) == expected[i]);
}
......@@ -54,7 +54,7 @@ static void add_and_check_mode(
git_index *index, const char *filename, unsigned int expect_mode)
{
int pos;
git_index_entry *entry;
const git_index_entry *entry;
cl_git_pass(git_index_add_from_workdir(index, filename));
......
......@@ -7,7 +7,7 @@ void test_index_rename__single_file(void)
git_index *index;
int position;
git_oid expected;
git_index_entry *entry;
const git_index_entry *entry;
p_mkdir("rename", 0700);
......
......@@ -27,7 +27,7 @@ void test_index_stage__cleanup(void)
void test_index_stage__add_always_adds_stage_0(void)
{
int entry_idx;
git_index_entry *entry;
const git_index_entry *entry;
cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
......@@ -41,7 +41,7 @@ void test_index_stage__add_always_adds_stage_0(void)
void test_index_stage__find_gets_first_stage(void)
{
int entry_idx;
git_index_entry *entry;
const git_index_entry *entry;
cl_assert((entry_idx = git_index_find(repo_index, "one.txt")) >= 0);
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
......
......@@ -208,7 +208,7 @@ void test_index_tests__add(void)
git_index *index;
git_filebuf file = GIT_FILEBUF_INIT;
git_repository *repo;
git_index_entry *entry;
const git_index_entry *entry;
git_oid id1;
/* Intialize a new repository */
......
......@@ -21,7 +21,7 @@ void test_object_commit_commitstagedfile__cleanup(void)
void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
{
git_index *index;
git_index_entry *entry;
const git_index_entry *entry;
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature;
git_tree *tree;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment