Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add utilities for repo iterators.
Vsevolod Stakhov committed 11 years ago
commit cb100b69a093f1bbda2e7f3700cdc83bff300cfa
parent d8dae8f
3 files changed +67 -38
modified libpkg/pkgdb_iterator.c
@@ -742,34 +742,6 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
	}
}

-
struct pkgdb_it *
-
pkgdb_it_new_sqlite(struct pkgdb *db, sqlite3_stmt *s, int type, short flags)
-
{
-
	struct pkgdb_it	*it;
-

-
	assert(db != NULL && s != NULL);
-
	assert(!(flags & (PKGDB_IT_FLAG_CYCLED & PKGDB_IT_FLAG_ONCE)));
-
	assert(!(flags & (PKGDB_IT_FLAG_AUTO & (PKGDB_IT_FLAG_CYCLED | PKGDB_IT_FLAG_ONCE))));
-

-
	if ((it = malloc(sizeof(struct pkgdb_it))) == NULL) {
-
		pkg_emit_errno("malloc", "pkgdb_it");
-
		sqlite3_finalize(s);
-
		return (NULL);
-
	}
-

-
	it->type = PKGDB_IT_LOCAL;
-

-
	it->db = db;
-
	it->un.local.sqlite = db->sqlite;
-
	it->un.local.stmt = s;
-
	it->un.local.pkg_type = type;
-

-
	it->un.local.flags = flags;
-
	it->un.local.finished = 0;
-

-
	return (it);
-
}
-

static struct load_on_flag {
	int	flag;
	int	(*load)(struct pkgdb *db, struct pkg *p);
@@ -964,3 +936,64 @@ pkgdb_it_free(struct pkgdb_it *it)

	free(it);
}
+

+
struct pkgdb_it *
+
pkgdb_it_new_sqlite(struct pkgdb *db, sqlite3_stmt *s, int type, short flags)
+
{
+
	struct pkgdb_it	*it;
+

+
	assert(db != NULL && s != NULL);
+
	assert(!(flags & (PKGDB_IT_FLAG_CYCLED & PKGDB_IT_FLAG_ONCE)));
+
	assert(!(flags & (PKGDB_IT_FLAG_AUTO & (PKGDB_IT_FLAG_CYCLED | PKGDB_IT_FLAG_ONCE))));
+

+
	if ((it = malloc(sizeof(struct pkgdb_it))) == NULL) {
+
		pkg_emit_errno("malloc", "pkgdb_it");
+
		sqlite3_finalize(s);
+
		return (NULL);
+
	}
+

+
	it->type = PKGDB_IT_LOCAL;
+

+
	it->db = db;
+
	it->un.local.sqlite = db->sqlite;
+
	it->un.local.stmt = s;
+
	it->un.local.pkg_type = type;
+

+
	it->un.local.flags = flags;
+
	it->un.local.finished = 0;
+

+
	return (it);
+
}
+

+
struct pkgdb_it *
+
pkgdb_it_new_repo(struct pkgdb *db)
+
{
+
	struct pkgdb_it	*it;
+

+
	if ((it = malloc(sizeof(struct pkgdb_it))) == NULL) {
+
		pkg_emit_errno("malloc", "pkgdb_it");
+
		return (NULL);
+
	}
+

+
	it->type = PKGDB_IT_REPO;
+

+
	it->db = db;
+

+
	it->un.remote = NULL;
+

+
	return (it);
+
}
+

+
void
+
pkgdb_it_repo_attach(struct pkgdb_it *it, struct pkg_repo_it *rit)
+
{
+
	struct _pkg_repo_it_set *item;
+

+
	if ((item = malloc(sizeof(struct _pkg_repo_it_set))) == NULL) {
+
		pkg_emit_errno("malloc", "_pkg_repo_it_set");
+
	}
+
	else {
+
		item->it = rit;
+
		LL_PREPEND(it->un.remote, item);
+
	}
+
}
modified libpkg/private/pkg.h
@@ -332,7 +332,8 @@ struct pkg_remote_it_ops {
struct pkg_repo_it {
	struct pkg_repo *repo;
	struct pkg_remote_it_ops *ops;
-
	char data[0];
+
	int flags;
+
	void *data;
};

struct pkg_repo_ops {
modified libpkg/private/pkgdb.h
@@ -85,7 +85,10 @@ int pkgdb_transaction_begin(sqlite3 *sqlite, const char *savepoint);
int pkgdb_transaction_commit(sqlite3 *sqlite, const char *savepoint);
int pkgdb_transaction_rollback(sqlite3 *sqlite, const char *savepoint);

-
struct pkgdb_it *pkgdb_it_new_sqlite(struct pkgdb *db, sqlite3_stmt *s, int type, short flags);
+
struct pkgdb_it *pkgdb_it_new_sqlite(struct pkgdb *db, sqlite3_stmt *s,
+
	int type, short flags);
+
struct pkgdb_it *pkgdb_it_new_repo(struct pkgdb *db);
+
void pkgdb_it_repo_attach(struct pkgdb_it *it, struct pkg_repo_it *rit);

void pkgshell_open(const char **r);

@@ -109,14 +112,6 @@ int pkgdb_repo_register_conflicts(const char *origin, char **conflicts,
const char * pkgdb_get_pattern_query(const char *pattern, match_t match);

/**
-
 * Returns whether the specified database is attached
-
 * @param s
-
 * @param name
-
 * @return
-
 */
-
bool pkgdb_is_attached(sqlite3 *s, const char *name);
-

-
/**
 * Find provides for a specified require in repos
 * @param db
 * @param provide