Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7b3e1b

Browse files
committed
Some callback error check style cleanups
I find this easier to read...
1 parent 6005801 commit c7b3e1b

File tree

12 files changed

+54
-30
lines changed

12 files changed

+54
-30
lines changed

src/attr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ int git_attr_foreach(
191191
if (error < 0)
192192
goto cleanup;
193193

194-
error = GITERR_CALLBACK(
195-
callback(assign->name, assign->value, payload) );
196-
if (error)
194+
error = callback(assign->name, assign->value, payload);
195+
if (error) {
196+
GITERR_CALLBACK(error);
197197
goto cleanup;
198+
}
198199
}
199200
}
200201
}

src/diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,10 @@ int git_diff__paired_foreach(
13881388
i++; j++;
13891389
}
13901390

1391-
if ((error = GITERR_CALLBACK( cb(h2i, i2w, payload) )) != 0)
1391+
if ((error = cb(h2i, i2w, payload)) != 0) {
1392+
GITERR_CALLBACK(error);
13921393
break;
1394+
}
13931395
}
13941396

13951397
/* restore case-insensitive delta sort */

src/fetchhead.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,20 @@ int git_repository_fetchhead_foreach(git_repository *repo,
260260
while ((line = git__strsep(&buffer, "\n")) != NULL) {
261261
++line_num;
262262

263-
if ((error = fetchhead_ref_parse(&oid, &is_merge, &name, &remote_url,
264-
line, line_num)) < 0)
263+
if ((error = fetchhead_ref_parse(
264+
&oid, &is_merge, &name, &remote_url, line, line_num)) < 0)
265265
goto done;
266266

267267
if (git_buf_len(&name) > 0)
268268
ref_name = git_buf_cstr(&name);
269269
else
270270
ref_name = NULL;
271271

272-
error = GITERR_CALLBACK(
273-
cb(ref_name, remote_url, &oid, is_merge, payload) );
274-
if (error)
272+
error = cb(ref_name, remote_url, &oid, is_merge, payload);
273+
if (error) {
274+
GITERR_CALLBACK(error);
275275
goto done;
276+
}
276277
}
277278

278279
if (*buffer) {

src/merge.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ int git_repository_mergehead_foreach(
287287
if ((error = git_oid_fromstr(&oid, line)) < 0)
288288
goto cleanup;
289289

290-
if ((error = GITERR_CALLBACK( cb(&oid, payload) )) != 0)
290+
if ((error = cb(&oid, payload)) != 0) {
291+
GITERR_CALLBACK(error);
291292
goto cleanup;
293+
}
292294

293295
++line_num;
294296
}

src/pack-objects.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,12 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
229229
if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
230230
pb->last_progress_report_time = current_time;
231231

232-
return GITERR_CALLBACK( pb->progress_cb(
232+
ret = pb->progress_cb(
233233
GIT_PACKBUILDER_ADDING_OBJECTS,
234-
pb->nr_objects, 0, pb->progress_cb_payload) );
234+
pb->nr_objects, 0, pb->progress_cb_payload);
235+
236+
if (ret)
237+
return GITERR_CALLBACK(ret);
235238
}
236239
}
237240

src/pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,10 @@ int git_pack_foreach_entry(
10881088
}
10891089

10901090
for (i = 0; i < p->num_objects; i++)
1091-
if ((error = GITERR_CALLBACK( cb(p->oids[i], data) )) != 0)
1091+
if ((error = cb(p->oids[i], data)) != 0) {
1092+
GITERR_CALLBACK(error);
10921093
break;
1094+
}
10931095

10941096
return error;
10951097
}

src/path.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,13 @@ int git_path_walk_up(
434434
iter.asize = path->asize;
435435

436436
while (scan >= stop) {
437-
error = GITERR_CALLBACK( cb(data, &iter) );
437+
error = cb(data, &iter);
438438
iter.ptr[scan] = oldc;
439-
if (error)
439+
440+
if (error) {
441+
GITERR_CALLBACK(error);
440442
break;
443+
}
441444

442445
scan = git_buf_rfind_next(&iter, '/');
443446
if (scan >= 0) {
@@ -874,12 +877,14 @@ int git_path_direach(
874877
if ((error = git_buf_put(path, de_path, de_len)) < 0)
875878
break;
876879

877-
error = GITERR_CALLBACK( fn(arg, path) );
880+
error = fn(arg, path);
878881

879882
git_buf_truncate(path, wd_len); /* restore path */
880883

881-
if (error)
884+
if (error != 0) {
885+
GITERR_CALLBACK(error);
882886
break;
887+
}
883888
}
884889

885890
closedir(dir);

src/push.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,9 @@ int git_push_status_foreach(git_push *push,
659659
unsigned int i;
660660

661661
git_vector_foreach(&push->status, i, status) {
662-
GITERR_CHECK_ERROR(
663-
GITERR_CALLBACK( cb(status->ref, status->msg, data) ) );
662+
int error = cb(status->ref, status->msg, data);
663+
if (error)
664+
return GITERR_CALLBACK(error);
664665
}
665666

666667
return 0;

src/remote.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,11 @@ static int rename_fetch_refspecs(
13481348
if (!remote->name ||
13491349
strcmp(git_buf_cstr(&base), spec->string)) {
13501350

1351-
error = GITERR_CALLBACK( callback(spec->string, payload) );
1352-
if (error)
1351+
if ((error = callback(spec->string, payload)) != 0) {
1352+
GITERR_CALLBACK(error);
13531353
break;
1354+
}
1355+
13541356
continue;
13551357
}
13561358

src/stash.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,15 @@ int git_stash_foreach(
582582
for (i = 0; i < max; i++) {
583583
entry = git_reflog_entry_byindex(reflog, i);
584584

585-
error = GITERR_CALLBACK(
586-
callback(i,
587-
git_reflog_entry_message(entry),
588-
git_reflog_entry_id_new(entry),
589-
payload) );
590-
if (error)
585+
error = callback(i,
586+
git_reflog_entry_message(entry),
587+
git_reflog_entry_id_new(entry),
588+
payload);
589+
590+
if (error) {
591+
GITERR_CALLBACK(error);
591592
break;
593+
}
592594
}
593595

594596
cleanup:

0 commit comments

Comments
 (0)