Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Allow a package to only track a repository
Baptiste Daroussin committed 12 years ago
commit 7f4c904874db4399d68b4c1e156b9902abf1b499
parent d692161
5 files changed +87 -60
modified libpkg/pkg.c
@@ -905,6 +905,19 @@ pkg_addannotation(struct pkg *pkg, const char *tag, const char *value)
	return (EPKG_OK);
}

+
struct pkg_note *
+
pkg_annotation_lookup(const struct pkg *pkg, const char *tag)
+
{
+
	struct pkg_note *an = NULL;
+

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

+
	HASH_FIND_STR(pkg->annotations, __DECONST(char *, tag), an);
+

+
	return (an);
+
}
+

int
pkg_delannotation(struct pkg *pkg, const char *tag)
{
modified libpkg/pkg.h.in
@@ -599,6 +599,8 @@ int pkg_shlibs_provided(const struct pkg *pkg, struct pkg_shlib **shlib);
 */
int pkg_annotations(const struct pkg *pkg, struct pkg_note **note);

+
struct pkg_note *pkg_annotation_lookup(const struct pkg *p, const char *tag);
+

/**
 * Iterate over all of the files within the package pkg, ensuring the
 * dependency list contains all applicable packages providing the
@@ -983,12 +985,12 @@ struct pkgdb_it * pkgdb_query_shlib_provided(struct pkgdb *db, const char *shlib
 * @param value -- text of the annotation
 * @return An error code
 */
-
int pkgdb_add_annotation(struct pkgdb *db, const char *pkgname,
-
	const char *pkgversion, const char *tag, const char *value);
-
int pkgdb_modify_annotation(struct pkgdb *db, const char *pkgname,
-
	const char *pkgversion, const char *tag, const char *value);
-
int pkgdb_delete_annotation(struct pkgdb *db, const char *pkgname,
-
        const char *pkgversion, const char *tag);
+
int pkgdb_add_annotation(struct pkgdb *db, const char *pkgorigin,
+
	const char *tag, const char *value);
+
int pkgdb_modify_annotation(struct pkgdb *db, const char *pkgorigin,
+
	const char *tag, const char *value);
+
int pkgdb_delete_annotation(struct pkgdb *db, const char *pkgorigin,
+
        const char *tag);

#define PKG_LOAD_BASIC			0
#define PKG_LOAD_DEPS			(1U << 0)
modified libpkg/pkg_jobs.c
@@ -535,7 +535,7 @@ get_remote_pkg(struct pkg_jobs *j, const char *pattern, match_t m, bool root)
	const char *buf1, *buf2;
	bool force = false;
	int rc = EPKG_FATAL;
-
	unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_SHLIBS_REQUIRED;
+
	unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_ANNOTATIONS;

	if (root && (j->flags & PKG_FLAG_FORCE) == PKG_FLAG_FORCE)
		force = true;
@@ -611,7 +611,7 @@ get_local_pkg(struct pkg_jobs *j, const char *origin, unsigned flag)
	struct pkgdb_it *it;

	if (flag == 0) {
-
		flag = PKG_LOAD_BASIC|PKG_LOAD_DEPS|PKG_LOAD_OPTIONS|PKG_LOAD_SHLIBS_REQUIRED;
+
		flag = PKG_LOAD_BASIC|PKG_LOAD_DEPS|PKG_LOAD_OPTIONS|PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_ANNOTATIONS;
	}

	if ((it = pkgdb_query(j->db, origin, MATCH_EXACT)) == NULL)
@@ -628,7 +628,8 @@ get_local_pkg(struct pkg_jobs *j, const char *origin, unsigned flag)
static bool
newer_than_local_pkg(struct pkg_jobs *j, struct pkg *rp, bool force)
{
-
	char *origin, *newversion, *oldversion;
+
	char *origin, *newversion, *oldversion, *reponame;
+
	struct pkg_note *an;
	int64_t oldsize;
	struct pkg *lp;
	struct pkg_option *lo = NULL, *ro = NULL;
@@ -637,7 +638,8 @@ newer_than_local_pkg(struct pkg_jobs *j, struct pkg *rp, bool force)
	bool automatic, locked;
	int cmp = 0, ret1, ret2;

-
	pkg_get(rp, PKG_ORIGIN, &origin);
+
	pkg_get(rp, PKG_ORIGIN, &origin,
+
	    PKG_REPONAME, &reponame);
	lp = get_local_pkg(j, origin, 0);

	/* obviously yes because local doesn't exists */
@@ -651,6 +653,17 @@ newer_than_local_pkg(struct pkg_jobs *j, struct pkg *rp, bool force)
	    PKG_VERSION, &oldversion,
	    PKG_FLATSIZE, &oldsize);

+
	an = pkg_annotation_lookup(lp, "repository");
+
	if (an != NULL)  {
+
		if (strcmp(pkg_repo_ident(pkg_repo_find_name(reponame)),
+
		    pkg_annotation_value(an)) != 0)  {
+
			pkg_free(lp);
+
			return (false);
+
		} else {
+
			pkg_addannotation(rp, "repository", pkg_annotation_value(an));
+
		}
+
	}
+

	if (locked) {
		pkg_free(lp);
		return (false);
@@ -973,11 +986,13 @@ pkg_jobs_install(struct pkg_jobs *j)

	while (pkg_jobs(j, &p) == EPKG_OK) {
		const char *pkgorigin, *pkgrepopath, *oldversion, *origin;
+
		struct pkg_note *an;
		bool automatic, locked;
		flags = 0;

		pkg_get(p, PKG_ORIGIN, &pkgorigin, PKG_REPOPATH, &pkgrepopath,
		    PKG_OLD_VERSION, &oldversion, PKG_AUTOMATIC, &automatic);
+
		an = pkg_annotation_lookup(p, "repository");

		if (oldversion != NULL) {
			pkg = NULL;
@@ -1083,6 +1098,10 @@ pkg_jobs_install(struct pkg_jobs *j)
			goto cleanup;
		}

+
		if (an != NULL) {
+
			pkgdb_add_annotation(j->db, pkgorigin, "repository", pkg_annotation_value(an));
+
		}
+

		if (oldversion != NULL)
			pkg_emit_upgrade_finished(p);
		else
modified libpkg/pkgdb.c
@@ -2230,18 +2230,18 @@ static sql_prstmt sql_prepared_statements[PRSTMT_LAST] = {
		NULL,
		"INSERT OR IGNORE INTO pkg_annotation(package_id, tag_id, value_id) "
		"VALUES ("
-
		" (SELECT id FROM packages WHERE name = ?1 AND version = ?2),"
-
		" (SELECT annotation_id FROM annotation WHERE annotation = ?3),"
-
		" (SELECT annotation_id FROM annotation WHERE annotation = ?4))",
+
		" (SELECT id FROM packages WHERE origin = ?1 ),"
+
		" (SELECT annotation_id FROM annotation WHERE annotation = ?2),"
+
		" (SELECT annotation_id FROM annotation WHERE annotation = ?3))",
		"TTTT",
	},
	[ANNOTATE_DEL1] = {
		NULL,
		"DELETE FROM pkg_annotation WHERE "
		"package_id IN"
-
                " (SELECT id FROM packages WHERE name = ?1 AND version = ?2) "
+
                " (SELECT id FROM packages WHERE origin = ?1) "
		"AND tag_id IN"
-
		" (SELECT annotation_id FROM annotation WHERE annotation = ?3)",
+
		" (SELECT annotation_id FROM annotation WHERE annotation = ?2)",
		"TTT",
	},
	[ANNOTATE_DEL2] = {
@@ -2763,27 +2763,23 @@ pkgdb_reanalyse_shlibs(struct pkgdb *db, struct pkg *pkg)
}

int
-
pkgdb_add_annotation(struct pkgdb *db, const char *pkgname,
-
    const char *pkgversion, const char *tag, const char *value)
+
pkgdb_add_annotation(struct pkgdb *db, const char *pkgorigin,
+
    const char *tag, const char *value)
{
	int	rows_changed;

-
	assert(pkgname != NULL && pkgname[0] != '\0');
-
	assert(pkgversion != NULL && pkgversion[0] != '\0');
+
	assert(pkgorigin != NULL && pkgorigin[0] != '\0');
	assert(tag != NULL);
	assert(value != NULL);

	if (!db->prstmt_initialized && prstmt_initialize(db) != EPKG_OK)
		return (EPKG_FATAL);

-
	if (pkgdb_transaction_begin(db->sqlite, NULL) != EPKG_OK)
-
		return (EPKG_FATAL);
-

	if (run_prstmt(ANNOTATE1, tag) != SQLITE_DONE
	    ||
	    run_prstmt(ANNOTATE1, value) != SQLITE_DONE
	    ||
-
	    run_prstmt(ANNOTATE_ADD1, pkgname, pkgversion, tag, value)
+
	    run_prstmt(ANNOTATE_ADD1, pkgorigin, tag, value)
	    != SQLITE_DONE) {
		ERROR_SQLITE(db->sqlite);
		pkgdb_transaction_rollback(db->sqlite, NULL);
@@ -2795,20 +2791,16 @@ pkgdb_add_annotation(struct pkgdb *db, const char *pkgname,

	rows_changed = sqlite3_changes(db->sqlite);

-
	if (pkgdb_transaction_commit(db->sqlite, NULL) != EPKG_OK)
-
		return (EPKG_FATAL);
-

	return (rows_changed == 1 ? EPKG_OK : EPKG_WARN);
}

int
-
pkgdb_modify_annotation(struct pkgdb *db, const char *pkgname,
-
    const char *pkgversion, const char *tag, const char *value)
+
pkgdb_modify_annotation(struct pkgdb *db, const char *pkgorigin,
+
    const char *tag, const char *value)
{
	int rows_changed; 

-
	assert(pkgname != NULL && pkgname[0] != '\0');
-
	assert(pkgversion != NULL && pkgversion[0] != '\0');
+
	assert(pkgorigin != NULL && pkgorigin[0] != '\0');
	assert(tag != NULL);
	assert(value != NULL);

@@ -2818,18 +2810,19 @@ pkgdb_modify_annotation(struct pkgdb *db, const char *pkgname,
	if (pkgdb_transaction_begin(db->sqlite, NULL) != EPKG_OK)
		return (EPKG_FATAL);

-
	if (run_prstmt(ANNOTATE_DEL1, pkgname, pkgversion, tag) != SQLITE_DONE
+
	if (run_prstmt(ANNOTATE_DEL1, pkgorigin, tag) != SQLITE_DONE
	    ||
	    run_prstmt(ANNOTATE1, tag) != SQLITE_DONE
	    ||
	    run_prstmt(ANNOTATE1, value) != SQLITE_DONE
	    ||
-
	    run_prstmt(ANNOTATE_ADD1, pkgname, pkgversion, tag, value) !=
+
	    run_prstmt(ANNOTATE_ADD1, pkgorigin, tag, value) !=
	        SQLITE_DONE
	    ||
	    run_prstmt(ANNOTATE_DEL2) != SQLITE_DONE) {
		ERROR_SQLITE(db->sqlite);
		pkgdb_transaction_rollback(db->sqlite, NULL);
+

		return (EPKG_FATAL);
	}

@@ -2844,14 +2837,13 @@ pkgdb_modify_annotation(struct pkgdb *db, const char *pkgname,
}

int
-
pkgdb_delete_annotation(struct pkgdb *db, const char *pkgname,
-
    const char *pkgversion, const char *tag)
+
pkgdb_delete_annotation(struct pkgdb *db, const char *pkgorigin,
+
    const char *tag)
{
	int	rows_changed;
	bool	result;

-
	assert(pkgname != NULL && pkgname[0] != '\0');
-
	assert(pkgversion != NULL && pkgversion[0] != '\0');
+
	assert(pkgorigin != NULL && pkgorigin[0] != '\0');
	assert(tag != NULL);

	if (!db->prstmt_initialized && prstmt_initialize(db) != EPKG_OK)
@@ -2860,7 +2852,7 @@ pkgdb_delete_annotation(struct pkgdb *db, const char *pkgname,
	if (pkgdb_transaction_begin(db->sqlite, NULL) != EPKG_OK)
		return (EPKG_FATAL);

-
	result = (run_prstmt(ANNOTATE_DEL1, pkgname, pkgversion, tag)
+
	result = (run_prstmt(ANNOTATE_DEL1, pkgorigin, tag)
		  == SQLITE_DONE);

	rows_changed = sqlite3_changes(db->sqlite);
modified pkg/annotate.c
@@ -63,43 +63,44 @@ usage_annotate(void)
}

static int
-
do_add(struct pkgdb *db, const char *pkgname, const char *pkgversion,
-
       const char *tag, const char *value)
+
do_add(struct pkgdb *db, struct pkg *pkg, const char *tag, const char *value)
{
-
	int	 ret = EPKG_OK;
+
	const char	*pkgname, *pkgversion, *pkgorigin;
+
	int		 ret = EPKG_OK;
+

+
	pkg_get(pkg, PKG_NAME, &pkgname, PKG_VERSION, &pkgversion, PKG_ORIGIN, &pkgorigin);

	if (yes || query_tty_yesno("%s-%s: Add annotation tagged: %s with "
	               "value: %s? [y/N]: ", pkgname, pkgversion,
                       tag, value)) {
-
		ret = pkgdb_add_annotation(db, pkgname, pkgversion,
-
                          tag, value);
+
		ret = pkgdb_add_annotation(db, pkgorigin, tag, value);
		if (ret == EPKG_OK) {
			if (!quiet)
				printf("%s-%s: added annotation tagged: %s\n",
-
				     pkgname, pkgversion, tag);
+
				    pkgname, pkgversion, tag);
		} else if (ret == EPKG_WARN) {
			if (!quiet)
				warnx("%s-%s: Can't add annotation tagged: %s -- "
-
				     "already exists", pkgname, pkgversion,
-
				     tag );
+
				    "already exists", pkgname, pkgversion, tag);
		} else
			warnx("%s-%s: Failed to add annotation tagged: %s",
-
			     pkgname, pkgversion, tag);
+
			    pkgname, pkgversion, tag);
	}
	return (ret);
}

static int
-
do_modify(struct pkgdb *db, const char *pkgname, const char *pkgversion,
-
	  const char *tag, const char *value)
+
do_modify(struct pkgdb *db, struct pkg *pkg, const char *tag, const char *value)
{
-
	int	ret = EPKG_OK;
+
	const char	*pkgname, *pkgversion, *pkgorigin;
+
	int		 ret = EPKG_OK;
+

+
	pkg_get(pkg, PKG_NAME, &pkgname, PKG_VERSION, &pkgversion, PKG_ORIGIN, &pkgorigin);

	if (yes || query_tty_yesno("%s-%s: Change annotation tagged: %s to "
		         "new value: %s? [y/N]: ",
			 pkgname, pkgversion, tag, value)) {
-
		ret = pkgdb_modify_annotation(db, pkgname, pkgversion,
-
                          tag, value);
+
		ret = pkgdb_modify_annotation(db, pkgorigin, tag, value);
		if (ret == EPKG_OK || ret == EPKG_WARN) {
			if (!quiet)
				printf("%s-%s: Modified annotation tagged: "
@@ -112,14 +113,16 @@ do_modify(struct pkgdb *db, const char *pkgname, const char *pkgversion,
} 

static int
-
do_delete(struct pkgdb *db, const char *pkgname, const char *pkgversion,
-
	  const char *tag)
+
do_delete(struct pkgdb *db, struct pkg *pkg, const char *tag)
{
-
	int	ret = EPKG_OK;
+
	const char	*pkgname, *pkgversion, *pkgorigin;
+
	int		 ret = EPKG_OK;
+

+
	pkg_get(pkg, PKG_NAME, &pkgname, PKG_VERSION, &pkgversion, PKG_ORIGIN, &pkgorigin);

	if (yes || query_tty_yesno("%s-%s: Delete annotation tagged: %s [y/N]: ",
			 pkgname, pkgversion, tag)) {
-
		ret = pkgdb_delete_annotation(db, pkgname, pkgversion, tag);
+
		ret = pkgdb_delete_annotation(db, pkgorigin, tag);
		if (ret == EPKG_OK) {
			if (!quiet)
				printf("%s-%s: Deleted annotation tagged: %s\n",
@@ -170,7 +173,6 @@ exec_annotate(int argc, char **argv)
	const char	*tag;
	const char	*value;
	const char	*pkgname;
-
	const char	*pkgversion;
	struct sbuf	*input    = NULL;
	int		 ch;
	int		 match    = MATCH_EXACT;
@@ -272,7 +274,6 @@ exec_annotate(int argc, char **argv)
	}

	while ((retcode = pkgdb_it_next(it, &pkg, 0)) == EPKG_OK) {
-
		pkg_get(pkg, PKG_NAME, &pkgname, PKG_VERSION, &pkgversion);

		switch(action) {
		case NONE:	/* Should never happen */
@@ -280,13 +281,13 @@ exec_annotate(int argc, char **argv)
			exitcode = EX_USAGE;
			break;
		case ADD:
-
			retcode = do_add(db, pkgname, pkgversion, tag, value);
+
			retcode = do_add(db, pkg, tag, value);
			break;
		case MODIFY:
-
			retcode = do_modify(db, pkgname, pkgversion, tag, value);
+
			retcode = do_modify(db, pkg, tag, value);
			break;
		case DELETE:
-
			retcode = do_delete(db, pkgname, pkgversion, tag);
+
			retcode = do_delete(db, pkg, tag);
			break;
		}