commit:     dd4ccd04e4ff70818d6213a94d8a00e47484ec5e
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 25 13:57:34 2025 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Aug 25 13:57:34 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dd4ccd04

q: drop unneeded entries from Manifest files

We don't need EBUILD, METADATA or AUX, because we guarantee the tree is
"good".  So only keep DIST.  This brings down the tree from 45MiB to
35MiB.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 q.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/q.c b/q.c
index 9fffb8a..8629e03 100644
--- a/q.c
+++ b/q.c
@@ -341,22 +341,38 @@ int q_build_cache_pkg(tree_pkg_ctx *pkg, void *priv)
                        }
                        close(ffd);
                }
-               ffd = openat(dfd, "Manifest", O_RDONLY);
-               if (ffd >= 0) {
-                       if (fstat(ffd, &st) == 0) {
+               /* for Manifest file we perform a "grep" here on the only
+                * relevant entries: DIST, this reduces the overall size
+                * of the tree considerably */
+               if (eat_file_at(dfd, "Manifest", &ctx->cbuf, &ctx->cbufsiz)) {
+                       bool  start = true;
+                       bool  write = false;
+                       char *wp;
+                       for (qc = ctx->cbuf, wp = ctx->cbuf; *qc != '\0'; qc++) 
{
+                               if (start && strncmp(qc, "DIST ", 5) == 0)
+                                       write = true;
+                               start = false;
+                               if (write)
+                                       *wp++ = *qc;
+                               if (*qc == '\r' || *qc == '\n') {
+                                       start = true;
+                                       write = false;
+                               }
+                       }
+                       ctx->cbuflen = wp - ctx->cbuf;
+
+                       if (ctx->cbuflen > 0) {
                                entry = archive_entry_new();
                                snprintf(p, siz, "Manifest");
                                archive_entry_set_pathname(entry, buf);
-                               archive_entry_set_size(entry, st.st_size);
+                               archive_entry_set_size(entry, ctx->cbuflen);
                                archive_entry_set_mtime(entry, ctx->buildtime, 
0);
                                archive_entry_set_filetype(entry, AE_IFREG);
                                archive_entry_set_perm(entry, 0644);
                                archive_write_header(a, entry);
-                               while ((flen = read(ffd, pth, sizeof(pth))) > 0)
-                                       archive_write_data(a, pth, flen);
+                               archive_write_data(a, ctx->cbuf, ctx->cbuflen);
                                archive_entry_free(entry);
                        }
-                       close(ffd);
                }
                /* process files, unfortunately this can be any number of
                 * directories deep (remember eblitz?) so we'll have to recurse

Reply via email to