db: store repository tag names including leading @

cute-signatures
Timo Teräs 2013-06-18 14:30:44 +03:00
parent af2b008bab
commit 98c6b46de6
5 changed files with 67 additions and 57 deletions

View File

@ -125,7 +125,7 @@ struct apk_db_options {
struct apk_repository_tag {
unsigned int allowed_repos;
apk_blob_t *name;
apk_blob_t tag, plain_name;
};
struct apk_database {

View File

@ -32,24 +32,13 @@ static int print_change(struct apk_database *db, struct apk_change *change,
struct apk_package *oldpkg = change->old_pkg;
struct apk_package *newpkg = change->new_pkg;
const char *msg = NULL;
char status[32], n[512], *nameptr;
char status[32];
apk_blob_t *oneversion = NULL;
int r;
snprintf(status, sizeof(status), "(%i/%i)", cur+1, total);
status[sizeof(status) - 1] = 0;
name = newpkg ? newpkg->name : oldpkg->name;
if (change->new_repository_tag > 0) {
snprintf(n, sizeof(n), "%s@" BLOB_FMT,
name->name,
BLOB_PRINTF(*db->repo_tags[change->new_repository_tag].name));
n[sizeof(n) - 1] = 0;
nameptr = n;
} else {
nameptr = name->name;
}
if (oldpkg == NULL) {
msg = "Installing";
oneversion = newpkg->version;
@ -84,12 +73,16 @@ static int print_change(struct apk_database *db, struct apk_change *change,
return FALSE;
if (oneversion) {
apk_message("%s %s %s (" BLOB_FMT ")",
status, msg, nameptr,
apk_message("%s %s %s" BLOB_FMT " (" BLOB_FMT ")",
status, msg,
name->name,
BLOB_PRINTF(db->repo_tags[change->new_repository_tag].tag),
BLOB_PRINTF(*oneversion));
} else {
apk_message("%s %s %s (" BLOB_FMT " -> " BLOB_FMT ")",
status, msg, nameptr,
apk_message("%s %s %s" BLOB_FMT " (" BLOB_FMT " -> " BLOB_FMT ")",
status, msg,
name->name,
BLOB_PRINTF(db->repo_tags[change->new_repository_tag].tag),
BLOB_PRINTF(*oldpkg->version),
BLOB_PRINTF(*newpkg->version));
}
@ -383,7 +376,7 @@ static void print_pinning_errors(struct print_state *ps, struct apk_package *pkg
for (i = 0; i < db->num_repo_tags; i++) {
if (pkg->repos & db->repo_tags[i].allowed_repos) {
label_start(ps, "masked in:");
apk_print_indented(&ps->i, *db->repo_tags[i].name);
apk_print_indented(&ps->i, db->repo_tags[i].tag);
}
}
label_end(ps);

View File

@ -907,7 +907,7 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
}
if (ipkg->repository_tag) {
apk_blob_push_blob(&bbuf, APK_BLOB_STR("s:"));
apk_blob_push_blob(&bbuf, *db->repo_tags[ipkg->repository_tag].name);
apk_blob_push_blob(&bbuf, db->repo_tags[ipkg->repository_tag].plain_name);
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
}
hlist_for_each_entry(diri, c1, &ipkg->owned_dirs, pkg_dirs_list) {
@ -1422,8 +1422,6 @@ static int add_repos_from_file(void *ctx, int dirfd, const char *file)
static void apk_db_setup_repositories(struct apk_database *db)
{
int repo_tag;
db->repos[APK_REPOSITORY_CACHED] = (struct apk_repository) {
.url = "cache",
.csum.data = {
@ -1437,8 +1435,8 @@ static void apk_db_setup_repositories(struct apk_database *db)
db->available_repos |= BIT(APK_REPOSITORY_CACHED);
/* Get first repository tag (the NULL tag) */
repo_tag = apk_db_get_tag_id(db, APK_BLOB_NULL);
db->repo_tags[repo_tag].allowed_repos |= BIT(APK_REPOSITORY_CACHED);
db->repo_tags[APK_DEFAULT_REPOSITORY_TAG].allowed_repos |= BIT(APK_REPOSITORY_CACHED);
db->num_repo_tags = 1;
}
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
@ -1773,21 +1771,38 @@ void apk_db_close(struct apk_database *db)
int apk_db_get_tag_id(struct apk_database *db, apk_blob_t tag)
{
apk_blob_t *b = apk_blob_atomize_dup(tag);
int i;
for (i = 0; i < db->num_repo_tags; i++) {
if (db->repo_tags[i].name == b)
return i;
if (APK_BLOB_IS_NULL(tag))
return APK_DEFAULT_REPOSITORY_TAG;
if (tag.ptr[0] == '@') {
for (i = 1; i < db->num_repo_tags; i++)
if (apk_blob_compare(db->repo_tags[i].tag, tag) == 0)
return i;
} else {
for (i = 1; i < db->num_repo_tags; i++)
if (apk_blob_compare(db->repo_tags[i].plain_name, tag) == 0)
return i;
}
if (i < ARRAY_SIZE(db->repo_tags)) {
db->num_repo_tags++;
db->repo_tags[i] = (struct apk_repository_tag) {
.name = b
};
return i;
if (i >= ARRAY_SIZE(db->repo_tags))
return -1;
db->num_repo_tags++;
if (tag.ptr[0] == '@') {
db->repo_tags[i].tag = *apk_blob_atomize_dup(tag);
} else {
char *tmp = alloca(tag.len + 1);
tmp[0] = '@';
memcpy(&tmp[1], tag.ptr, tag.len);
db->repo_tags[i].tag = *apk_blob_atomize_dup(APK_BLOB_PTR_LEN(tmp, tag.len+1));
}
return -1;
db->repo_tags[i].plain_name = db->repo_tags[i].tag;
apk_blob_pull_char(&db->repo_tags[i].plain_name, '@');
return i;
}
static int fire_triggers(apk_hash_item item, void *ctx)
@ -1896,10 +1911,10 @@ int apk_db_check_world(struct apk_database *db, struct apk_dependency_array *wor
tag = dep->repository_tag;
if (tag == 0 || db->repo_tags[tag].allowed_repos != 0)
continue;
apk_warning("The repository tag for world dependency '%s@" BLOB_FMT "' does not exist",
dep->name->name,
BLOB_PRINTF(*db->repo_tags[tag].name));
if (tag < 0)
tag = 0;
apk_warning("The repository tag for world dependency '%s" BLOB_FMT "' does not exist",
dep->name->name, BLOB_PRINTF(db->repo_tags[tag].tag));
bad++;
}
@ -2066,7 +2081,6 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository)
return 0;
if (brepo.ptr[0] == '@') {
apk_blob_pull_char(&brepo, '@');
apk_blob_cspn(brepo, apk_spn_repo_separators, &btag, &brepo);
apk_blob_spn(brepo, apk_spn_repo_separators, NULL, &brepo);
tag_id = apk_db_get_tag_id(db, btag);

View File

@ -38,6 +38,10 @@ static const apk_spn_match_def apk_spn_dependency_separator = {
[4] = (1<<0) /* */,
};
static const apk_spn_match_def apk_spn_repotag_separator = {
[8] = (1<<0) /*@*/
};
struct apk_package *apk_pkg_get_installed(struct apk_name *name)
{
struct apk_provider *p;
@ -241,7 +245,7 @@ void apk_blob_pull_dep(apk_blob_t *b, struct apk_database *db, struct apk_depend
bver = APK_BLOB_NULL;
}
if (apk_blob_split(bname, APK_BLOB_STR("@"), &bname, &btag))
if (apk_blob_cspn(bname, apk_spn_repotag_separator, &bname, &btag))
tag = apk_db_get_tag_id(db, btag);
/* convert to apk_dependency */
@ -385,10 +389,8 @@ void apk_blob_push_dep(apk_blob_t *to, struct apk_database *db, struct apk_depen
apk_blob_push_blob(to, APK_BLOB_PTR_LEN("!", 1));
apk_blob_push_blob(to, APK_BLOB_STR(dep->name->name));
if (dep->repository_tag && db != NULL) {
apk_blob_push_blob(to, APK_BLOB_PTR_LEN("@", 1));
apk_blob_push_blob(to, *db->repo_tags[dep->repository_tag].name);
}
if (dep->repository_tag && db != NULL)
apk_blob_push_blob(to, db->repo_tags[dep->repository_tag].tag);
if (!APK_BLOB_IS_NULL(*dep->version)) {
apk_blob_push_blob(to, APK_BLOB_STR(apk_version_op_string(result_mask)));
apk_blob_push_blob(to, *dep->version);

View File

@ -101,7 +101,7 @@ static void ver_print_package_status(struct apk_database *db, const char *match,
struct ver_ctx *ctx = (struct ver_ctx *) pctx;
struct apk_package *pkg;
struct apk_provider *p0;
char pkgname[256];
char pkgname[41];
const char *opstr;
apk_blob_t *latest = apk_blob_atomize(APK_BLOB_STR(""));
unsigned int latest_repos = 0;
@ -119,7 +119,7 @@ static void ver_print_package_status(struct apk_database *db, const char *match,
struct apk_package *pkg0 = p0->pkg;
if (pkg0->name != name || pkg0->repos == 0)
continue;
if (!(ctx->all_tags || (pkg0->repos & allowed_repos)))
if (!(ctx->all_tags || (pkg0->repos & allowed_repos)))
continue;
r = apk_version_compare_blob(*pkg0->version, *latest);
switch (r) {
@ -141,19 +141,20 @@ static void ver_print_package_status(struct apk_database *db, const char *match,
printf("%s\n", pkg->name->name);
return;
}
snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT, PKG_VER_PRINTF(pkg));
printf("%-40s%s " BLOB_FMT, pkgname, opstr, BLOB_PRINTF(*latest));
if (!(latest_repos & db->repo_tags[APK_DEFAULT_REPOSITORY_TAG].allowed_repos)) {
for (i = 1; i < db->num_repo_tags; i++) {
if (!(latest_repos & db->repo_tags[i].allowed_repos))
continue;
if (!(ctx->all_tags || i == tag))
continue;
printf(" @" BLOB_FMT,
BLOB_PRINTF(*db->repo_tags[i].name));
tag = APK_DEFAULT_REPOSITORY_TAG;
for (i = 1; i < db->num_repo_tags; i++) {
if (latest_repos & db->repo_tags[i].allowed_repos) {
tag = i;
break;
}
}
printf("\n");
snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT, PKG_VER_PRINTF(pkg));
printf("%-40s%s " BLOB_FMT " " BLOB_FMT "\n",
pkgname, opstr,
BLOB_PRINTF(*latest),
BLOB_PRINTF(db->repo_tags[tag].tag));
}
static int ver_main(void *pctx, struct apk_database *db, struct apk_string_array *args)