Further callback error check style fixes Okay, I've decided I like the readability of this style much better so I used it everywhere.
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
diff --git a/src/config.c b/src/config.c
index 8b3a426..5477b04 100644
--- a/src/config.c
+++ b/src/config.c
@@ -507,9 +507,10 @@ int git_config_backend_foreach_match(
continue;
/* abort iterator on non-zero return value */
- error = GITERR_CALLBACK( cb(entry, payload) );
- if (error)
+ if ((error = cb(entry, payload)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
}
if (regexp != NULL)
@@ -533,9 +534,12 @@ int git_config_foreach_match(
if ((error = git_config_iterator_glob_new(&iter, cfg, regexp)) < 0)
return error;
- while (!(error = git_config_next(&entry, iter)) &&
- !(error = GITERR_CALLBACK( cb(entry, payload) )))
- /* make callback on each config */;
+ while (!(error = git_config_next(&entry, iter))) {
+ if ((error = cb(entry, payload)) != 0) {
+ GITERR_CALLBACK(error);
+ break;
+ }
+ }
git_config_iterator_free(iter);
@@ -794,8 +798,10 @@ int git_config_get_multivar_foreach(
while ((err = iter->next(&entry, iter)) == 0) {
found = 1;
- if ((err = GITERR_CALLBACK( cb(entry, payload) )) != 0)
+ if ((err = cb(entry, payload)) != 0) {
+ GITERR_CALLBACK(err);
break;
+ }
}
iter->free(iter);
diff --git a/src/notes.c b/src/notes.c
index e3a3fcc..e0d5ad1 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -582,10 +582,12 @@ int git_note_foreach(
if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0)
return error;
- while (!(error = git_note_next(¬e_id, &annotated_id, iter)) &&
- !(error = GITERR_CALLBACK(
- note_cb(¬e_id, &annotated_id, payload))))
- /* callback for each note */;
+ while (!(error = git_note_next(¬e_id, &annotated_id, iter))) {
+ if ((error = note_cb(¬e_id, &annotated_id, payload)) != 0) {
+ GITERR_CALLBACK(error);
+ break;
+ }
+ }
if (error == GIT_ITEROVER)
error = 0;
diff --git a/src/refs.c b/src/refs.c
index afb0679..25037cc 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -516,9 +516,12 @@ int git_reference_foreach(
if ((error = git_reference_iterator_new(&iter, repo)) < 0)
return error;
- while (!(error = git_reference_next(&ref, iter)) &&
- !(error = GITERR_CALLBACK( callback(ref, payload) )))
- /* callback on each reference */;
+ while (!(error = git_reference_next(&ref, iter))) {
+ if ((error = callback(ref, payload)) != 0) {
+ GITERR_CALLBACK(error);
+ break;
+ }
+ }
if (error == GIT_ITEROVER)
error = 0;
@@ -539,9 +542,12 @@ int git_reference_foreach_name(
if ((error = git_reference_iterator_new(&iter, repo)) < 0)
return error;
- while (!(error = git_reference_next_name(&refname, iter)) &&
- !(error = GITERR_CALLBACK( callback(refname, payload) )))
- /* callback on each reference name */;
+ while (!(error = git_reference_next_name(&refname, iter))) {
+ if ((error = callback(refname, payload)) != 0) {
+ GITERR_CALLBACK(error);
+ break;
+ }
+ }
if (error == GIT_ITEROVER)
error = 0;
@@ -563,9 +569,12 @@ int git_reference_foreach_glob(
if ((error = git_reference_iterator_glob_new(&iter, repo, glob)) < 0)
return error;
- while (!(error = git_reference_next_name(&refname, iter)) &&
- !(error = GITERR_CALLBACK( callback(refname, payload) )))
- /* callback on each matching reference name */;
+ while (!(error = git_reference_next_name(&refname, iter))) {
+ if ((error = callback(refname, payload)) != 0) {
+ GITERR_CALLBACK(error);
+ break;
+ }
+ }
if (error == GIT_ITEROVER)
error = 0;