diff options
| author | Russell Belfer <rb@github.com> | 2013-05-31 12:18:43 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-05-31 12:18:43 -0700 |
| commit | cee695ae6b9a9f586d32d0b9460a358bfdc4fe1b (patch) | |
| tree | 33fa5cceec1bbb24ab919ccb21732cd1487d4fec /src/merge.c | |
| parent | 1ed356dcfef449313bac3ce795f26d19423c744c (diff) | |
| download | libgit2-cee695ae6b9a9f586d32d0b9460a358bfdc4fe1b.tar.gz | |
Make iterators use GIT_ITEROVER & smart advance
1. internal iterators now return GIT_ITEROVER when you go past the
last item in the iteration.
2. git_iterator_advance will "advance" to the first item in the
iteration if it is called immediately after creating the
iterator, which allows a simpler idiom for basic iteration.
3. if git_iterator_advance encounters an error reading data (e.g.
a missing tree or an unreadable file), it returns the error
but also attempts to advance past the invalid data to prevent
an infinite loop.
Updated all tests and internal usage of iterators to account for
these new behaviors.
Diffstat (limited to 'src/merge.c')
| -rw-r--r-- | src/merge.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/merge.c b/src/merge.c index 11345587c..047d96013 100644 --- a/src/merge.c +++ b/src/merge.c @@ -1259,7 +1259,8 @@ int git_merge_diff_list__find_differences( /* Set up the iterators */ for (i = 0; i < 3; i++) { - if ((error = git_iterator_current(&items[i], iterators[i])) < 0) + error = git_iterator_current(&items[i], iterators[i]); + if (error < 0 && error != GIT_ITEROVER) goto done; } @@ -1313,11 +1314,16 @@ int git_merge_diff_list__find_differences( error = merge_index_insert_conflict(diff_list, &df_data, cur_items); else error = merge_index_insert_unmodified(diff_list, cur_items); + if (error < 0) + goto done; /* Advance each iterator that participated */ for (i = 0; i < 3; i++) { - if (cur_items[i] != NULL && - (error = git_iterator_advance(&items[i], iterators[i])) < 0) + if (cur_items[i] == NULL) + continue; + + error = git_iterator_advance(&items[i], iterators[i]); + if (error < 0 && error != GIT_ITEROVER) goto done; } } @@ -1326,6 +1332,9 @@ done: for (i = 0; i < 3; i++) git_iterator_free(iterators[i]); + if (error == GIT_ITEROVER) + error = 0; + return error; } |
