Skip to content

Commit fe1b226

Browse files
peffgitster
authored andcommitted
foreach_alt_odb: propagate return value from callback
We check the return value of the callback and stop iterating if it is non-zero. However, we do not make the non-zero return value available to the caller, so they have no way of knowing whether the operation succeeded or not (technically they can keep their own error flag in the callback data, but that is unlike our other for_each functions). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a136f6d commit fe1b226

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ extern void prepare_alt_odb(void);
11431143
extern void read_info_alternates(const char * relative_base, int depth);
11441144
extern void add_to_alternates_file(const char *reference);
11451145
typedef int alt_odb_fn(struct alternate_object_database *, void *);
1146-
extern void foreach_alt_odb(alt_odb_fn, void*);
1146+
extern int foreach_alt_odb(alt_odb_fn, void*);
11471147

11481148
struct pack_window {
11491149
struct pack_window *next;

sha1_file.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,18 @@ void add_to_alternates_file(const char *reference)
412412
link_alt_odb_entries(alt, strlen(alt), '\n', NULL, 0);
413413
}
414414

415-
void foreach_alt_odb(alt_odb_fn fn, void *cb)
415+
int foreach_alt_odb(alt_odb_fn fn, void *cb)
416416
{
417417
struct alternate_object_database *ent;
418+
int r = 0;
418419

419420
prepare_alt_odb();
420-
for (ent = alt_odb_list; ent; ent = ent->next)
421-
if (fn(ent, cb))
422-
return;
421+
for (ent = alt_odb_list; ent; ent = ent->next) {
422+
r = fn(ent, cb);
423+
if (r)
424+
break;
425+
}
426+
return r;
423427
}
424428

425429
void prepare_alt_odb(void)

0 commit comments

Comments
 (0)