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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 15, 2014 at 18:33 UTC fe1b22686f26bed3047294cc4552e50ce58fa954
2 files changed +9 -5
cache.h
+1 -1
@@ -1143,7 +1143,7 @@ extern void prepare_alt_odb(void);
1143 extern void read_info_alternates(const char * relative_base, int depth);
1144 extern void add_to_alternates_file(const char *reference);
1145 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*);
1147
1148 struct pack_window {
1149 struct pack_window *next;
sha1_file.c
+8 -4
@@ -412,14 +412,18 @@ void add_to_alternates_file(const char *reference)
412 link_alt_odb_entries(alt, strlen(alt), '\n', NULL, 0);
413 }
414
415 -void foreach_alt_odb(alt_odb_fn fn, void *cb)
415 +int foreach_alt_odb(alt_odb_fn fn, void *cb)
416 {
417 struct alternate_object_database *ent;
418 + int r = 0;
419
420 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;
427 }
428
429 void prepare_alt_odb(void)