Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Remove useless code and duplicated code
Baptiste Daroussin committed 9 years ago
commit bd5adf3b1ffcdb5eae905ac1aafd934a33b7c277
parent f95a54b
7 files changed +40 -138
modified libpkg/fetch.c
@@ -460,9 +460,9 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
	FILE		*remote = NULL;
	struct url	*u = NULL;
	struct url_stat	 st;
-
	struct keyval	*kv, *kvtmp;
-
	struct keyval	*envtorestore = NULL;
-
	struct keyval	*envtounset = NULL;
+
	struct pkg_kv	*kv, *kvtmp;
+
	struct pkg_kv	*envtorestore = NULL;
+
	struct pkg_kv	*envtounset = NULL;
	char		*tmp;
	off_t		 done = 0;
	off_t		 r;
@@ -520,12 +520,12 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
			kvtmp = xcalloc(1, sizeof(*kvtmp));
			kvtmp->key = xstrdup(kv->key);
			if ((tmp = getenv(kv->key)) != NULL) {
-
				kvtmp->val = xstrdup(tmp);
+
				kvtmp->value = xstrdup(tmp);
				LL_APPEND(envtorestore, kvtmp);
			} else {
				LL_APPEND(envtounset, kvtmp);
			}
-
			setenv(kv->key, kv->val, 1);
+
			setenv(kv->key, kv->value, 1);
		}
	}

@@ -698,17 +698,13 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
cleanup:
	if (repo != NULL) {
		LL_FOREACH_SAFE(envtorestore, kv, kvtmp) {
-
			setenv(kv->key, kv->val, 1);
+
			setenv(kv->key, kv->value, 1);
			LL_DELETE(envtorestore, kv);
-
			free(kv->key);
-
			free(kv->val);
-
			free(kv);
+
			pkg_kv_free(kv);
		}
		LL_FOREACH_SAFE(envtounset, kv, kvtmp) {
			unsetenv(kv->key);
-
			free(kv->key);
-
			free(kv->val);
-
			free(kv);
+
			pkg_kv_free(kv);
		}
	}

modified libpkg/pkg.c
@@ -641,8 +641,7 @@ pkg_adddep(struct pkg *pkg, const char *name, const char *origin, const char *ve
		}
	}

-
	pkg_dep_new(&d);
-

+
	d = xcalloc(1, sizeof(*d));
	d->origin = xstrdup(origin);
	d->name = xstrdup(name);
	if (version != NULL && version[0] != '\0')
@@ -666,8 +665,8 @@ pkg_addrdep(struct pkg *pkg, const char *name, const char *origin, const char *v
	assert(origin != NULL && origin[0] != '\0');

	pkg_debug(3, "Pkg: add a new reverse dependency origin: %s, name: %s", origin, name);
-
	pkg_dep_new(&d);

+
	d = xcalloc(1, sizeof(*d));
	d->origin = xstrdup(origin);
	d->name = xstrdup(name);
	if (version != NULL && version[0] != '\0')
@@ -711,7 +710,7 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sum,
		}
	}

-
	pkg_file_new(&f);
+
	f = xcalloc(1, sizeof(*f));
	strlcpy(f->path, path, sizeof(f->path));

	if (sum != NULL)
@@ -752,7 +751,7 @@ pkg_addconfig_file(struct pkg *pkg, const char *path, const char *content)
			pkg_emit_error("duplicate file listing: %s, ignoring", path);
		}
	}
-
	pkg_config_file_new(&f);
+
	f = xcalloc(1, sizeof(*f));
	strlcpy(f->path, path, sizeof(f->path));

	if (content != NULL)
@@ -821,7 +820,7 @@ pkg_adddir_attr(struct pkg *pkg, const char *path, const char *uname,
		}
	}

-
	pkg_dir_new(&d);
+
	d = xcalloc(1, sizeof(*d));
	strlcpy(d->path, path, sizeof(d->path));

	if (uname != NULL)
@@ -1001,7 +1000,7 @@ pkg_addoption(struct pkg *pkg, const char *key, const char *value)
	pkg_debug(2,"Pkg> adding options: %s = %s", key, value);
	HASH_FIND_STR(pkg->options, key, o);
	if (o == NULL) {
-
		pkg_option_new(&o);
+
		o = xcalloc(1, sizeof(*o));
		o->key = xstrdup(key);
	} else if ( o->value != NULL) {
		if (developer_mode) {
@@ -1037,7 +1036,7 @@ pkg_addoption_default(struct pkg *pkg, const char *key,

	HASH_FIND_STR(pkg->options, key, o);
	if (o == NULL) {
-
		pkg_option_new(&o);
+
		o = xcalloc(1, sizeof(*o));
		o->key = xstrdup(key);
	} else if ( o->default_value != NULL) {
		if (developer_mode) {
@@ -1073,7 +1072,7 @@ pkg_addoption_description(struct pkg *pkg, const char *key,

	HASH_FIND_STR(pkg->options, key, o);
	if (o == NULL) {
-
		pkg_option_new(&o);
+
		o = xcalloc(1, sizeof(*o));
		o->key = xstrdup(key);
	} else if ( o->description != NULL) {
		if (developer_mode) {
@@ -1149,7 +1148,7 @@ pkg_addconflict(struct pkg *pkg, const char *uniqueid)
	if (c != NULL)
		return (EPKG_OK);

-
	pkg_conflict_new(&c);
+
	c = xcalloc(1, sizeof(*c));
	c->uid = xstrdup(uniqueid);
	pkg_debug(3, "Pkg: add a new conflict origin: %s, with %s", pkg->uid, uniqueid);

@@ -1233,7 +1232,7 @@ pkg_kv_add(struct pkg_kv **list, const char *key, const char *val, const char *t
		}
	}

-
	pkg_kv_new(&kv, key, val);
+
	kv = pkg_kv_new(key, val);
	LL_APPEND(*list, kv);

	return (EPKG_OK);
@@ -1303,7 +1302,7 @@ pkg_list_free(struct pkg *pkg, pkg_list list) {
		pkg->flags &= ~PKG_LOAD_FILES;
		break;
	case PKG_DIRS:
-
		LL_FREE(pkg->dirs, pkg_dir_free);
+
		LL_FREE(pkg->dirs, free);
		kh_destroy_pkg_dirs(pkg->dirhash);
		pkg->flags &= ~PKG_LOAD_DIRS;
		break;
modified libpkg/pkg_attributes.c
@@ -35,14 +35,6 @@
/*
 * Dep
 */
-
int
-
pkg_dep_new(struct pkg_dep **d)
-
{
-
	*d = xcalloc(1, sizeof(struct pkg_dep));
-

-
	return (EPKG_OK);
-
}
-

void
pkg_dep_free(struct pkg_dep *d)
{
@@ -88,18 +80,6 @@ pkg_dep_is_locked(struct pkg_dep const * const d)
/*
 * File
 */
-

-
int
-
pkg_file_new(struct pkg_file **file)
-
{
-
	*file = xcalloc(1, sizeof(struct pkg_file));
-

-
	(*file)->perm = 0;
-
	(*file)->fflags = 0;
-

-
	return (EPKG_OK);
-
}
-

void
pkg_file_free(struct pkg_file *file)
{
@@ -108,27 +88,6 @@ pkg_file_free(struct pkg_file *file)
}

/*
-
 * Dir
-
 */
-

-
int
-
pkg_dir_new(struct pkg_dir **d)
-
{
-
	*d = xcalloc(1, sizeof(struct pkg_dir));
-

-
	(*d)->perm = 0;
-
	(*d)->fflags = 0;
-

-
	return (EPKG_OK);
-
}
-

-
void
-
pkg_dir_free(struct pkg_dir *d)
-
{
-
	free(d);
-
}
-

-
/*
 * Script
 */

@@ -144,15 +103,6 @@ pkg_script_get(struct pkg const * const p, pkg_script i)
/*
 * Option
 */
-

-
int
-
pkg_option_new(struct pkg_option **option)
-
{
-
	*option = xcalloc(1, sizeof(struct pkg_option));
-

-
	return (EPKG_OK);
-
}
-

void
pkg_option_free(struct pkg_option *option)
{
@@ -169,15 +119,6 @@ pkg_option_free(struct pkg_option *option)
/*
 * Conflicts
 */
-

-
int
-
pkg_conflict_new(struct pkg_conflict **c)
-
{
-
	*c = xcalloc(1, sizeof(struct pkg_conflict));
-

-
	return (EPKG_OK);
-
}
-

void
pkg_conflict_free(struct pkg_conflict *c)
{
@@ -192,14 +133,6 @@ pkg_conflict_free(struct pkg_conflict *c)
/*
 * Config files
 */
-
int
-
pkg_config_file_new(struct pkg_config_file **c)
-
{
-
	*c = xcalloc(1, sizeof(struct pkg_config_file));
-

-
	return (EPKG_OK);
-
}
-

void
pkg_config_file_free(struct pkg_config_file *c)
{
@@ -215,15 +148,16 @@ pkg_config_file_free(struct pkg_config_file *c)
 * kv
 */

-
int
-
pkg_kv_new(struct pkg_kv **c, const char *key, const char *val)
+
struct pkg_kv *
+
pkg_kv_new(const char *key, const char *val)
{
-
	*c = xcalloc(1, sizeof(struct pkg_kv));
+
	struct pkg_kv *c;

-
	(*c)->key = xstrdup(key);
-
	(*c)->value = xstrdup(val);
+
	c = xcalloc(1, sizeof(struct pkg_kv));
+
	c->key = xstrdup(key);
+
	c->value = xstrdup(val);

-
	return (EPKG_OK);
+
	return (c);
}

void
modified libpkg/pkg_config.c
@@ -509,7 +509,7 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname, pkg_ini
{
	const ucl_object_t *cur, *enabled, *env;
	ucl_object_iter_t it = NULL;
-
	struct keyval *kv;
+
	struct pkg_kv *kv;
	bool enable = true;
	const char *url = NULL, *pubkey = NULL, *mirror_type = NULL;
	const char *signature_type = NULL, *fingerprints = NULL;
@@ -681,9 +681,8 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname, pkg_ini
	if (env != NULL) {
		it = NULL;
		while ((cur = ucl_iterate_object(env, &it, true))) {
-
			kv = xcalloc(1, sizeof(*kv));
-
			kv->key = xstrdup(ucl_object_key(cur));
-
			kv->val = xstrdup(ucl_object_tostring_forced(cur));
+
			kv = pkg_kv_new(ucl_object_key(cur),
+
			    ucl_object_tostring_forced(cur));
			LL_APPEND(r->env, kv);
		}
	}
@@ -1286,7 +1285,7 @@ pkg_repo_overwrite(struct pkg_repo *r, const char *name, const char *url,
static void
pkg_repo_free(struct pkg_repo *r)
{
-
	struct keyval *kv, *tmp;
+
	struct pkg_kv *kv, *tmp;

	free(r->url);
	free(r->name);
@@ -1298,9 +1297,7 @@ pkg_repo_free(struct pkg_repo *r)
	}
	LL_FOREACH_SAFE(r->env, kv, tmp) {
		LL_DELETE(r->env, kv);
-
		free(kv->val);
-
		free(kv->key);
-
		free(kv);
+
		pkg_kv_free(kv);
	}
	free(r);
}
modified libpkg/pkg_jobs_conflicts.c
@@ -164,14 +164,8 @@ pkg_conflicts_register(struct pkg *p1, struct pkg *p2, enum pkg_conflict_type ty
{
	struct pkg_conflict *c1, *c2, *test;

-
	pkg_conflict_new(&c1);
-
	if (c1 == NULL)
-
		return;
-
	pkg_conflict_new(&c2);
-
	if (c2 == NULL) {
-
		pkg_conflict_free(c1);
-
		return;
-
	}
+
	c1 = xcalloc(1, sizeof(*c1));
+
	c2 = xcalloc(1, sizeof(*c2));

	c1->type = c2->type = type;
	HASH_FIND_STR(p1->conflicts, p2->uid, test);
@@ -266,7 +260,7 @@ pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
	HASH_FIND_STR(p2->conflicts, p1->uid, c2);

	if (c1 == NULL) {
-
		pkg_conflict_new(&c1);
+
		c1 = xcalloc(1, sizeof(*c1));
		c1->type = type;
		c1->uid = xstrdup(p2->uid);

@@ -278,7 +272,7 @@ pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
	}

	if (c2 == NULL) {
-
		pkg_conflict_new(&c2);
+
		c2 = xcalloc(1, sizeof(*c2));
		c2->type = type;

		c2->uid = xstrdup(p1->uid);
modified libpkg/pkg_repo_create.c
@@ -89,7 +89,7 @@ pkg_repo_new_conflict(const char *uniqueid, struct pkg_conflict_bulk *bulk)
{
	struct pkg_conflict *new;

-
	pkg_conflict_new(&new);
+
	new = xcalloc(1, sizeof(*new));
	new->uid = xstrdup(uniqueid);

	HASH_ADD_KEYPTR(hh, bulk->conflicts, new->uid, strlen(new->uid), new);
modified libpkg/private/pkg.h
@@ -497,12 +497,6 @@ typedef enum _pkg_repo_flags {
	REPO_FLAGS_USE_IPV6 = (1U << 1)
} pkg_repo_flags;

-
struct keyval {
-
	char *key;
-
	char *val;
-
	struct keyval *next;
-
};
-

struct pkg_repo {
	struct pkg_repo_ops *ops;

@@ -535,7 +529,7 @@ struct pkg_repo {
	unsigned int priority;

	pkg_repo_flags flags;
-
	struct keyval *env;
+
	struct pkg_kv *env;

	/* Opaque repository data */
	void *priv;
@@ -662,29 +656,17 @@ int pkg_validate(struct pkg *pkg, struct pkgdb *db);

void pkg_list_free(struct pkg *, pkg_list);

-
int pkg_kv_new(struct pkg_kv **, const char *key, const char *val);
+
struct pkg_kv *pkg_kv_new(const char *key, const char *val);
void pkg_kv_free(struct pkg_kv *);

-
int pkg_dep_new(struct pkg_dep **);
void pkg_dep_free(struct pkg_dep *);
-

-
int pkg_file_new(struct pkg_file **);
void pkg_file_free(struct pkg_file *);
-

-
int pkg_dir_new(struct pkg_dir **);
-
void pkg_dir_free(struct pkg_dir *);
-

-
int pkg_option_new(struct pkg_option **);
void pkg_option_free(struct pkg_option *);
-

-
int pkg_jobs_resolv(struct pkg_jobs *jobs);
-

-
int pkg_conflict_new(struct pkg_conflict **);
void pkg_conflict_free(struct pkg_conflict *);
-

-
int pkg_config_file_new(struct pkg_config_file **);
void pkg_config_file_free(struct pkg_config_file *);

+
int pkg_jobs_resolv(struct pkg_jobs *jobs);
+

struct packing;

int packing_init(struct packing **pack, const char *path, pkg_formats format);