index iterator: optionally include conflicts
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
diff --git a/src/iterator.c b/src/iterator.c
index c5c5fd7..1e946fa 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -46,6 +46,7 @@
#define iterator__include_trees(I) iterator__flag(I,INCLUDE_TREES)
#define iterator__dont_autoexpand(I) iterator__flag(I,DONT_AUTOEXPAND)
#define iterator__do_autoexpand(I) !iterator__flag(I,DONT_AUTOEXPAND)
+#define iterator__include_conflicts(I) iterator__flag(I, INCLUDE_CONFLICTS)
#define GIT_ITERATOR_FIRST_ACCESS (1 << 15)
#define iterator__has_been_accessed(I) iterator__flag(I,FIRST_ACCESS)
@@ -668,13 +669,16 @@ static const git_index_entry *index_iterator__index_entry(index_iterator *ii)
return ie;
}
-static const git_index_entry *index_iterator__skip_conflicts(index_iterator *ii)
+static const git_index_entry *index_iterator__advance_over_conflicts(index_iterator *ii)
{
- const git_index_entry *ie;
+ const git_index_entry *ie = index_iterator__index_entry(ii);
- while ((ie = index_iterator__index_entry(ii)) != NULL &&
- git_index_entry_stage(ie) != 0)
- ii->current++;
+ if (!iterator__include_conflicts(ii)) {
+ while (ie && git_index_entry_stage(ie) != 0) {
+ ii->current++;
+ ie = index_iterator__index_entry(ii);
+ }
+ }
return ie;
}
@@ -702,7 +706,7 @@ static void index_iterator__next_prefix_tree(index_iterator *ii)
static int index_iterator__first_prefix_tree(index_iterator *ii)
{
- const git_index_entry *ie = index_iterator__skip_conflicts(ii);
+ const git_index_entry *ie = index_iterator__advance_over_conflicts(ii);
const char *scan, *prior, *slash;
if (!ie || !iterator__include_trees(ii))
@@ -825,7 +829,7 @@ static int index_iterator__reset(
git_index_snapshot_find(
&ii->current, &ii->entries, ii->entry_srch, ii->base.start, 0, 0);
- if ((ie = index_iterator__skip_conflicts(ii)) == NULL)
+ if ((ie = index_iterator__advance_over_conflicts(ii)) == NULL)
return 0;
if (git_buf_sets(&ii->partial, ie->path) < 0)
diff --git a/src/iterator.h b/src/iterator.h
index 1520bff..db1f325 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -33,6 +33,8 @@ typedef enum {
GIT_ITERATOR_DONT_AUTOEXPAND = (1u << 3),
/** convert precomposed unicode to decomposed unicode */
GIT_ITERATOR_PRECOMPOSE_UNICODE = (1u << 4),
+ /** include conflicts */
+ GIT_ITERATOR_INCLUDE_CONFLICTS = (1u << 5),
} git_iterator_flag_t;
typedef struct {