| 138 | } |
| 139 | |
| 140 | static int merge_ref_iterator_advance(struct ref_iterator *ref_iterator) |
| 141 | { |
| 142 | struct merge_ref_iterator *iter = |
| 143 | (struct merge_ref_iterator *)ref_iterator; |
| 144 | int ok; |
| 145 | |
| 146 | if (!iter->current) { |
| 147 | /* Initialize: advance both iterators to their first entries */ |
| 148 | if ((ok = ref_iterator_advance(iter->iter0)) != ITER_OK) { |
| 149 | iter->iter0 = NULL; |
| 150 | if (ok == ITER_ERROR) |
| 151 | goto error; |
| 152 | } |
| 153 | if ((ok = ref_iterator_advance(iter->iter1)) != ITER_OK) { |
| 154 | iter->iter1 = NULL; |
| 155 | if (ok == ITER_ERROR) |
| 156 | goto error; |
| 157 | } |
| 158 | } else { |
| 159 | /* |
| 160 | * Advance the current iterator past the just-used |
| 161 | * entry: |
| 162 | */ |
| 163 | if ((ok = ref_iterator_advance(*iter->current)) != ITER_OK) { |
| 164 | *iter->current = NULL; |
| 165 | if (ok == ITER_ERROR) |
| 166 | goto error; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /* Loop until we find an entry that we can yield. */ |
| 171 | while (1) { |
| 172 | struct ref_iterator **secondary; |
| 173 | enum iterator_selection selection = |
| 174 | iter->select(iter->iter0, iter->iter1, iter->cb_data); |
| 175 | |
| 176 | if (selection == ITER_SELECT_DONE) { |
| 177 | return ITER_DONE; |
| 178 | } else if (selection == ITER_SELECT_ERROR) { |
| 179 | return ITER_ERROR; |
| 180 | } |
| 181 | |
| 182 | if ((selection & ITER_CURRENT_SELECTION_MASK) == 0) { |
| 183 | iter->current = &iter->iter0; |
| 184 | secondary = &iter->iter1; |
| 185 | } else { |
| 186 | iter->current = &iter->iter1; |
| 187 | secondary = &iter->iter0; |
| 188 | } |
| 189 | |
| 190 | if (selection & ITER_SKIP_SECONDARY) { |
| 191 | if ((ok = ref_iterator_advance(*secondary)) != ITER_OK) { |
| 192 | *secondary = NULL; |
| 193 | if (ok == ITER_ERROR) |
| 194 | goto error; |
| 195 | } |
| 196 | } |
| 197 |
nothing calls this directly
no test coverage detected