aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gentoo.org>2014-02-27 20:42:32 -0800
committerMike Frysinger <vapier@gentoo.org>2014-02-27 20:42:32 -0800
commitfbb0a3f0e5e6ed695e1bca9a47ff34131a776aaf (patch)
tree27863a1b5871c9b9ea3d1a836aaaa82504cf7300
parentvdb: add a q_vdb_pkg_eat helper to unify various call styles (diff)
downloadportage-utils-fbb0a3f0e5e6ed695e1bca9a47ff34131a776aaf.tar.gz
portage-utils-fbb0a3f0e5e6ed695e1bca9a47ff34131a776aaf.tar.bz2
portage-utils-fbb0a3f0e5e6ed695e1bca9a47ff34131a776aaf.zip
qlist: add ::repo support for package listing and atom matching
-rw-r--r--Makefile.am8
-rw-r--r--libq/atom_compare.c6
-rw-r--r--libq/atom_explode.c8
-rw-r--r--libq/vdb.c6
-rw-r--r--qlist.c95
-rwxr-xr-xtests/qlist/dotest9
-rw-r--r--tests/qlist/list11.good5
-rw-r--r--tests/qlist/list12.good5
-rw-r--r--tests/qlist/list13.good8
-rw-r--r--tests/qlist/root/a-b/a-0/repository1
-rw-r--r--tests/qlist/root/a-b/b-0/repository1
-rw-r--r--tests/qlist/root/app-arch/cpio-2.11/repository1
-rw-r--r--tests/qlist/root/cat/pkg-1/repository1
-rw-r--r--tests/qlist/root/sys-fs/mtools-4.0.13/repository1
14 files changed, 125 insertions, 30 deletions
diff --git a/Makefile.am b/Makefile.am
index 531c7a0..ed5c184 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -194,17 +194,25 @@ EXTRA_DIST += \
tests/qlist/list08.good \
tests/qlist/list09.good \
tests/qlist/list10.good \
+ tests/qlist/list11.good \
+ tests/qlist/list12.good \
+ tests/qlist/list13.good \
tests/qlist/root/-merge-foo/CONTENTS \
tests/qlist/root/a-b/a-0/CONTENTS \
tests/qlist/root/a-b/a-0/SLOT \
+ tests/qlist/root/a-b/a-0/repository \
tests/qlist/root/a-b/b-0/CONTENTS \
tests/qlist/root/a-b/b-0/SLOT \
+ tests/qlist/root/a-b/b-0/repository \
tests/qlist/root/app-arch/cpio-2.11/CONTENTS \
tests/qlist/root/app-arch/cpio-2.11/SLOT \
+ tests/qlist/root/app-arch/cpio-2.11/repository \
tests/qlist/root/cat/pkg-1/CONTENTS \
tests/qlist/root/cat/pkg-1/SLOT \
+ tests/qlist/root/cat/pkg-1/repository \
tests/qlist/root/sys-fs/mtools-4.0.13/CONTENTS \
tests/qlist/root/sys-fs/mtools-4.0.13/SLOT \
+ tests/qlist/root/sys-fs/mtools-4.0.13/repository \
tests/qmerge/Makefile \
tests/qmerge/dotest \
tests/qmerge/packages/Packages \
diff --git a/libq/atom_compare.c b/libq/atom_compare.c
index 65bb043..dbea5b3 100644
--- a/libq/atom_compare.c
+++ b/libq/atom_compare.c
@@ -60,6 +60,12 @@ static int atom_compare(const depend_atom *a1, const depend_atom *a2)
return NOT_EQUAL;
}
+ /* check repo */
+ if (a1->REPO || a2->REPO) {
+ if (!a1->REPO || !a2->REPO || strcmp(a1->REPO, a2->REPO))
+ return NOT_EQUAL;
+ }
+
/* Check category, iff both are specified. This way we can match
* atoms like "sys-devel/gcc" and "gcc".
*/
diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index a674197..daa18ac 100644
--- a/libq/atom_explode.c
+++ b/libq/atom_explode.c
@@ -37,7 +37,7 @@ typedef struct {
char letter;
atom_suffix *suffixes;
char *PV, *PVR;
- char *P, *SLOT;
+ char *P, *SLOT, *REPO;
} depend_atom;
#ifdef _USE_CACHE
@@ -115,6 +115,12 @@ depend_atom *atom_explode(const char *atom)
if ((ptr = strstr(ret->CATEGORY, ".ebuild")) != NULL)
*ptr = '\0';
+ /* chip off the trailing [::REPO] as needed */
+ if ((ptr = strstr(ret->CATEGORY, "::")) != NULL) {
+ ret->REPO = ptr + 2;
+ *ptr = '\0';
+ }
+
/* chip off the trailing [:SLOT] as needed */
if ((ptr = strrchr(ret->CATEGORY, ':')) != NULL) {
ret->SLOT = ptr + 1;
diff --git a/libq/vdb.c b/libq/vdb.c
index dda5e2c..44ebf9e 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -170,8 +170,8 @@ _q_static void q_vdb_close_cat(q_vdb_cat_ctx *cat_ctx)
typedef struct {
const char *name;
- char *slot;
- size_t slot_len;
+ char *slot, *repo;
+ size_t slot_len, repo_len;
int fd;
q_vdb_cat_ctx *cat_ctx;
} q_vdb_pkg_ctx;
@@ -196,6 +196,7 @@ _q_static q_vdb_pkg_ctx *q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name
q_vdb_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
pkg_ctx->name = name;
pkg_ctx->slot = NULL;
+ pkg_ctx->repo = NULL;
pkg_ctx->fd = -1;
pkg_ctx->cat_ctx = cat_ctx;
return pkg_ctx;
@@ -266,6 +267,7 @@ _q_static void q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx)
if (pkg_ctx->fd != -1)
close(pkg_ctx->fd);
free(pkg_ctx->slot);
+ free(pkg_ctx->repo);
free(pkg_ctx);
}
diff --git a/qlist.c b/qlist.c
index 7755736..be5893d 100644
--- a/qlist.c
+++ b/qlist.c
@@ -9,12 +9,13 @@
#ifdef APPLET_qlist
-#define QLIST_FLAGS "ISUcDeados" COMMON_FLAGS
+#define QLIST_FLAGS "ISRUcDeados" COMMON_FLAGS
static struct option const qlist_long_opts[] = {
{"installed", no_argument, NULL, 'I'},
{"slots", no_argument, NULL, 'S'},
- {"columns", no_argument, NULL, 'c'},
+ {"repo", no_argument, NULL, 'R'},
{"umap", no_argument, NULL, 'U'},
+ {"columns", no_argument, NULL, 'c'},
{"dups", no_argument, NULL, 'D'},
{"showdebug", no_argument, NULL, 128},
{"exact", no_argument, NULL, 'e'},
@@ -28,8 +29,9 @@ static struct option const qlist_long_opts[] = {
static const char * const qlist_opts_help[] = {
"Just show installed packages",
"Display installed packages with slots",
- "Display column view",
+ "Display installed packages with repository",
"Display installed packages with flags used",
+ "Display column view",
"Only show package dups",
"Show /usr/lib/debug files",
"Exact match (only CAT/PN or PN without PV)",
@@ -142,13 +144,31 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
char buf[_Q_PATH_MAX];
char swap[_Q_PATH_MAX];
const char *uslot;
+ size_t uslot_len = 0;
+ const char *urepo;
+ size_t urepo_len = 0;
depend_atom *atom;
uslot = strchr(name, ':');
if (uslot) {
- ++uslot;
- if (!pkg_ctx->slot)
- q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
+ if (*++uslot == ':')
+ uslot = NULL;
+ else {
+ if (!pkg_ctx->slot)
+ q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
+ uslot_len = strlen(uslot);
+ }
+ }
+
+ urepo = strstr(name, "::");
+ if (urepo) {
+ if (!pkg_ctx->repo)
+ q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo, &pkg_ctx->repo_len);
+ urepo_len = strlen(urepo);
+ urepo += 2;
+
+ if (uslot_len)
+ uslot_len -= urepo_len;
}
/* maybe they're using a version range */
@@ -157,8 +177,9 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
case '>':
case '<':
case '~':
- snprintf(buf, sizeof(buf), "%s/%s%c%s", catname, pkgname,
- pkg_ctx->slot ? ':' : '\0', pkg_ctx->slot ? : "");
+ snprintf(buf, sizeof(buf), "%s/%s%c%s%s%s", catname, pkgname,
+ pkg_ctx->slot ? ':' : '\0', pkg_ctx->slot ? : "",
+ pkg_ctx->repo ? "::" : "", pkg_ctx->repo ? : "");
if ((atom = atom_explode(buf)) == NULL) {
warn("invalid atom %s", buf);
return false;
@@ -182,18 +203,27 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
if (uslot) {
/* require exact match on SLOTs */
- if (strcmp(pkg_ctx->slot, uslot) != 0)
+ if (strncmp(pkg_ctx->slot, uslot, uslot_len) != 0 || pkg_ctx->slot[uslot_len] != '\0')
+ return false;
+ }
+
+ if (urepo) {
+ /* require exact match on repositories */
+ if (strcmp(pkg_ctx->repo, urepo) != 0)
return false;
}
/* printf("buf=%s:%s\n", buf,grab_vdb_item("SLOT", catname, pkgname)); */
if (exact) {
- snprintf(buf, sizeof(buf), "%s/%s:%s", catname, pkgname, pkg_ctx->slot);
+ int i;
- /* exact match: CAT/PN-PVR[:SLOT] */
+ snprintf(buf, sizeof(buf), "%s/%s:%s::%s",
+ catname, pkgname, pkg_ctx->slot, pkg_ctx->repo);
+
+ /* exact match: CAT/PN-PVR[:SLOT][::REPO] */
if (strcmp(name, buf) == 0)
return true;
- /* exact match: PN-PVR[:SLOT] */
+ /* exact match: PN-PVR[:SLOT][::REPO] */
if (strcmp(name, strstr(buf, "/") + 1) == 0)
return true;
@@ -202,25 +232,26 @@ qlist_match(q_vdb_pkg_ctx *pkg_ctx, const char *name, depend_atom **name_atom, b
warn("invalid atom %s", buf);
return false;
}
- if (uslot)
- snprintf(swap, sizeof(swap), "%s/%s:%s",
- atom->CATEGORY, atom->PN, atom->SLOT);
- else
- snprintf(swap, sizeof(swap), "%s/%s",
- atom->CATEGORY, atom->PN);
+
+ i = snprintf(swap, sizeof(swap), "%s/%s", atom->CATEGORY, atom->PN);
+ if (uslot && i <= (int)sizeof(swap))
+ i += snprintf(swap + i, sizeof(swap) - i, ":%s", atom->SLOT);
+ if (urepo && i <= (int)sizeof(swap))
+ i += snprintf(swap + i, sizeof(swap) - i, "::%s", atom->REPO);
+
atom_implode(atom);
- /* exact match: CAT/PN[:SLOT] */
+ /* exact match: CAT/PN[:SLOT][::REPO] */
if (strcmp(name, swap) == 0)
return true;
- /* exact match: PN[:SLOT] */
+ /* exact match: PN[:SLOT][::REPO] */
if (strcmp(name, strstr(swap, "/") + 1) == 0)
return true;
} else {
- size_t ulen;
+ size_t ulen = strlen(name);
+ if (urepo)
+ ulen -= (urepo_len + 2);
if (uslot)
- ulen = uslot - name - 1;
- else
- ulen = strlen(name);
+ ulen -= (uslot_len + 1);
snprintf(buf, sizeof(buf), "%s/%s", catname, pkgname);
/* partial leading match: CAT/PN-PVR */
if (strncmp(name, buf, ulen) == 0)
@@ -248,6 +279,7 @@ struct qlist_opt_state {
bool dups_only;
bool show_dir;
bool show_obj;
+ bool show_repo;
bool show_sym;
bool show_slots;
bool show_umap;
@@ -288,11 +320,14 @@ _q_static int qlist_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv)
if ((state->all + state->just_pkgname) < 2) {
if (state->show_slots && !pkg_ctx->slot)
q_vdb_pkg_eat(pkg_ctx, "SLOT", &pkg_ctx->slot, &pkg_ctx->slot_len);
+ if (state->show_repo && !pkg_ctx->repo)
+ q_vdb_pkg_eat(pkg_ctx, "repository", &pkg_ctx->repo, &pkg_ctx->repo_len);
/* display it */
- printf("%s%s/%s%s%s%s%s%s%s%s%s%s\n", BOLD, catname, BLUE,
+ printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", BOLD, catname, BLUE,
(!state->columns ? (atom ? atom->PN : pkgname) : atom->PN),
(state->columns ? " " : ""), (state->columns ? atom->PV : ""),
NORM, YELLOW, state->show_slots ? ":" : "", state->show_slots ? pkg_ctx->slot : "", NORM,
+ NORM, GREEN, state->show_repo ? "::" : "", state->show_repo ? pkg_ctx->repo : "", NORM,
umapstr(state->show_umap, catname, pkgname));
}
if (atom)
@@ -357,6 +392,7 @@ int qlist_main(int argc, char **argv)
.dups_only = false,
.show_dir = false,
.show_obj = false,
+ .show_repo = false,
.show_sym = false,
.show_slots = false,
.show_umap = false,
@@ -376,6 +412,7 @@ int qlist_main(int argc, char **argv)
case 'a': state.all = true;
case 'I': state.just_pkgname = true; break;
case 'S': state.just_pkgname = state.show_slots = true; break;
+ case 'R': state.just_pkgname = state.show_repo = true; break;
case 'U': state.just_pkgname = state.show_umap = true; break;
case 'e': state.exact = true; break;
case 'd': state.show_dir = true; break;
@@ -413,12 +450,16 @@ int qlist_main(int argc, char **argv)
strncpy(last, atom->PN, sizeof(last));
if (ok) {
char *slot = NULL;
+ char *repo = NULL;
if (state.show_slots)
slot = grab_vdb_item("SLOT", atom->CATEGORY, atom->P);
- printf("%s%s/%s%s%s%s%s%s%s%s%s", BOLD, atom->CATEGORY, BLUE,
+ if (state.show_repo)
+ repo = grab_vdb_item("repository", atom->CATEGORY, atom->P);
+ printf("%s%s/%s%s%s%s%s%s%s%s%s%s%s%s%s", BOLD, atom->CATEGORY, BLUE,
(!state.columns ? (verbose ? atom->P : atom->PN) : atom->PN),
(state.columns ? " " : ""), (state.columns ? atom->PV : ""),
- NORM, YELLOW, slot ? ":" : "", slot ? slot : "", NORM);
+ NORM, YELLOW, slot ? ":" : "", slot ? slot : "",
+ NORM, GREEN, repo ? "::" : "", repo ? repo : "", NORM);
puts(umapstr(state.show_umap, atom->CATEGORY, atom->P));
}
atom_implode(atom);
diff --git a/tests/qlist/dotest b/tests/qlist/dotest
index 5ee4bb6..dfc4779 100755
--- a/tests/qlist/dotest
+++ b/tests/qlist/dotest
@@ -46,6 +46,15 @@ test 09 "qlist -C mtools -d"
# ver test
test 10 "qlist -Iv =mtools-4*"
+# repo test
+test 11 "qlist -ICR"
+
+# slot with repo test
+test 12 "qlist -ICSR"
+
+# exact CAT/PN:slot::repo files list test
+test 13 "qlist -Ce --showdebug app-arch/cpio:0::gentoo"
+
cleantmpdir
end
diff --git a/tests/qlist/list11.good b/tests/qlist/list11.good
new file mode 100644
index 0000000..1f2bfe6
--- /dev/null
+++ b/tests/qlist/list11.good
@@ -0,0 +1,5 @@
+a-b/a::a
+a-b/b::b
+app-arch/cpio::gentoo
+cat/pkg::repo
+sys-fs/mtools::gentoo
diff --git a/tests/qlist/list12.good b/tests/qlist/list12.good
new file mode 100644
index 0000000..61d8643
--- /dev/null
+++ b/tests/qlist/list12.good
@@ -0,0 +1,5 @@
+a-b/a:a-0::a
+a-b/b:b-0::b
+app-arch/cpio:0::gentoo
+cat/pkg:1::repo
+sys-fs/mtools:0::gentoo
diff --git a/tests/qlist/list13.good b/tests/qlist/list13.good
new file mode 100644
index 0000000..8d3d7c7
--- /dev/null
+++ b/tests/qlist/list13.good
@@ -0,0 +1,8 @@
+/bin/cpio
+/usr/share/man/man1/cpio.1.lzma
+/usr/share/doc/cpio-2.11/ChangeLog.lzma
+/usr/share/doc/cpio-2.11/NEWS.lzma
+/usr/share/doc/cpio-2.11/README.lzma
+/usr/share/locale/de/LC_MESSAGES/cpio.mo
+/usr/share/info/cpio.info.lzma
+/usr/lib/debug/bin/cpio.debug
diff --git a/tests/qlist/root/a-b/a-0/repository b/tests/qlist/root/a-b/a-0/repository
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/tests/qlist/root/a-b/a-0/repository
@@ -0,0 +1 @@
+a
diff --git a/tests/qlist/root/a-b/b-0/repository b/tests/qlist/root/a-b/b-0/repository
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/tests/qlist/root/a-b/b-0/repository
@@ -0,0 +1 @@
+b
diff --git a/tests/qlist/root/app-arch/cpio-2.11/repository b/tests/qlist/root/app-arch/cpio-2.11/repository
new file mode 100644
index 0000000..23574f3
--- /dev/null
+++ b/tests/qlist/root/app-arch/cpio-2.11/repository
@@ -0,0 +1 @@
+gentoo
diff --git a/tests/qlist/root/cat/pkg-1/repository b/tests/qlist/root/cat/pkg-1/repository
new file mode 100644
index 0000000..f606d5e
--- /dev/null
+++ b/tests/qlist/root/cat/pkg-1/repository
@@ -0,0 +1 @@
+repo
diff --git a/tests/qlist/root/sys-fs/mtools-4.0.13/repository b/tests/qlist/root/sys-fs/mtools-4.0.13/repository
new file mode 100644
index 0000000..23574f3
--- /dev/null
+++ b/tests/qlist/root/sys-fs/mtools-4.0.13/repository
@@ -0,0 +1 @@
+gentoo