Skip to content

Commit

Permalink
foreach_alt_odb: propagate return value from callback
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 16, 2014
1 parent a136f6d commit fe1b226
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ extern void prepare_alt_odb(void);
extern void read_info_alternates(const char * relative_base, int depth);
extern void add_to_alternates_file(const char *reference);
typedef int alt_odb_fn(struct alternate_object_database *, void *);
extern void foreach_alt_odb(alt_odb_fn, void*);
extern int foreach_alt_odb(alt_odb_fn, void*);

struct pack_window {
struct pack_window *next;
Expand Down
12 changes: 8 additions & 4 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,18 @@ void add_to_alternates_file(const char *reference)
link_alt_odb_entries(alt, strlen(alt), '\n', NULL, 0);
}

void foreach_alt_odb(alt_odb_fn fn, void *cb)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
struct alternate_object_database *ent;
int r = 0;

prepare_alt_odb();
for (ent = alt_odb_list; ent; ent = ent->next)
if (fn(ent, cb))
return;
for (ent = alt_odb_list; ent; ent = ent->next) {
r = fn(ent, cb);
if (r)
break;
}
return r;
}

void prepare_alt_odb(void)
Expand Down

0 comments on commit fe1b226

Please sign in to comment.