commit: 7dc2cc4bfaf2bbb943c45bc8171843a523cea7e5
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 13 20:30:48 2021 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Mar 13 20:30:48 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7dc2cc4b
q: show masking reason from comments when using -vv with -m
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
main.c | 1 -
man/include/q.optdesc.yaml | 5 ++--
man/q.1 | 7 +++---
q.c | 58 +++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/main.c b/main.c
index a68af63..ceab587 100644
--- a/main.c
+++ b/main.c
@@ -677,7 +677,6 @@ read_one_repos_conf(const char *repos_conf, char **primary)
main_repo = NULL;
repo = NULL;
- line = 0;
for (p = strtok_r(buf, "\n", &s); p != NULL; p = strtok_r(NULL, "\n",
&s))
{
/* trim trailing whitespace, remove comments, locate = */
diff --git a/man/include/q.optdesc.yaml b/man/include/q.optdesc.yaml
index cde6eed..468ffa9 100644
--- a/man/include/q.optdesc.yaml
+++ b/man/include/q.optdesc.yaml
@@ -10,5 +10,6 @@ envvar: |
variable name and the value is printed as a shell-style declaration.
masks: |
Print the masks from package.mask files found. Use \fI-v\fR to see
- the source (file) where the mask was declared. Additional arguments
- are treated as atom selectors which must match the masks.
+ the source (file) where the mask was declared. Use multiple
+ \fI-v\fR to print the comment right before the mask. Additional
+ arguments are treated as atom selectors which must match the masks.
diff --git a/man/q.1 b/man/q.1
index 2979cab..f43be6f 100644
--- a/man/q.1
+++ b/man/q.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH q "1" "Feb 2021" "Gentoo Foundation" "q"
+.TH q "1" "Mar 2021" "Gentoo Foundation" "q"
.SH NAME
q \- invoke a portage utility applet
.SH SYNOPSIS
@@ -35,8 +35,9 @@ variable name and the value is printed as a shell-style
declaration.
.TP
\fB\-m\fR, \fB\-\-masks\fR
Print the masks from package.mask files found. Use \fI-v\fR to see
-the source (file) where the mask was declared. Additional arguments
-are treated as atom selectors which must match the masks.
+the source (file) where the mask was declared. Use multiple
+\fI-v\fR to print the comment right before the mask. Additional
+arguments are treated as atom selectors which must match the masks.
.TP
\fB\-\-root\fR \fI<arg>\fR
Set the ROOT env var.
diff --git a/q.c b/q.c
index a6a9a0b..e514b0c 100644
--- a/q.c
+++ b/q.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2010 Ned Ludd - <[email protected]>
@@ -288,6 +288,11 @@ int q_main(int argc, char **argv)
size_t n;
int j;
bool match;
+ char *lastmfile = NULL;
+ long lastcbeg = 0;
+ long lastcend = 0;
+ char *buf = NULL;
+ size_t buflen = 0;
depend_atom *atom;
depend_atom *qatom;
@@ -313,16 +318,63 @@ int q_main(int argc, char **argv)
if (!match)
continue;
+ if (verbose > 1) {
+ char *mfile = (char *)array_get_elem(files, n);
+ char *l;
+ char *s = NULL;
+ long line = 0;
+ long cbeg = 0;
+ long cend = 0;
+
+ s = l = strchr(mfile, ':');
+ /* p cannot be NULL, just crash if something's
wrong */
+ (void)strtol(l + 1, &l, 10);
+ if (*l == ':')
+ cbeg = strtol(l + 1, &l, 10);
+ if (*l == '-')
+ cend = strtol(l + 1, &l, 10);
+ if (cend < cbeg)
+ cend = cbeg = 0;
+
+ if (lastmfile == NULL ||
+ strncmp(lastmfile, mfile, s -
mfile + 1) != 0 ||
+ lastcbeg != cbeg || lastcend !=
cend)
+ {
+ *s = '\0';
+ if (buf != NULL)
+ *buf = '\0';
+ eat_file(mfile, &buf, &buflen);
+ *s = ':';
+
+ line = 0;
+ for (l = buf; (s = strchr(l, '\n')) !=
NULL; l = s + 1)
+ {
+ line++;
+ if (line >= cbeg && line <=
cend)
+ printf("%.*s\n",
(int)(s - l), l);
+ if (line > cend)
+ break;
+ }
+ }
+ lastmfile = mfile;
+ lastcbeg = cbeg;
+ lastcend = cend;
+ }
printf("%s", atom_format(
"%[pfx]%[CAT]%[PF]%[SLOT]%[SUBSLOT]%[sfx]%[USE]%[REPO]",
atom));
- if (verbose)
+
+ if (verbose == 1) {
printf(" [%s]\n", (char *)array_get_elem(files,
n));
- else
+ } else {
printf("\n");
+ }
atom_implode(atom);
}
+ if (buf != NULL)
+ free(buf);
+
xarrayfree_int(masks);
xarrayfree_int(files);