Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a new function pkg_dep_lookup to avoid uselessly looping on deps
Baptiste Daroussin committed 12 years ago
commit 284c496f0e25bea3c536a0cf36af037233f6a820
parent 5d83698
3 files changed +18 -10
modified libpkg/pkg.c
@@ -393,6 +393,19 @@ pkg_deps(const struct pkg *pkg, struct pkg_dep **d)
	HASH_NEXT(pkg->deps, (*d));
}

+
struct pkg_dep *
+
pkg_dep_lookup(const struct pkg *pkg, const char *origin)
+
{
+
	struct pkg_dep *d = NULL;
+

+
	assert(pkg != NULL);
+
	assert(origin != NULL);
+

+
	HASH_FIND_STR(pkg->deps, __DECONST(char *, origin), d);
+

+
	return (d);
+
}
+

int
pkg_rdeps(const struct pkg *pkg, struct pkg_dep **d)
{
modified libpkg/pkg.h.in
@@ -532,6 +532,8 @@ int pkg_list_count(const struct pkg *, pkg_list);
 */
int pkg_deps(const struct pkg *, struct pkg_dep **dep);

+
struct pkg_dep *pkg_dep_lookup(const struct pkg *, const char *origin);
+

/**
 * Iterates over the reverse dependencies of the package.
 * That is, the packages which require this package.
modified libpkg/pkg_elf.c
@@ -120,7 +120,6 @@ test_depends(void *actdata, struct pkg *pkg, const char *fpath,
	const char *pkgname, *pkgversion;
	bool deplocked;
	char pathbuf[MAXPATHLEN];
-
	bool found;

	assert(db != NULL);

@@ -153,15 +152,9 @@ test_depends(void *actdata, struct pkg *pkg, const char *fpath,
			   PKG_VERSION, &depversion,
			   PKG_LOCKED,  &deplocked);

-
		dep = NULL;
-
		found = false;
-
		while (pkg_deps(pkg, &dep) == EPKG_OK) {
-
			if (strcmp(pkg_dep_origin(dep), deporigin) == 0) {
-
				found = true;
-
				break;
-
			}
-
		}
-
		if (!found) {
+
		dep = pkg_dep_lookup(pkg, deporigin);
+

+
		if (dep != NULL) {
			pkg_emit_error("adding unlisted depends (%s): %s-%s",
			    pathbuf, depname, depversion);
			pkg_adddep(pkg, depname, deporigin, depversion,