Commit cb103d042c6d1e6cb1483ffa71f54577a8564d9a

Stefan Sperling 2018-11-07T06:42:26

allow got_object_idset_for_each() to return an error

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