index functions: return an int Stop returning a void for functions, future-proofing them to allow them to fail.
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
diff --git a/include/git2/sys/index.h b/include/git2/sys/index.h
index f1900df..1f6d93f 100644
--- a/include/git2/sys/index.h
+++ b/include/git2/sys/index.h
@@ -75,8 +75,9 @@ GIT_EXTERN(int) git_index_name_add(git_index *index,
* Remove all filename conflict entries.
*
* @param index an existing index object
+ * @return 0 or an error code
*/
-GIT_EXTERN(void) git_index_name_clear(git_index *index);
+GIT_EXTERN(int) git_index_name_clear(git_index *index);
/**@}*/
@@ -170,8 +171,9 @@ GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
* Remove all resolve undo entries from the index
*
* @param index an existing index object
+ * @return 0 or an error code
*/
-GIT_EXTERN(void) git_index_reuc_clear(git_index *index);
+GIT_EXTERN(int) git_index_reuc_clear(git_index *index);
/**@}*/
diff --git a/src/index.c b/src/index.c
index e2a8c7b..907bd6d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -539,13 +539,19 @@ int git_index_clear(git_index *index)
git_idxmap_clear(index->entries_map);
while (!error && index->entries.length > 0)
error = index_remove_entry(index, index->entries.length - 1);
+
+ if (error)
+ goto done;
+
index_free_deleted(index);
- git_index_reuc_clear(index);
- git_index_name_clear(index);
+ if ((error = git_index_name_clear(index)) < 0 ||
+ (error = git_index_reuc_clear(index)) < 0)
+ goto done;
git_futils_filestamp_set(&index->stamp, NULL);
+done:
return error;
}
@@ -2136,7 +2142,7 @@ int git_index_name_add(git_index *index,
return 0;
}
-void git_index_name_clear(git_index *index)
+int git_index_name_clear(git_index *index)
{
size_t i;
git_index_name_entry *conflict_name;
@@ -2149,6 +2155,8 @@ void git_index_name_clear(git_index *index)
git_vector_clear(&index->names);
index->dirty = 1;
+
+ return 0;
}
size_t git_index_reuc_entrycount(git_index *index)
@@ -2245,7 +2253,7 @@ int git_index_reuc_remove(git_index *index, size_t position)
return error;
}
-void git_index_reuc_clear(git_index *index)
+int git_index_reuc_clear(git_index *index)
{
size_t i;
@@ -2257,6 +2265,8 @@ void git_index_reuc_clear(git_index *index)
git_vector_clear(&index->reuc);
index->dirty = 1;
+
+ return 0;
}
static int index_error_invalid(const char *message)
@@ -3277,8 +3287,9 @@ static int git_index_read_iterator(
}
}
- git_index_name_clear(index);
- git_index_reuc_clear(index);
+ if ((error = git_index_name_clear(index)) < 0 ||
+ (error = git_index_reuc_clear(index)) < 0)
+ goto done;
git_vector_swap(&new_entries, &index->entries);
new_entries_map = git__swap(index->entries_map, new_entries_map);