Skip to content

Commit a3126a7

Browse files
committed
repository functions: return an int
Stop returning a void for functions, future-proofing them to allow them to fail.
1 parent cb43274 commit a3126a7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

include/git2/sys/repository.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ GIT_EXTERN(int) git_repository_new(git_repository **out);
4444
* trying to aggressively cleanup the repo before its
4545
* deallocation. `git_repository_free` already performs this operation
4646
* before deallocating the repo.
47+
*
48+
* @param repo The repository to clean up
49+
* @return 0 on success, or an error code
4750
*/
48-
GIT_EXTERN(void) git_repository__cleanup(git_repository *repo);
51+
GIT_EXTERN(int) git_repository__cleanup(git_repository *repo);
4952

5053
/**
5154
* Update the filesystem config settings for an open repository
@@ -78,8 +81,9 @@ GIT_EXTERN(int) git_repository_reinit_filesystem(
7881
*
7982
* @param repo A repository object
8083
* @param config A Config object
84+
* @return 0 on success, or an error code
8185
*/
82-
GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
86+
GIT_EXTERN(int) git_repository_set_config(git_repository *repo, git_config *config);
8387

8488
/**
8589
* Set the Object Database for this repository
@@ -93,8 +97,9 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
9397
*
9498
* @param repo A repository object
9599
* @param odb An ODB object
100+
* @return 0 on success, or an error code
96101
*/
97-
GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
102+
GIT_EXTERN(int) git_repository_set_odb(git_repository *repo, git_odb *odb);
98103

99104
/**
100105
* 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);
108113
*
109114
* @param repo A repository object
110115
* @param refdb An refdb object
116+
* @return 0 on success, or an error code
111117
*/
112-
GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
118+
GIT_EXTERN(int) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
113119

114120
/**
115121
* Set the index file for this repository
@@ -123,8 +129,9 @@ GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb
123129
*
124130
* @param repo A repository object
125131
* @param index An index object
132+
* @return 0 on success, or an error code
126133
*/
127-
GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
134+
GIT_EXTERN(int) git_repository_set_index(git_repository *repo, git_index *index);
128135

129136
/**
130137
* Set a repository to be bare.

src/repository.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void set_index(git_repository *repo, git_index *index)
138138
}
139139
}
140140

141-
void git_repository__cleanup(git_repository *repo)
141+
int git_repository__cleanup(git_repository *repo)
142142
{
143143
assert(repo);
144144

@@ -150,6 +150,8 @@ void git_repository__cleanup(git_repository *repo)
150150
set_index(repo, NULL);
151151
set_odb(repo, NULL);
152152
set_refdb(repo, NULL);
153+
154+
return 0;
153155
}
154156

155157
void git_repository_free(git_repository *repo)
@@ -1070,10 +1072,11 @@ int git_repository_config_snapshot(git_config **out, git_repository *repo)
10701072
return git_config_snapshot(out, weak);
10711073
}
10721074

1073-
void git_repository_set_config(git_repository *repo, git_config *config)
1075+
int git_repository_set_config(git_repository *repo, git_config *config)
10741076
{
10751077
assert(repo && config);
10761078
set_config(repo, config);
1079+
return 0;
10771080
}
10781081

10791082
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)
11211124
return 0;
11221125
}
11231126

1124-
void git_repository_set_odb(git_repository *repo, git_odb *odb)
1127+
int git_repository_set_odb(git_repository *repo, git_odb *odb)
11251128
{
11261129
assert(repo && odb);
11271130
set_odb(repo, odb);
1131+
return 0;
11281132
}
11291133

11301134
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)
11611165
return 0;
11621166
}
11631167

1164-
void git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
1168+
int git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
11651169
{
11661170
assert(repo && refdb);
11671171
set_refdb(repo, refdb);
1172+
return 0;
11681173
}
11691174

11701175
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)
12101215
return 0;
12111216
}
12121217

1213-
void git_repository_set_index(git_repository *repo, git_index *index)
1218+
int git_repository_set_index(git_repository *repo, git_index *index)
12141219
{
12151220
assert(repo);
12161221
set_index(repo, index);
1222+
return 0;
12171223
}
12181224

12191225
int git_repository_set_namespace(git_repository *repo, const char *namespace)

0 commit comments

Comments
 (0)