Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use function pointers instead of a switch/case
Baptiste Daroussin committed 12 years ago
commit 40b9cc93a2a587f5d68b1c5aa8ec73cf42d75ba8
parent 62e7e8f
3 files changed +11 -8
modified libpkg/pkg_config.c
@@ -1254,6 +1254,7 @@ pkg_repo_new(const char *name, const char *url)

	r = calloc(1, sizeof(struct pkg_repo));
	r->type = REPO_BINARY_PKGS;
+
	r->update = repo_update_binary_pkgs;
	r->url = subst_packagesite_str(url);
	r->signature_type = SIG_NONE;
	r->mirror_type = NOMIRROR;
modified libpkg/private/pkg.h
@@ -319,6 +319,9 @@ struct pkg_repo {
	} sshio;
	size_t fetched;
	size_t tofetch;
+

+
	int (*update)(struct pkg_repo *, bool);
+

	bool enable;
	UT_hash_handle hh;
};
@@ -470,4 +473,7 @@ int pkg_emit_manifest_sbuf(struct pkg*, struct sbuf *, short, char **);
int pkg_emit_filelist(struct pkg *, FILE *);

int do_extract_mtree(char *mtree, const char *prefix);
+

+
int repo_update_binary_pkgs(struct pkg_repo *repo, bool force);
+

#endif
modified libpkg/update.c
@@ -810,8 +810,8 @@ cleanup:
	return (rc);
}

-
static int
-
update_binary_pkgs(struct pkg_repo *repo, bool force)
+
int
+
repo_update_binary_pkgs(struct pkg_repo *repo, bool force)
{
	char repofile[MAXPATHLEN];

@@ -913,9 +913,5 @@ cleanup:
int
pkg_update(struct pkg_repo *repo, bool force)
{
-
	switch (repo->type) {
-
	case REPO_BINARY_PKGS:
-
		return (update_binary_pkgs(repo, force));
-
		break;
-
	}
-
};
+
	return (repo->update(repo, force));
+
}