allow got_object_idset_for_each() to return an error
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
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index df87bed..0165b20 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -490,13 +490,14 @@ struct gather_branch_tips_arg {
int ntips;
};
-static void
+static const struct got_error *
gather_branch_tips(struct got_object_id *id, void *data, void *arg)
{
struct gather_branch_tips_arg *a = arg;
memcpy(&a->tips[a->ntips].id, id, sizeof(*id));
a->tips[a->ntips].node = data;
a->ntips++;
+ return NULL;
}
static const struct got_error *
@@ -531,8 +532,10 @@ fetch_commits_from_open_branches(int *ncommits,
}
arg.ntips = 0; /* reset; gather_branch_tips() will increment */
arg.tips = graph->tips;
- got_object_idset_for_each(graph->open_branches,
+ err = got_object_idset_for_each(graph->open_branches,
gather_branch_tips, &arg);
+ if (err)
+ return err;
for (i = 0; i < arg.ntips; i++) {
struct got_object_id *commit_id;
@@ -588,11 +591,12 @@ got_commit_graph_fetch_commits(struct got_commit_graph *graph, int limit,
return NULL;
}
-static void
+static const struct got_error *
free_node_iter(struct got_object_id *id, void *data, void *arg)
{
struct got_commit_graph_node *node = data;
free_node(node);
+ return NULL;
}
void
diff --git a/lib/got_lib_object_idset.h b/lib/got_lib_object_idset.h
index aad9204..6ae68d9 100644
--- a/lib/got_lib_object_idset.h
+++ b/lib/got_lib_object_idset.h
@@ -26,6 +26,7 @@ const struct got_error *got_object_idset_remove(void **,
struct got_object_idset *, struct got_object_id *);
int got_object_idset_contains(struct got_object_idset *,
struct got_object_id *);
-void got_object_idset_for_each(struct got_object_idset *,
- void (*cb)(struct got_object_id *, void *, void *), void *);
+const struct got_error *got_object_idset_for_each(struct got_object_idset *,
+ const struct got_error *(*cb)(struct got_object_id *, void *, void *),
+ void *);
int got_object_idset_num_elements(struct got_object_idset *);
diff --git a/lib/object_cache.c b/lib/object_cache.c
index 1433b27..3325c9f 100644
--- a/lib/object_cache.c
+++ b/lib/object_cache.c
@@ -149,7 +149,8 @@ print_cache_stats(struct got_object_cache *cache, const char *name)
cache->cache_miss, cache->cache_evict);
}
-void check_refcount(struct got_object_id *id, void *data, void *arg)
+const struct got_error *
+check_refcount(struct got_object_id *id, void *data, void *arg)
{
struct got_object_cache *cache = arg;
struct got_object_cache_entry *ce = data;
@@ -159,7 +160,7 @@ void check_refcount(struct got_object_id *id, void *data, void *arg)
char *id_str;
if (got_object_id_str(&id_str, id) != NULL)
- return;
+ return NULL;
switch (cache->type) {
case GOT_OBJECT_CACHE_TYPE_OBJ:
@@ -185,6 +186,7 @@ void check_refcount(struct got_object_id *id, void *data, void *arg)
break;
}
free(id_str);
+ return NULL;
}
#endif
diff --git a/lib/object_idset.c b/lib/object_idset.c
index 8b2ebfe..aef9d21 100644
--- a/lib/object_idset.c
+++ b/lib/object_idset.c
@@ -172,13 +172,20 @@ got_object_idset_contains(struct got_object_idset *set,
return entry ? 1 : 0;
}
-void got_object_idset_for_each(struct got_object_idset *set,
- void (*cb)(struct got_object_id *, void *, void *), void *arg)
+const struct got_error *
+got_object_idset_for_each(struct got_object_idset *set,
+ const struct got_error *(*cb)(struct got_object_id *, void *, void *),
+ void *arg)
{
+ const struct got_error *err;
struct got_object_idset_element *entry;
- RB_FOREACH(entry, got_object_idset_tree, &set->entries)
- (*cb)(&entry->id, entry->data, arg);
+ RB_FOREACH(entry, got_object_idset_tree, &set->entries) {
+ err = (*cb)(&entry->id, entry->data, arg);
+ if (err)
+ return err;
+ }
+ return NULL;
}
int
diff --git a/regress/idset/idset_test.c b/regress/idset/idset_test.c
index a3971bd..0925d76 100644
--- a/regress/idset/idset_test.c
+++ b/regress/idset/idset_test.c
@@ -55,12 +55,13 @@ static const char *id_str3 = "ffffffffffffffffffffffffffffffffffffffff";
static struct got_object_id id1, id2, id3;
static const char *data1 = "data1", *data2 = "data2", *data3 = "data3";
-static void
+static const struct got_error *
idset_cb(struct got_object_id *id, void *data, void *arg) {
if ((got_object_id_cmp(id, &id1) == 0 && data == (void *)data1) ||
(got_object_id_cmp(id, &id3) == 0 && data == (void *)data3))
- return;
+ return NULL;
abort();
+ return NULL; /* not reached */
}
static int