summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-18 14:30:44 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-18 14:30:44 +0300
commit98c6b46de6d5074235e80617fd03c9e15cdd16e2 (patch)
treea4d219fa30071bdfcaa430b36cacd2d0d159b3d2 /src
parentaf2b008bab6923f8b9582e68686826825d9e29a9 (diff)
downloadapk-tools-98c6b46de6d5074235e80617fd03c9e15cdd16e2.tar.gz
apk-tools-98c6b46de6d5074235e80617fd03c9e15cdd16e2.tar.bz2
apk-tools-98c6b46de6d5074235e80617fd03c9e15cdd16e2.tar.xz
apk-tools-98c6b46de6d5074235e80617fd03c9e15cdd16e2.zip
db: store repository tag names including leading @
Diffstat (limited to 'src')
-rw-r--r--src/apk_database.h2
-rw-r--r--src/commit.c27
-rw-r--r--src/database.c56
-rw-r--r--src/package.c12
-rw-r--r--src/ver.c27
5 files changed, 67 insertions, 57 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index a47586b..f3f7b7b 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -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 {
diff --git a/src/commit.c b/src/commit.c
index 01ac4a8..4c6e53a 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -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);
diff --git a/src/database.c b/src/database.c
index 1d10d59..23da6af 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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);
diff --git a/src/package.c b/src/package.c
index fcfdd00..f38a57e 100644
--- a/src/package.c
+++ b/src/package.c
@@ -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);
diff --git a/src/ver.c b/src/ver.c
index ed1719d..a4ebc5c 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -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)