commit: 5c7672ae5f40babb6b042892eb4cb9260f3211f0
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 24 09:20:00 2026 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan 24 09:26:34 2026 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5c7672ae
main: add --overlay global option to restrict to a single overlay
Allow to restrict to which overlay to consider when walking through
trees (not VDB or binpkg), or consider an overlay that is not defined in
repos.conf by providing the absolute path to the repo.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
applets.h | 7 +++++--
main.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/applets.h b/applets.h
index fc4e27c..97b2d62 100644
--- a/applets.h
+++ b/applets.h
@@ -128,15 +128,17 @@ static const struct applet_t {
#define COMMON_FLAGS "vqChV"
#define COMMON_LONG_OPTS \
{"root", a_argument, NULL, 0x1}, \
+ {"overlay", a_argument, NULL, 0x2}, \
{"verbose", no_argument, NULL, 'v'}, \
{"quiet", no_argument, NULL, 'q'}, \
{"nocolor", no_argument, NULL, 'C'}, \
- {"color", no_argument, NULL, 0x2}, \
+ {"color", no_argument, NULL, 0x3}, \
{"help", no_argument, NULL, 'h'}, \
{"version", no_argument, NULL, 'V'}, \
{NULL, no_argument, NULL, 0x0}
#define COMMON_OPTS_HELP \
"Set the ROOT env var", \
+ "Select the given overlay for use, instead of all found (see q -o)", \
"Report full package versions, emit more elaborate output", \
"Tighter output; suppress warnings", \
"Don't output color", \
@@ -146,6 +148,7 @@ static const struct applet_t {
NULL
#define COMMON_GETOPTS_CASES(applet) \
case 0x1: /* already handled early in main */ break; \
+ case 0x2: /* already handled early in main */ break; \
case 'v': ++verbose; break; \
case 'q': /* already handled early in main */ break; \
case 'V': version_barf(); break; \
@@ -155,7 +158,7 @@ static const struct applet_t {
color_clear(); \
setenv("NOCOLOR", "true", 1); \
} break; \
- case 0x2: if (nocolor) { \
+ case 0x3: if (nocolor) { \
nocolor = 0; \
color_remap(); \
setenv("NOCOLOR", "false", 1); \
diff --git a/main.c b/main.c
index d2a10f4..f6409bc 100644
--- a/main.c
+++ b/main.c
@@ -1252,6 +1252,7 @@ int main(int argc, char **argv)
{
struct stat st;
struct winsize winsz;
+ char *overlay = NULL;
int i;
warnout = stderr;
@@ -1300,8 +1301,8 @@ int main(int argc, char **argv)
* the first non-option argument) because otherwise argv is
* modified, this basically sulks, because ideally we parse and
* handle the common options here. Because we are parsing profiles
- * and stuff at this point we need -q for bug #735134, and --root so
- * do lame matching for that */
+ * and stuff at this point we need -q for bug #735134, and
+ * --root/--overlay so do lame matching for that */
for (i = 1; i < argc; i++) {
if (argv[i] != NULL && argv[i][0] == '-') {
if (argv[i][1] == '-') {
@@ -1318,6 +1319,10 @@ int main(int argc, char **argv)
errp("--root argument could not
be resolved");
set_portage_env_var(&vars_to_read[0],
root,
"command line"); /* ROOT */
+ } else if (strcmp(&argv[i][2], "overlay") == 0
&&
+ argv[i + 1] != NULL)
+ {
+ overlay = argv[i + 1];
}
} else {
char *p;
@@ -1339,6 +1344,64 @@ int main(int argc, char **argv)
setup_quiet();
initialize_portage_env();
+
+ /* select or implicitly create overlay when given */
+ if (overlay != NULL)
+ {
+ char buf[_Q_PATH_MAX];
+ const char *match;
+ char *oname;
+ size_t n;
+
+ if (overlay[0] != '/' &&
+ getcwd(buf, sizeof(buf)) != NULL)
+ {
+ size_t len = strlen(buf);
+ snprintf(buf + len, sizeof(buf) - len, "/%s", overlay);
+ /* first try as relative path */
+ match = overlay_from_path(buf);
+ if (match == NULL)
+ {
+ /* then as overlay name */
+ array_for_each(overlay_names, n, oname)
+ {
+ if (strcmp(oname, overlay) == 0)
+ {
+ match = array_get(overlays, n);
+ break;
+ }
+ }
+ }
+
+ if (match == NULL)
+ err("no such overlay '%s'", overlay);
+ }
+ else
+ {
+ match = overlay_from_path(overlay);
+ if (match == NULL)
+ {
+ /* this is an absolute path, so create it as
overlay,
+ * which allows for easy testing */
+ match = array_append_strcpy(overlays, overlay);
+
+ array_append_strcpy(overlay_names, "implicit");
+ array_append_strcpy(overlay_src, "--overlay");
+ }
+ }
+
+ /* at this point match should always be set to something */
+ array_for_each_rev(overlays, n, oname)
+ {
+ if (oname != match)
+ {
+ array_delete(overlays, n, NULL);
+ array_delete(overlay_names, n, NULL);
+ array_delete(overlay_src, n, NULL);
+ }
+ }
+ }
+
optind = 0;
i = q_main(argc, argv);