Skip to content

Commit cb43274

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

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

include/git2/sys/index.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ GIT_EXTERN(int) git_index_name_add(git_index *index,
7575
* Remove all filename conflict entries.
7676
*
7777
* @param index an existing index object
78+
* @return 0 or an error code
7879
*/
79-
GIT_EXTERN(void) git_index_name_clear(git_index *index);
80+
GIT_EXTERN(int) git_index_name_clear(git_index *index);
8081

8182
/**@}*/
8283

@@ -170,8 +171,9 @@ GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n);
170171
* Remove all resolve undo entries from the index
171172
*
172173
* @param index an existing index object
174+
* @return 0 or an error code
173175
*/
174-
GIT_EXTERN(void) git_index_reuc_clear(git_index *index);
176+
GIT_EXTERN(int) git_index_reuc_clear(git_index *index);
175177

176178
/**@}*/
177179

src/index.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,19 @@ int git_index_clear(git_index *index)
539539
git_idxmap_clear(index->entries_map);
540540
while (!error && index->entries.length > 0)
541541
error = index_remove_entry(index, index->entries.length - 1);
542+
543+
if (error)
544+
goto done;
545+
542546
index_free_deleted(index);
543547

544-
git_index_reuc_clear(index);
545-
git_index_name_clear(index);
548+
if ((error = git_index_name_clear(index)) < 0 ||
549+
(error = git_index_reuc_clear(index)) < 0)
550+
goto done;
546551

547552
git_futils_filestamp_set(&index->stamp, NULL);
548553

554+
done:
549555
return error;
550556
}
551557

@@ -2136,7 +2142,7 @@ int git_index_name_add(git_index *index,
21362142
return 0;
21372143
}
21382144

2139-
void git_index_name_clear(git_index *index)
2145+
int git_index_name_clear(git_index *index)
21402146
{
21412147
size_t i;
21422148
git_index_name_entry *conflict_name;
@@ -2149,6 +2155,8 @@ void git_index_name_clear(git_index *index)
21492155
git_vector_clear(&index->names);
21502156

21512157
index->dirty = 1;
2158+
2159+
return 0;
21522160
}
21532161

21542162
size_t git_index_reuc_entrycount(git_index *index)
@@ -2245,7 +2253,7 @@ int git_index_reuc_remove(git_index *index, size_t position)
22452253
return error;
22462254
}
22472255

2248-
void git_index_reuc_clear(git_index *index)
2256+
int git_index_reuc_clear(git_index *index)
22492257
{
22502258
size_t i;
22512259

@@ -2257,6 +2265,8 @@ void git_index_reuc_clear(git_index *index)
22572265
git_vector_clear(&index->reuc);
22582266

22592267
index->dirty = 1;
2268+
2269+
return 0;
22602270
}
22612271

22622272
static int index_error_invalid(const char *message)
@@ -3277,8 +3287,9 @@ static int git_index_read_iterator(
32773287
}
32783288
}
32793289

3280-
git_index_name_clear(index);
3281-
git_index_reuc_clear(index);
3290+
if ((error = git_index_name_clear(index)) < 0 ||
3291+
(error = git_index_reuc_clear(index)) < 0)
3292+
goto done;
32823293

32833294
git_vector_swap(&new_entries, &index->entries);
32843295
new_entries_map = git__swap(index->entries_map, new_entries_map);

0 commit comments

Comments
 (0)