Some callback error check style cleanups I find this easier to read...
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
diff --git a/src/attr.c b/src/attr.c
index 08d7ee9..553c071 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -191,10 +191,11 @@ int git_attr_foreach(
if (error < 0)
goto cleanup;
- error = GITERR_CALLBACK(
- callback(assign->name, assign->value, payload) );
- if (error)
+ error = callback(assign->name, assign->value, payload);
+ if (error) {
+ GITERR_CALLBACK(error);
goto cleanup;
+ }
}
}
}
diff --git a/src/diff.c b/src/diff.c
index 101426f..b7657e4 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1388,8 +1388,10 @@ int git_diff__paired_foreach(
i++; j++;
}
- if ((error = GITERR_CALLBACK( cb(h2i, i2w, payload) )) != 0)
+ if ((error = cb(h2i, i2w, payload)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
}
/* restore case-insensitive delta sort */
diff --git a/src/fetchhead.c b/src/fetchhead.c
index 7c37be4..2f217fa 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -260,8 +260,8 @@ int git_repository_fetchhead_foreach(git_repository *repo,
while ((line = git__strsep(&buffer, "\n")) != NULL) {
++line_num;
- if ((error = fetchhead_ref_parse(&oid, &is_merge, &name, &remote_url,
- line, line_num)) < 0)
+ if ((error = fetchhead_ref_parse(
+ &oid, &is_merge, &name, &remote_url, line, line_num)) < 0)
goto done;
if (git_buf_len(&name) > 0)
@@ -269,10 +269,11 @@ int git_repository_fetchhead_foreach(git_repository *repo,
else
ref_name = NULL;
- error = GITERR_CALLBACK(
- cb(ref_name, remote_url, &oid, is_merge, payload) );
- if (error)
+ error = cb(ref_name, remote_url, &oid, is_merge, payload);
+ if (error) {
+ GITERR_CALLBACK(error);
goto done;
+ }
}
if (*buffer) {
diff --git a/src/merge.c b/src/merge.c
index 6f73fc1..f1778c9 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -287,8 +287,10 @@ int git_repository_mergehead_foreach(
if ((error = git_oid_fromstr(&oid, line)) < 0)
goto cleanup;
- if ((error = GITERR_CALLBACK( cb(&oid, payload) )) != 0)
+ if ((error = cb(&oid, payload)) != 0) {
+ GITERR_CALLBACK(error);
goto cleanup;
+ }
++line_num;
}
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 2f0007f..09b7248 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -229,9 +229,12 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
pb->last_progress_report_time = current_time;
- return GITERR_CALLBACK( pb->progress_cb(
+ ret = pb->progress_cb(
GIT_PACKBUILDER_ADDING_OBJECTS,
- pb->nr_objects, 0, pb->progress_cb_payload) );
+ pb->nr_objects, 0, pb->progress_cb_payload);
+
+ if (ret)
+ return GITERR_CALLBACK(ret);
}
}
diff --git a/src/pack.c b/src/pack.c
index 3f2adb2..fd53ef4 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1088,8 +1088,10 @@ int git_pack_foreach_entry(
}
for (i = 0; i < p->num_objects; i++)
- if ((error = GITERR_CALLBACK( cb(p->oids[i], data) )) != 0)
+ if ((error = cb(p->oids[i], data)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
return error;
}
diff --git a/src/path.c b/src/path.c
index 857a2e6..8c19e00 100644
--- a/src/path.c
+++ b/src/path.c
@@ -434,10 +434,13 @@ int git_path_walk_up(
iter.asize = path->asize;
while (scan >= stop) {
- error = GITERR_CALLBACK( cb(data, &iter) );
+ error = cb(data, &iter);
iter.ptr[scan] = oldc;
- if (error)
+
+ if (error) {
+ GITERR_CALLBACK(error);
break;
+ }
scan = git_buf_rfind_next(&iter, '/');
if (scan >= 0) {
@@ -874,12 +877,14 @@ int git_path_direach(
if ((error = git_buf_put(path, de_path, de_len)) < 0)
break;
- error = GITERR_CALLBACK( fn(arg, path) );
+ error = fn(arg, path);
git_buf_truncate(path, wd_len); /* restore path */
- if (error)
+ if (error != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
}
closedir(dir);
diff --git a/src/push.c b/src/push.c
index 4281733..8ebba15 100644
--- a/src/push.c
+++ b/src/push.c
@@ -659,8 +659,9 @@ int git_push_status_foreach(git_push *push,
unsigned int i;
git_vector_foreach(&push->status, i, status) {
- GITERR_CHECK_ERROR(
- GITERR_CALLBACK( cb(status->ref, status->msg, data) ) );
+ int error = cb(status->ref, status->msg, data);
+ if (error)
+ return GITERR_CALLBACK(error);
}
return 0;
diff --git a/src/remote.c b/src/remote.c
index 307306d..d46364a 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1348,9 +1348,11 @@ static int rename_fetch_refspecs(
if (!remote->name ||
strcmp(git_buf_cstr(&base), spec->string)) {
- error = GITERR_CALLBACK( callback(spec->string, payload) );
- if (error)
+ if ((error = callback(spec->string, payload)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
+
continue;
}
diff --git a/src/stash.c b/src/stash.c
index 458a1e1..fb5bb2e 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -582,13 +582,15 @@ int git_stash_foreach(
for (i = 0; i < max; i++) {
entry = git_reflog_entry_byindex(reflog, i);
- error = GITERR_CALLBACK(
- callback(i,
- git_reflog_entry_message(entry),
- git_reflog_entry_id_new(entry),
- payload) );
- if (error)
+ error = callback(i,
+ git_reflog_entry_message(entry),
+ git_reflog_entry_id_new(entry),
+ payload);
+
+ if (error) {
+ GITERR_CALLBACK(error);
break;
+ }
}
cleanup:
diff --git a/src/status.c b/src/status.c
index d76617a..d4a4362 100644
--- a/src/status.c
+++ b/src/status.c
@@ -392,9 +392,10 @@ int git_status_foreach_ext(
status_entry->head_to_index->old_file.path :
status_entry->index_to_workdir->old_file.path;
- error = GITERR_CALLBACK( cb(path, status_entry->status, payload) );
- if (error)
+ if ((error = cb(path, status_entry->status, payload)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
}
git_status_list_free(status);
diff --git a/src/submodule.c b/src/submodule.c
index e9d534a..5298302 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -168,8 +168,10 @@ int git_submodule_foreach(
break;
}
- if ((error = GITERR_CALLBACK(callback(sm, sm->name, payload))) != 0)
+ if ((error = callback(sm, sm->name, payload)) != 0) {
+ GITERR_CALLBACK(error);
break;
+ }
});
git_vector_free(&seen);