commit:     f23fa9375a936d3d7d565175dfe39a2dd209d45e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 24 00:21:25 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Feb 24 00:21:25 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=f23fa937

qmerge: parse the binpkg header first

This contains common details (like REPO) that are not repeated for every
entry.  We'll propagate that back out whenever we reset the Pkg state.

Also seed the SLOT value with 0 every time.  Its value is omitted when it
is the default, so we have to do this ourselves.

---
 qmerge.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/qmerge.c b/qmerge.c
index be28cb7..1bd860d 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -1675,13 +1675,40 @@ parse_packages(queue *todo)
        char *buf, *p;
        struct pkg_t Pkg;
        depend_atom *pkg_atom;
+       char repo[sizeof(Pkg.REPO)];
 
        fp = open_binpkg_index();
 
+       buf = NULL;
+       repo[0] = '\0';
+
+       /* First consume the header with the common data. */
+       while (getline(&buf, &buflen, fp) != -1) {
+               if (*buf == '\n')
+                       break;
+
+               if ((p = strchr(buf, '\n')) != NULL)
+                       *p = 0;
+               if ((p = strchr(buf, ':')) == NULL)
+                       continue;
+               if (p[1] != ' ')
+                       continue;
+               *p = 0;
+               p += 2;
+
+               switch (*buf) {
+               case 'R':
+                       if (!strcmp(buf, "REPO"))
+                               strncpy(repo, p, sizeof(repo));
+                       break;
+               }
+       }
+
        pkg_atom = NULL;
        memset(&Pkg, 0, sizeof(Pkg));
+       strcpy(Pkg.SLOT, "0");
 
-       buf = NULL;
+       /* Then walk all the package entries. */
        while (getline(&buf, &buflen, fp) != -1) {
                if (*buf == '\n') {
                        if (pkg_atom) {
@@ -1706,6 +1733,8 @@ parse_packages(queue *todo)
                                pkg_atom = NULL;
                        }
                        memset(&Pkg, 0, sizeof(Pkg));
+                       strcpy(Pkg.SLOT, "0");
+                       strcpy(Pkg.REPO, repo);
                        continue;
                }
 

Reply via email to