repository 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 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
diff --git a/include/git2/sys/repository.h b/include/git2/sys/repository.h
index ea2773f..892be66 100644
--- a/include/git2/sys/repository.h
+++ b/include/git2/sys/repository.h
@@ -44,8 +44,11 @@ GIT_EXTERN(int) git_repository_new(git_repository **out);
* trying to aggressively cleanup the repo before its
* deallocation. `git_repository_free` already performs this operation
* before deallocating the repo.
+ *
+ * @param repo The repository to clean up
+ * @return 0 on success, or an error code
*/
-GIT_EXTERN(void) git_repository__cleanup(git_repository *repo);
+GIT_EXTERN(int) git_repository__cleanup(git_repository *repo);
/**
* Update the filesystem config settings for an open repository
@@ -78,8 +81,9 @@ GIT_EXTERN(int) git_repository_reinit_filesystem(
*
* @param repo A repository object
* @param config A Config object
+ * @return 0 on success, or an error code
*/
-GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
+GIT_EXTERN(int) git_repository_set_config(git_repository *repo, git_config *config);
/**
* Set the Object Database for this repository
@@ -93,8 +97,9 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
*
* @param repo A repository object
* @param odb An ODB object
+ * @return 0 on success, or an error code
*/
-GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
+GIT_EXTERN(int) git_repository_set_odb(git_repository *repo, git_odb *odb);
/**
* Set the Reference Database Backend for this repository
@@ -108,8 +113,9 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
*
* @param repo A repository object
* @param refdb An refdb object
+ * @return 0 on success, or an error code
*/
-GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
+GIT_EXTERN(int) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
/**
* Set the index file for this repository
@@ -123,8 +129,9 @@ GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb
*
* @param repo A repository object
* @param index An index object
+ * @return 0 on success, or an error code
*/
-GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
+GIT_EXTERN(int) git_repository_set_index(git_repository *repo, git_index *index);
/**
* Set a repository to be bare.
diff --git a/src/repository.c b/src/repository.c
index 03f6820..2469e13 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -138,7 +138,7 @@ static void set_index(git_repository *repo, git_index *index)
}
}
-void git_repository__cleanup(git_repository *repo)
+int git_repository__cleanup(git_repository *repo)
{
assert(repo);
@@ -150,6 +150,8 @@ void git_repository__cleanup(git_repository *repo)
set_index(repo, NULL);
set_odb(repo, NULL);
set_refdb(repo, NULL);
+
+ return 0;
}
void git_repository_free(git_repository *repo)
@@ -1070,10 +1072,11 @@ int git_repository_config_snapshot(git_config **out, git_repository *repo)
return git_config_snapshot(out, weak);
}
-void git_repository_set_config(git_repository *repo, git_config *config)
+int git_repository_set_config(git_repository *repo, git_config *config)
{
assert(repo && config);
set_config(repo, config);
+ return 0;
}
int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
@@ -1121,10 +1124,11 @@ int git_repository_odb(git_odb **out, git_repository *repo)
return 0;
}
-void git_repository_set_odb(git_repository *repo, git_odb *odb)
+int git_repository_set_odb(git_repository *repo, git_odb *odb)
{
assert(repo && odb);
set_odb(repo, odb);
+ return 0;
}
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
@@ -1161,10 +1165,11 @@ int git_repository_refdb(git_refdb **out, git_repository *repo)
return 0;
}
-void git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
+int git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
{
assert(repo && refdb);
set_refdb(repo, refdb);
+ return 0;
}
int git_repository_index__weakptr(git_index **out, git_repository *repo)
@@ -1210,10 +1215,11 @@ int git_repository_index(git_index **out, git_repository *repo)
return 0;
}
-void git_repository_set_index(git_repository *repo, git_index *index)
+int git_repository_set_index(git_repository *repo, git_index *index)
{
assert(repo);
set_index(repo, index);
+ return 0;
}
int git_repository_set_namespace(git_repository *repo, const char *namespace)