summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-03-25 23:04:26 -0700
committerRussell Belfer <arrbee@arrbee.com>2012-03-25 23:04:26 -0700
commit1db12b00532d747fa7a805a8fa8d293c58ec16d9 (patch)
treec7fd3bc4e6b27ab35c0ca7162274452deee53410 /src/status.c
parent875bfc5ffcdd21fca616d4f88444d4dcf6fd69ac (diff)
downloadlibgit2-1db12b00532d747fa7a805a8fa8d293c58ec16d9.tar.gz
Eliminate hairy COITERATE macro
I decided that the COITERATE macro was, in the end causing more confusion that it would save and decided just to write out the loops that I needed for parallel diff list iteration. It is not that much code and this just feels less obfuscated.
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/status.c b/src/status.c
index bec75294f..88dd5e03b 100644
--- a/src/status.c
+++ b/src/status.c
@@ -120,13 +120,14 @@ int git_status_foreach_ext(
int (*cb)(const char *, unsigned int, void *),
void *cbdata)
{
- int err = 0;
+ int err = 0, cmp;
git_diff_options diffopt;
git_diff_list *idx2head = NULL, *wd2idx = NULL;
git_tree *head = NULL;
git_status_show_t show =
opts ? opts->show : GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
git_diff_delta *i2h, *w2i;
+ unsigned int i, j, i_max, j_max;
assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
@@ -158,23 +159,35 @@ int git_status_foreach_ext(
goto cleanup;
if (show == GIT_STATUS_SHOW_INDEX_THEN_WORKDIR) {
- git_diff_list *empty = NULL;
- GIT_DIFF_COITERATE(
- idx2head, empty, i2h, w2i,
- err = cb(i2h->old.path, index_delta2status(i2h->status), cbdata),
- /* nothing */, /* nothing */, if (err < 0) break);
-
+ for (i = 0; !err && i < idx2head->deltas.length; i++) {
+ i2h = GIT_VECTOR_GET(&idx2head->deltas, i);
+ err = cb(i2h->old.path, index_delta2status(i2h->status), cbdata);
+ }
git_diff_list_free(idx2head);
idx2head = NULL;
}
- GIT_DIFF_COITERATE(
- idx2head, wd2idx, i2h, w2i,
- err = cb(i2h->old.path, index_delta2status(i2h->status), cbdata),
- err = cb(w2i->old.path, workdir_delta2status(w2i->status), cbdata),
- err = cb(i2h->old.path, index_delta2status(i2h->status) |
- workdir_delta2status(w2i->status), cbdata),
- if (err < 0) break);
+ i_max = idx2head ? idx2head->deltas.length : 0;
+ j_max = wd2idx ? wd2idx->deltas.length : 0;
+
+ for (i = 0, j = 0; !err && (i < i_max || j < j_max); ) {
+ i2h = idx2head ? GIT_VECTOR_GET(&idx2head->deltas,i) : NULL;
+ w2i = wd2idx ? GIT_VECTOR_GET(&wd2idx->deltas,j) : NULL;
+
+ cmp = !w2i ? -1 : !i2h ? 1 : strcmp(i2h->old.path, w2i->old.path);
+
+ if (cmp < 0) {
+ err = cb(i2h->old.path, index_delta2status(i2h->status), cbdata);
+ i++;
+ } else if (cmp > 0) {
+ err = cb(w2i->old.path, workdir_delta2status(w2i->status), cbdata);
+ j++;
+ } else {
+ err = cb(i2h->old.path, index_delta2status(i2h->status) |
+ workdir_delta2status(w2i->status), cbdata);
+ i++; j++;
+ }
+ }
cleanup:
git_tree_free(head);