Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Convert pkg_files to khash
Baptiste Daroussin committed 10 years ago
commit 942aa46c76b1e90b39dfe29d454b9485f1258c2d
parent 103ce1c
6 files changed +29 -38
modified libpkg/pkg.c
@@ -530,7 +530,7 @@ pkg_files(const struct pkg *pkg, struct pkg_file **f)
{
	assert(pkg != NULL);

-
	HASH_NEXT(pkg->files, (*f));
+
	kh_next(pkg_files, pkg->files, (*f), path);
}

int
@@ -754,16 +754,13 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sum,
	path = pkg_absolutepath(path, abspath, sizeof(abspath));
	pkg_debug(3, "Pkg: add new file '%s'", path);

-
	if (check_duplicates) {
-
		HASH_FIND_STR(pkg->files, path, f);
-
		if (f != NULL) {
-
			if (developer_mode) {
-
				pkg_emit_error("duplicate file listing: %s, fatal (developer mode)", f->path);
-
				return (EPKG_FATAL);
-
			} else {
-
				pkg_emit_error("duplicate file listing: %s, ignoring", f->path);
-
				return (EPKG_OK);
-
			}
+
	if (check_duplicates && kh_contains(pkg_files, pkg->files, path)) {
+
		if (developer_mode) {
+
			pkg_emit_error("duplicate file listing: %s, fatal (developer mode)", f->path);
+
			return (EPKG_FATAL);
+
		} else {
+
			pkg_emit_error("duplicate file listing: %s, ignoring", f->path);
+
			return (EPKG_OK);
		}
	}

@@ -785,7 +782,7 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sum,
	if (fflags != 0)
		f->fflags = fflags;

-
	HASH_ADD_STR(pkg->files, path, f);
+
	kh_add(pkg_files, pkg->files, f, f->path);

	return (EPKG_OK);
}
@@ -1323,7 +1320,7 @@ pkg_list_count(const struct pkg *pkg, pkg_list list)
	case PKG_OPTIONS:
		return (HASH_COUNT(pkg->options));
	case PKG_FILES:
-
		return (HASH_COUNT(pkg->files));
+
		return (kh_count(pkg->files));
	case PKG_DIRS:
		return (HASH_COUNT(pkg->dirs));
	case PKG_USERS:
@@ -1364,7 +1361,7 @@ pkg_list_free(struct pkg *pkg, pkg_list list) {
		break;
	case PKG_FILES:
	case PKG_CONFIG_FILES:
-
		HASH_FREE(pkg->files, pkg_file_free);
+
		kh_free(pkg_files, pkg->files, struct pkg_file, pkg_file_free);
		HASH_FREE(pkg->config_files, pkg_config_file_free);
		pkg->flags &= ~PKG_LOAD_FILES;
		break;
@@ -1731,21 +1728,21 @@ pkg_is_config_file(struct pkg *p, const char *path,
    const struct pkg_file **file,
    struct pkg_config_file **cfile)
{
-
	struct pkg_file *f;
	struct pkg_config_file *cf;
+
	khint_t k;

	*file = NULL;
	*cfile = NULL;

-
	HASH_FIND_STR(p->files, path, f);
-
	if (f == NULL)
+
	k = kh_get_pkg_files(p->files, path);
+
	if (k == kh_end(p->files))
		return (false);

	HASH_FIND_STR(p->config_files, path, cf);
	if (cf == NULL)
		return (false);

-
	*file = f;
+
	*file = kh_value(p->files, k);
	*cfile = cf;

	return (true);
@@ -1754,11 +1751,7 @@ pkg_is_config_file(struct pkg *p, const char *path,
bool
pkg_has_file(struct pkg *p, const char *path)
{
-
	struct pkg_file *f;
-

-
	HASH_FIND_STR(p->files, path, f);
-

-
	return (f != NULL ? true : false);
+
	return (kh_contains(pkg_files, p->files, path));
}

bool
modified libpkg/pkg_add.c
@@ -647,7 +647,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,

	/* add the user and group if necessary */

-
	nfiles = HASH_COUNT(pkg->files);
+
	nfiles = kh_count(pkg->files);
	/*
	 * Extract the files on disk.
	 */
modified libpkg/pkg_create.c
@@ -75,7 +75,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	 * Get / compute size / checksum if not provided in the manifest
	 */

-
	nfiles = HASH_COUNT(pkg->files);
+
	nfiles = kh_count(pkg->files);
	counter_init("file sizes/checksums", nfiles);

	hardlinks = kh_init_hardlinks();
modified libpkg/pkg_delete.c
@@ -327,7 +327,7 @@ pkg_delete_files(struct pkg *pkg, unsigned force)

	int		nfiles, cur_file = 0;

-
	nfiles = HASH_COUNT(pkg->files);
+
	nfiles = kh_count(pkg->files);

	if (nfiles == 0)
		return (EPKG_OK);
modified libpkg/pkg_jobs_conflicts.c
@@ -207,7 +207,7 @@ pkg_conflicts_item_cmp(struct pkg_jobs_conflict_item *a,
static bool
pkg_conflicts_need_conflict(struct pkg_jobs *j, struct pkg *p1, struct pkg *p2)
{
-
	struct pkg_file *fcur, *ftmp, *ff;
+
	struct pkg_file *fcur;
	struct pkg_dir *df;
	struct pkg_conflict *c1, *c2;

@@ -235,14 +235,13 @@ pkg_conflicts_need_conflict(struct pkg_jobs *j, struct pkg *p1, struct pkg *p2)
	/*
	 * We need to check all files and dirs and find the similar ones
	 */
-
	HASH_ITER(hh, p1->files, fcur, ftmp) {
-
		HASH_FIND_STR(p2->files, fcur->path, ff);
-
		if (ff != NULL)
+
	kh_each_value(p1->files, fcur, {
+
		if (pkg_has_file(p2, fcur->path))
			return (true);
		HASH_FIND_STR(p2->dirs, fcur->path, df);
		if (df != NULL)
			return (true);
-
	}
+
	});
	/* XXX pkg dirs are terribly broken */

	/* No common paths are found in p1 and p2 */
@@ -466,20 +465,19 @@ static void
pkg_conflicts_check_chain_conflict(struct pkg_job_universe_item *it,
	struct pkg_job_universe_item *local, struct pkg_jobs *j)
{
-
	struct pkg_file *fcur, *ftmp, *ff;
+
	struct pkg_file *fcur;
	struct pkg *p;
	struct pkg_job_universe_item *cun;
	struct sipkey *k;

-
	HASH_ITER(hh, it->pkg->files, fcur, ftmp) {
+
	kh_each_value(it->pkg->files, fcur, {
		k = pkg_conflicts_sipkey_init();
		/* Check in hash tree */
		cun = pkg_conflicts_check_all_paths(j, fcur->path, it, k);

		if (local != NULL) {
			/* Filter only new files for remote packages */
-
			HASH_FIND_STR(local->pkg->files, fcur->path, ff);
-
			if (ff != NULL)
+
			if (pkg_has_file(local->pkg, fcur->path))
				continue;
		}
		/* Check for local conflict in db */
@@ -492,7 +490,7 @@ pkg_conflicts_check_chain_conflict(struct pkg_job_universe_item *it,
			assert(cun != NULL);
			pkg_conflicts_register_chain(j, it, cun, fcur->path);
		}
-
	}
+
	});
	/* XXX: dirs are currently broken terribly */
#if 0
	struct pkg_dir *dcur, *dtmp, *df;
modified libpkg/private/pkg.h
@@ -198,6 +198,7 @@ struct pkg_repo_it;
struct pkg_repo;

KHASH_MAP_INIT_STR(pkg_deps, struct pkg_dep *);
+
KHASH_MAP_INIT_STR(pkg_files, struct pkg_file *);

struct pkg {
	bool		 direct;
@@ -235,7 +236,7 @@ struct pkg {
	kh_pkg_deps_t		*rdeps;
	struct pkg_strel	*categories;
	struct pkg_strel	*licenses;
-
	struct pkg_file		*files;
+
	kh_pkg_files_t		*files;
	struct pkg_dir		*dirs;
	struct pkg_option	*options;
	struct pkg_user		*users;
@@ -294,7 +295,6 @@ struct pkg_file {
	char		 gname[MAXLOGNAME];
	mode_t		 perm;
	u_long		 fflags;
-
	UT_hash_handle	 hh;
};

struct pkg_dir {