iterator: make use the `GIT_CONTAINER_OF` macro
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
diff --git a/src/iterator.c b/src/iterator.c
index 0db9292..d00b8aa 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1521,7 +1521,7 @@ static void filesystem_iterator_set_current(
static int filesystem_iterator_current(
const git_index_entry **out, git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
if (!iterator__has_been_accessed(i))
return iter->base.cb->advance(out, i);
@@ -1568,7 +1568,7 @@ done:
static int filesystem_iterator_advance(
const git_index_entry **out, git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
bool is_dir;
int error = 0;
@@ -1627,7 +1627,7 @@ static int filesystem_iterator_advance(
static int filesystem_iterator_advance_into(
const git_index_entry **out, git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *frame;
filesystem_iterator_entry *prev_entry;
int error;
@@ -1664,7 +1664,7 @@ static int filesystem_iterator_advance_into(
int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
const git_index_entry *entry;
if (i->type != GIT_ITERATOR_TYPE_FS &&
@@ -1724,15 +1724,19 @@ GIT_INLINE(bool) filesystem_iterator_current_is_ignored(
bool git_iterator_current_is_ignored(git_iterator *i)
{
+ filesystem_iterator *iter = NULL;
+
if (i->type != GIT_ITERATOR_TYPE_WORKDIR)
return false;
- return filesystem_iterator_current_is_ignored((filesystem_iterator *)i);
+ iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
+
+ return filesystem_iterator_current_is_ignored(iter);
}
bool git_iterator_current_tree_is_ignored(git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *frame;
if (i->type != GIT_ITERATOR_TYPE_WORKDIR)
@@ -1747,7 +1751,7 @@ static int filesystem_iterator_advance_over(
git_iterator_status_t *status,
git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *current_frame;
filesystem_iterator_entry *current_entry;
const git_index_entry *entry = NULL;
@@ -1866,7 +1870,7 @@ static int filesystem_iterator_init(filesystem_iterator *iter)
static int filesystem_iterator_reset(git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_clear(iter);
return filesystem_iterator_init(iter);
@@ -1874,7 +1878,7 @@ static int filesystem_iterator_reset(git_iterator *i)
static void filesystem_iterator_free(git_iterator *i)
{
- filesystem_iterator *iter = (filesystem_iterator *)i;
+ filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
git__free(iter->root);
git_buf_dispose(&iter->current_path);
git_tree_free(iter->tree);
@@ -2083,7 +2087,7 @@ static int index_iterator_skip_pseudotree(index_iterator *iter)
static int index_iterator_advance(
const git_index_entry **out, git_iterator *i)
{
- index_iterator *iter = (index_iterator *)i;
+ index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
const git_index_entry *entry = NULL;
bool is_submodule;
int error = 0;
@@ -2156,7 +2160,7 @@ static int index_iterator_advance(
static int index_iterator_advance_into(
const git_index_entry **out, git_iterator *i)
{
- index_iterator *iter = (index_iterator *)i;
+ index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
if (! S_ISDIR(iter->tree_entry.mode)) {
if (out)
@@ -2174,7 +2178,7 @@ static int index_iterator_advance_over(
git_iterator_status_t *status,
git_iterator *i)
{
- index_iterator *iter = (index_iterator *)i;
+ index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
const git_index_entry *entry;
int error;
@@ -2203,7 +2207,7 @@ static int index_iterator_init(index_iterator *iter)
static int index_iterator_reset(git_iterator *i)
{
- index_iterator *iter = (index_iterator *)i;
+ index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
index_iterator_clear(iter);
return index_iterator_init(iter);
@@ -2211,7 +2215,7 @@ static int index_iterator_reset(git_iterator *i)
static void index_iterator_free(git_iterator *i)
{
- index_iterator *iter = (index_iterator *)i;
+ index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
git_index_snapshot_release(&iter->entries, iter->base.index);
git_buf_dispose(&iter->tree_buf);