summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2012-11-20 19:57:46 -0700
committerBen Straub <bs@github.com>2012-11-27 13:18:28 -0800
commitf45d51ff8e04c6849413c13aedcf5abacc3c69bd (patch)
treedab9495e4954677f12475d8335cd2ea9e752f24e
parentd9023dbe0cb5d47e30d86149701b7be9006f7683 (diff)
downloadlibgit2-f45d51ff8e04c6849413c13aedcf5abacc3c69bd.tar.gz
API updates for index.h
-rw-r--r--examples/general.c2
-rw-r--r--include/git2/index.h77
-rw-r--r--include/git2/tree.h2
-rw-r--r--src/attr.c2
-rw-r--r--src/index.c8
-rw-r--r--src/iterator.c2
-rw-r--r--src/submodule.c2
-rw-r--r--src/tree.c8
-rw-r--r--tests-clar/attr/repo.c2
-rw-r--r--tests-clar/index/conflicts.c6
-rw-r--r--tests-clar/index/filemodes.c4
-rw-r--r--tests-clar/index/rename.c2
-rw-r--r--tests-clar/index/stage.c4
-rw-r--r--tests-clar/index/tests.c2
-rw-r--r--tests-clar/object/commit/commitstagedfile.c2
15 files changed, 63 insertions, 62 deletions
diff --git a/examples/general.c b/examples/general.c
index d9bb6c04d..9ea264ec6 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -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);
diff --git a/include/git2/index.h b/include/git2/index.h
index 8e1a7e521..195e5b13f 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -21,10 +21,10 @@
*/
GIT_BEGIN_DECL
-#define GIT_IDXENTRY_NAMEMASK (0x0fff)
+#define GIT_IDXENTRY_NAMEMASK (0x0fff)
#define GIT_IDXENTRY_STAGEMASK (0x3000)
-#define GIT_IDXENTRY_EXTENDED (0x4000)
-#define GIT_IDXENTRY_VALID (0x8000)
+#define GIT_IDXENTRY_EXTENDED (0x4000)
+#define GIT_IDXENTRY_VALID (0x8000)
#define GIT_IDXENTRY_STAGESHIFT 12
/*
@@ -34,26 +34,26 @@ GIT_BEGIN_DECL
*
* In-memory only flags:
*/
-#define GIT_IDXENTRY_UPDATE (1 << 0)
-#define GIT_IDXENTRY_REMOVE (1 << 1)
-#define GIT_IDXENTRY_UPTODATE (1 << 2)
-#define GIT_IDXENTRY_ADDED (1 << 3)
+#define GIT_IDXENTRY_UPDATE (1 << 0)
+#define GIT_IDXENTRY_REMOVE (1 << 1)
+#define GIT_IDXENTRY_UPTODATE (1 << 2)
+#define GIT_IDXENTRY_ADDED (1 << 3)
-#define GIT_IDXENTRY_HASHED (1 << 4)
-#define GIT_IDXENTRY_UNHASHED (1 << 5)
-#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */
-#define GIT_IDXENTRY_CONFLICTED (1 << 7)
+#define GIT_IDXENTRY_HASHED (1 << 4)
+#define GIT_IDXENTRY_UNHASHED (1 << 5)
+#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */
+#define GIT_IDXENTRY_CONFLICTED (1 << 7)
-#define GIT_IDXENTRY_UNPACKED (1 << 8)
+#define GIT_IDXENTRY_UNPACKED (1 << 8)
#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
/*
* Extended on-disk flags:
*/
-#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13)
-#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14)
+#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13)
+#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14)
/* GIT_IDXENTRY_EXTENDED2 is for future extension */
-#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
+#define GIT_IDXENTRY_EXTENDED2 (1 << 15)
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
@@ -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);
/**@}*/
diff --git a/include/git2/tree.h b/include/git2/tree.h
index d20141052..0104ba144 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -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);
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/index.c b/src/index.c
index 971fec9fa..fb0061cea 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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);
diff --git a/src/iterator.c b/src/iterator.c
index ec3c08ee7..469913d3b 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -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 &&
diff --git a/src/submodule.c b/src/submodule.c
index bc38f1f24..b6e5c96f6 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -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)
diff --git a/src/tree.c b/src/tree.c
index 252980182..6692263c5 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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)
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index b51d5e335..1d2b1e8df 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -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));
diff --git a/tests-clar/index/conflicts.c b/tests-clar/index/conflicts.c
index 91ff926e5..790e06717 100644
--- a/tests-clar/index/conflicts.c
+++ b/tests-clar/index/conflicts.c
@@ -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);
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 882d41748..a2d5df605 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -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));
diff --git a/tests-clar/index/rename.c b/tests-clar/index/rename.c
index e16ec00c1..adbbcfaac 100644
--- a/tests-clar/index/rename.c
+++ b/tests-clar/index/rename.c
@@ -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);
diff --git a/tests-clar/index/stage.c b/tests-clar/index/stage.c
index 9c9d29660..0f3b29832 100644
--- a/tests-clar/index/stage.c
+++ b/tests-clar/index/stage.c
@@ -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);
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 3b71b704d..4d613d693 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -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 */
diff --git a/tests-clar/object/commit/commitstagedfile.c b/tests-clar/object/commit/commitstagedfile.c
index 6dc536e3a..55c70d98e 100644
--- a/tests-clar/object/commit/commitstagedfile.c
+++ b/tests-clar/object/commit/commitstagedfile.c
@@ -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;