Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a kh_find macro to simplify the code and avoid mistakes
Baptiste Daroussin committed 9 years ago
commit 13b83fb3e1bf7387eda9bd04093adb8ebd605c60
parent 3bdf74d
4 files changed +23 -38
modified libpkg/pkg.c
@@ -1721,7 +1721,6 @@ pkg_is_config_file(struct pkg *p, const char *path,
    const struct pkg_file **file,
    struct pkg_config_file **cfile)
{
-
	khint_t k, k2;

	*file = NULL;
	*cfile = NULL;
@@ -1729,16 +1728,15 @@ pkg_is_config_file(struct pkg *p, const char *path,
	if (kh_count(p->config_files) == 0)
		return (false);

-
	k = kh_get_pkg_files(p->filehash, path);
-
	if (k == kh_end(p->filehash))
+
	kh_find(pkg_files, p->filehash, path, *file);
+
	if (*file == NULL)
		return (false);

-
	k2 = kh_get_pkg_config_files(p->config_files, path);
-
	if (k2 == kh_end(p->config_files))
+
	kh_find(pkg_config_files, p->config_files, path, *cfile);
+
	if (cfile == NULL) {
+
		*file = NULL;
		return (false);
-

-
	*file = kh_value(p->filehash, k);
-
	*cfile = kh_value(p->config_files, k2);
+
	}

	return (true);
}
@@ -1746,13 +1744,9 @@ pkg_is_config_file(struct pkg *p, const char *path,
struct pkg_dir *
pkg_get_dir(struct pkg *p, const char *path)
{
-
	struct pkg_dir *d = NULL;
-
	khint_t k;
+
	struct pkg_dir *d;

-
	k = kh_get_pkg_dirs(p->dirhash, path);
-
	if (k != kh_end(p->dirhash)) {
-
		d = kh_value(p->dirhash, k);
-
	}
+
	kh_find(pkg_dirs, p->dirhash, path, d);

	return (d);
}
@@ -1760,13 +1754,9 @@ pkg_get_dir(struct pkg *p, const char *path)
struct pkg_file *
pkg_get_file(struct pkg *p, const char *path)
{
-
	struct pkg_file *f = NULL;
-
	khint_t k;
+
	struct pkg_file *f;

-
	k = kh_get_pkg_files(p->filehash, path);
-
	if (k != kh_end(p->filehash)) {
-
		f = kh_value(p->filehash, k);
-
	}
+
	kh_find(pkg_files, p->filehash, path, f);

	return (f);
}
modified libpkg/pkg_add.c
@@ -409,7 +409,6 @@ do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
	const struct stat *aest;
	unsigned long clear;
	int fd = -1;
-
	khint_t k;
	size_t len;
	struct timespec tspec[2];

@@ -438,9 +437,8 @@ do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
	}

	if (pkg->config_files != NULL) {
-
		k = kh_get_pkg_config_files(pkg->config_files, f->path);
-
		if (k != kh_end(pkg->config_files))
-
			f->config = kh_value(pkg->config_files, k);
+
		kh_find(pkg_config_files, pkg->config_files, f->path,
+
		    f->config);
	}

	if (f->config) {
modified libpkg/pkg_jobs_universe.c
@@ -49,19 +49,6 @@

typedef kvec_t(struct pkg *) pkg_chain_t;

-
static struct pkg_job_universe_item *
-
pkg_jobs_seen_find(struct pkg_jobs_universe *universe, const char *digest)
-
{
-
	khint_t k;
-

-
	if (universe->seen == NULL)
-
		return (NULL);
-
	k = kh_get_pkg_jobs_seen(universe->seen, digest);
-
	if (k == kh_end(universe->seen))
-
		return (NULL);
-
	return (kh_value(universe->seen, k));
-
}
-

struct pkg *
pkg_jobs_universe_get_local(struct pkg_jobs_universe *universe,
	const char *uid, unsigned flag)
@@ -182,7 +169,7 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
		}
	}

-
	seen = pkg_jobs_seen_find(universe, pkg->digest);
+
	kh_find(pkg_jobs_seen, universe->seen, pkg->digest, seen);
	if (seen != NULL && !force) {
		/*
		 * For remote packages we could have the same digest but different repos
modified libpkg/private/pkg.h
@@ -204,6 +204,16 @@
		free_func(val);				\
} while (0)

+
#define kh_find(name, h, k, ret) do {			\
+
	khint_t __k;					\
+
	__k = kh_get(name, h, k);			\
+
	ret = NULL;					\
+
	if (__k != kh_end(h)) {				\
+
		ret = kh_value(h, __k);			\
+
	}						\
+
} while (0)
+

+


extern int eventpipe;
extern int64_t debug_level;