dselect: Replace relevant pkg->set->name with pkg_name()
authorGuillem Jover <guillem@debian.org>
Tue, 1 Mar 2011 14:15:04 +0000 (15:15 +0100)
committerGuillem Jover <guillem@debian.org>
Mon, 23 Jan 2012 02:13:36 +0000 (03:13 +0100)
Many have been left untouched because there are fake package entries
which represent heading and whose pkg->set->name is NULL.

FIXME:
 - check change of pkginfo constness.
 - review all calls for correct installed/available pkgbin accesses.
 - review all calls for correct pno flags.

Based-on-patch-by: Raphaƫl Hertzog <hertzog@debian.org>
Sponsored-by: Linaro Limited
dselect/pkgcmds.cc
dselect/pkgdepcon.cc
dselect/pkginfo.cc
dselect/pkglist.cc
dselect/pkgsublist.cc
dselect/pkgtop.cc

index cf5f733..5661631 100644 (file)
@@ -148,7 +148,7 @@ void packagelist::kd_purge()    { setwant(pkginfo::want_purge);     }
 int would_like_to_install(pkginfo::pkgwant wantvalue, pkginfo *pkg) {
   /* Returns: 1 for yes, 0 for no, -1 for if they want to preserve an error condition. */
   debug(dbg_general, "would_like_to_install(%d, %s) status %d",
-        wantvalue, pkg->set->name, pkg->status);
+        wantvalue, pkg_name(pkg, pnaw_nonambig), pkg->status);
 
   if (wantvalue == pkginfo::want_install) return 1;
   if (wantvalue != pkginfo::want_hold) return 0;
@@ -159,7 +159,10 @@ int would_like_to_install(pkginfo::pkgwant wantvalue, pkginfo *pkg) {
 }
 
 const char *packagelist::itemname(int index) {
-  return table[index]->pkg->set->name;
+  if (table[index]->pkg->set->name)
+    return pkg_name(table[index]->pkg, pnaw_nonambig);
+  else
+    return NULL;
 }
 
 void packagelist::kd_swapstatorder() {
index 3408c49..653049b 100644 (file)
@@ -52,7 +52,7 @@ packagelist::find_pkgbin(pkginfo *pkg)
   pkgbin *r;
   r= useavailable(pkg) ? &pkg->available : &pkg->installed;
   debug(dbg_general, "packagelist[%p]::find_pkgbin(%s) useavailable=%d",
-        this, pkg->set->name, useavailable(pkg));
+        this, pkgbin_name(pkg, r, pnaw_nonambig), useavailable(pkg));
 
   return r;
 }
@@ -88,7 +88,8 @@ int packagelist::resolvesuggest() {
       if (!table[index]->pkg->set->name)
         continue;
       debug(dbg_depcon, "packagelist[%p]::resolvesuggest() loop[%i] %s / %d",
-            this, index, table[index]->pkg->set->name, changemade);
+            this, index, pkg_name(table[index]->pkg, pnaw_nonambig),
+            changemade);
       dependency *depends;
       for (depends = find_pkgbin(table[index]->pkg)->depends;
            depends;
@@ -103,7 +104,8 @@ int packagelist::resolvesuggest() {
         changemade = checkdependers(&depends->list->ed->pkg, changemade);
       }
       debug(dbg_depcon, "packagelist[%p]::resolvesuggest() loop[%i] %s / -> %d",
-            this, index, table[index]->pkg->set->name, changemade);
+            this, index, pkg_name(table[index]->pkg, pnaw_nonambig),
+            changemade);
     }
     if (!changemade) break;
     maxchangemade = max(maxchangemade, changemade);
@@ -118,7 +120,8 @@ static int dep_update_best_to_change_stop(perpackagestate *& best, pkginfo *tryt
   if (!trythis->clientdata) return 0;
 
   debug(dbg_depcon, "update_best_to_change(best=%s{%d}, test=%s{%d});",
-        best ? best->pkg->set->name : "", best ? (int)best->spriority : -1,
+        best ? pkg_name(best->pkg, pnaw_nonambig) : "",
+        best ? (int)best->spriority : -1,
         trythis->set->name, trythis->clientdata->spriority);
 
   // If the problem is caused by us deselecting one of these packages
@@ -170,8 +173,8 @@ packagelist::deselect_one_of(pkginfo *per, pkginfo *ped, dependency *dep)
 
   debug(dbg_depcon,
         "packagelist[%p]::deselect_one_of(): er %s{%d} ed %s{%d} [%p]",
-        this, er->pkg->set->name, er->spriority,
-        ed->pkg->set->name, ed->spriority, dep);
+        this, pkg_name(er->pkg, pnaw_nonambig), er->spriority,
+        pkg_name(ed->pkg, pnaw_nonambig), ed->spriority, dep);
 
   perpackagestate *best;
 
@@ -190,7 +193,7 @@ packagelist::deselect_one_of(pkginfo *per, pkginfo *ped, dependency *dep)
   else best= ed;                                      // ... failing that, the second
 
   debug(dbg_depcon, "packagelist[%p]::deselect_one_of(): best %s{%d}",
-        this, best->pkg->set->name, best->spriority);
+        this, pkg_name(best->pkg, pnaw_nonambig), best->spriority);
 
   if (best->spriority >= sp_deselecting) return 0;
   best->suggested=
@@ -217,7 +220,8 @@ int packagelist::resolvedepcon(dependency *depends) {
 
     debug(dbg_depcon,
           "packagelist[%p]::resolvedepcon([%p] %s --%s-->%s); (ing)->want=%s",
-          this, depends, depends->up->set->name, relatestrings[depends->type],
+          this, depends, pkg_name(depends->up, pnaw_nonambig),
+          relatestrings[depends->type],
           pkg_names.string(), depends->up->clientdata ?
           wantstrings[depends->up->clientdata->suggested] : "(no clientdata)");
   }
@@ -263,7 +267,7 @@ int packagelist::resolvedepcon(dependency *depends) {
     if (fixbyupgrade) {
       debug(dbg_depcon,
             "packagelist[%p]::resolvedepcon([%p]): fixbyupgrade %s",
-            this, depends, fixbyupgrade->pkg->set->name);
+            this, depends, pkg_name(fixbyupgrade->pkg, pnaw_nonambig));
       best= fixbyupgrade;
     } else {
       best= 0;
@@ -293,7 +297,7 @@ int packagelist::resolvedepcon(dependency *depends) {
     }
     debug(dbg_depcon,
           "packagelist[%p]::resolvedepcon([%p]): select best=%s{%d}",
-          this, depends, best->pkg->set->name, best->spriority);
+          this, depends, pkg_name(best->pkg, pnaw_nonambig), best->spriority);
     if (best->spriority >= sp_selecting) return r;
     /* Always select depends. Only select recommends if we got here because
      * of a manually-initiated install request. */
@@ -307,7 +311,7 @@ int packagelist::resolvedepcon(dependency *depends) {
     best= depends->up->clientdata;
     debug(dbg_depcon,
           "packagelist[%p]::resolvedepcon([%p]): mustdeselect best=%s{%d}",
-          this, depends, best->pkg->set->name, best->spriority);
+          this, depends, pkg_name(best->pkg, pnaw_nonambig), best->spriority);
 
     if (best->spriority >= sp_deselecting) return r;
     /* Always remove depends, but never remove recommends. */
index 2d3840b..73c4960 100644 (file)
@@ -113,7 +113,7 @@ void packagelist::itd_description() {
     const char *p= strchr(m,'\n');
     int l= p ? (int)(p-m) : strlen(m);
     wattrset(infopad,info_headattr);
-    waddstr(infopad, table[cursorline]->pkg->set->name);
+    waddstr(infopad, pkg_name(table[cursorline]->pkg, pnaw_nonambig));
     waddstr(infopad," - ");
     waddnstr(infopad,m,l);
     wattrset(infopad,info_attr);
index b7fcd58..0424f66 100644 (file)
@@ -66,6 +66,7 @@ int packagelist::compareentries(const struct perpackagestate *a,
     a->pkg->priority - b->pkg->priority;
   if (!c_priority && a->pkg->priority == pkginfo::pri_other)
     c_priority= strcasecmp(a->pkg->otherpriority, b->pkg->otherpriority);
+  /* XXX: Should sort by architecture in case of equality */
   int c_name=
     a->pkg->set->name && b->pkg->set->name ?
       strcasecmp(a->pkg->set->name, b->pkg->set->name) :
@@ -178,7 +179,7 @@ void packagelist::ensurestatsortinfo() {
     if (calcssadone) return;
     for (index=0; index < nitems; index++) {
       debug(dbg_general, "packagelist[%p]::ensurestatsortinfos() i=%d pkg=%s",
-            this, index, table[index]->pkg->set->name);
+            this, index, pkg_name(table[index]->pkg, pnaw_nonambig));
       pkg= table[index]->pkg;
       switch (pkg->status) {
       case pkginfo::stat_unpacked:
@@ -228,7 +229,7 @@ void packagelist::ensurestatsortinfo() {
     if (calcsssdone) return;
     for (index=0; index < nitems; index++) {
       debug(dbg_general, "packagelist[%p]::ensurestatsortinfos() i=%d pkg=%s",
-            this, index, table[index]->pkg->set->name);
+            this, index, pkg_name(table[index]->pkg, pnaw_nonambig));
       switch (table[index]->pkg->status) {
       case pkginfo::stat_unpacked:
       case pkginfo::stat_halfconfigured:
@@ -315,7 +316,7 @@ void packagelist::sortmakeheads() {
     debug(dbg_general,
           "packagelist[%p]::sortmakeheads() pkg=%s  state=%d avail=%d %s  "
           "priority=%d otherpriority=%s %s  section=%s %s",
-          this, thispkg->set->name,
+          this, pkg_name(thispkg, pnaw_nonambig),
           thispkg->clientdata->ssavail, thispkg->clientdata->ssstate,
           ssdiff ? "*diff" : "same",
           thispkg->priority,
index ebb0867..ec379f6 100644 (file)
 #include "bindings.h"
 
 void packagelist::add(pkginfo *pkg) {
-  debug(dbg_general, "packagelist[%p]::add(pkginfo %s)", this, pkg->set->name);
+  debug(dbg_general, "packagelist[%p]::add(pkginfo %s)", this,
+        pkg_name(pkg, pnaw_nonambig));
   if (!recursive ||  // never add things to top level
       !pkg->clientdata ||  // don't add pure virtual packages
       pkg->clientdata->uprec)  // don't add ones already in the recursive list
     return;
   debug(dbg_general, "packagelist[%p]::add(pkginfo %s) adding",
-        this, pkg->set->name);
+        this, pkg_name(pkg, pnaw_nonambig));
   perpackagestate *state= &datatable[nitems];
   state->pkg= pkg;
   state->direct= state->original= pkg->clientdata->selected;
@@ -54,21 +55,21 @@ void packagelist::add(pkginfo *pkg) {
 
 void packagelist::add(pkginfo *pkg, pkginfo::pkgwant nw) {
   debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s)",
-        this, pkg->set->name, wantstrings[nw]);
+        this, pkg_name(pkg, pnaw_nonambig), wantstrings[nw]);
   add(pkg);  if (!pkg->clientdata) return;
   pkg->clientdata->direct= nw;
   selpriority np;
   np= would_like_to_install(nw,pkg) ? sp_selecting : sp_deselecting;
   if (pkg->clientdata->spriority > np) return;
   debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s) setting",
-        this, pkg->set->name, wantstrings[nw]);
+        this, pkg_name(pkg, pnaw_nonambig), wantstrings[nw]);
   pkg->clientdata->suggested= pkg->clientdata->selected= nw;
   pkg->clientdata->spriority= np;
 }
 
 void packagelist::add(pkginfo *pkg, const char *extrainfo, showpriority showimp) {
   debug(dbg_general, "packagelist[%p]::add(pkginfo %s, ..., showpriority %d)",
-        this, pkg->set->name, showimp);
+        this, pkg_name(pkg, pnaw_nonambig), showimp);
   add(pkg);  if (!pkg->clientdata) return;
   if (pkg->clientdata->dpriority < showimp) pkg->clientdata->dpriority= showimp;
   pkg->clientdata->relations(extrainfo);
@@ -117,7 +118,7 @@ packagelist::add(dependency *depends, showpriority displayimportance)
 
   const char *comma= "";
   varbuf info;
-  info(depends->up->set->name);
+  info(pkg_name(depends->up, pnaw_nonambig));
   info(' ');
   info(gettext(relatestrings[depends->type]));
   info(' ');
index 45d82b7..68b0766 100644 (file)
@@ -109,7 +109,8 @@ void packagelist::redrawthisstate() {
   const char *priority= pkgprioritystring(table[cursorline]->pkg);
   char *buf= new char[500+
                       max((table[cursorline]->pkg->set->name ?
-                           strlen(table[cursorline]->pkg->set->name) : 0),
+                           strlen(pkg_name(table[cursorline]->pkg,
+                                           pnaw_nonambig)) : 0),
                           (section ? strlen(section) : 0) +
                           (priority ? strlen(priority) : 0))];
 
@@ -117,7 +118,7 @@ void packagelist::redrawthisstate() {
     sprintf(buf,
             _("%-*s %s%s%s;  %s (was: %s).  %s"),
             package_width,
-            table[cursorline]->pkg->set->name,
+            pkg_name(table[cursorline]->pkg, pnaw_nonambig),
             gettext(statusstrings[table[cursorline]->pkg->status]),
             ((eflagstrings[table[cursorline]->pkg->eflag][0]==' ') &&
               (eflagstrings[table[cursorline]->pkg->eflag][1]=='\0'))  ? "" : " - ",
@@ -138,7 +139,7 @@ void packagelist::redrawthisstate() {
 void packagelist::redraw1itemsel(int index, int selected) {
   int i, indent, j;
   const char *p;
-  const struct pkginfo *pkg= table[index]->pkg;
+  struct pkginfo *pkg = table[index]->pkg;
   const struct pkgbin *info = &pkg->available;
   int screenline = index - topofscreen;
 
@@ -199,7 +200,7 @@ void packagelist::redraw1itemsel(int index, int selected) {
               pkg->section ? pkg->section : "?");
 
     mvwprintw(listpad, screenline, package_column - 1, " %-*.*s ",
-              package_width, package_width, pkg->set->name);
+              package_width, package_width, pkg_name(pkg, pnaw_nonambig));
 
     if (versioninstalled_width)
       mvwprintw(listpad, screenline, versioninstalled_column, "%-*.*s ",