Dpkg::Source::Package::V2: Mark single-debian-patch as not needing forwarding
[dpkg.git] / dselect / pkgsublist.cc
blobd7875dc6976047b2376c9006a1d12e7c9e6597fc
1 /*
2 * dselect - Debian package maintenance user interface
3 * pkgsublist.cc - status modification and recursive package list handling
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 #include <config.h>
23 #include <compat.h>
25 #include <string.h>
26 #include <stdio.h>
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.h>
32 #include "dselect.h"
33 #include "bindings.h"
35 void packagelist::add(pkginfo *pkg) {
36 debug(dbg_general, "packagelist[%p]::add(pkginfo %s)",
37 this, pkg_name(pkg, pnaw_always));
38 if (!recursive || // never add things to top level
39 !pkg->clientdata || // don't add pure virtual packages
40 pkg->clientdata->uprec) // don't add ones already in the recursive list
41 return;
42 debug(dbg_general, "packagelist[%p]::add(pkginfo %s) adding",
43 this, pkg_name(pkg, pnaw_always));
44 perpackagestate *state= &datatable[nitems];
45 state->pkg= pkg;
46 state->direct= state->original= pkg->clientdata->selected;
47 state->suggested= state->selected= pkg->clientdata->selected;
48 state->spriority= sp_inherit; state->dpriority= dp_none;
49 state->uprec= pkg->clientdata;
50 state->relations.init();
51 pkg->clientdata= state;
52 table[nitems]= state;
53 nitems++;
56 void
57 packagelist::add(pkginfo *pkg, pkgwant nw)
59 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s)",
60 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
61 add(pkg); if (!pkg->clientdata) return;
62 pkg->clientdata->direct= nw;
63 selpriority np;
64 np= would_like_to_install(nw,pkg) ? sp_selecting : sp_deselecting;
65 if (pkg->clientdata->spriority > np) return;
66 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s) setting",
67 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
68 pkg->clientdata->suggested= pkg->clientdata->selected= nw;
69 pkg->clientdata->spriority= np;
72 void packagelist::add(pkginfo *pkg, const char *extrainfo, showpriority showimp) {
73 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, ..., showpriority %d)",
74 this, pkg_name(pkg, pnaw_always), showimp);
75 add(pkg); if (!pkg->clientdata) return;
76 if (pkg->clientdata->dpriority < showimp) pkg->clientdata->dpriority= showimp;
77 pkg->clientdata->relations(extrainfo);
80 bool
81 packagelist::alreadydone(doneent **done, void *check)
83 doneent *search = *done;
85 while (search && search->dep != check)
86 search = search->next;
87 if (search)
88 return true;
89 debug(dbg_general, "packagelist[%p]::alreadydone(%p, %p) new",
90 this, done, check);
91 search= new doneent;
92 search->next= *done;
93 search->dep= check;
94 *done= search;
95 return false;
98 void packagelist::addunavailable(deppossi *possi) {
99 debug(dbg_general, "packagelist[%p]::addunavail(%p)", this, possi);
101 if (!recursive) return;
102 if (alreadydone(&unavdone,possi)) return;
104 if (possi->up->up->clientdata == nullptr)
105 internerr("deppossi from package %s has nullptr clientdata",
106 pkg_name(possi->up->up, pnaw_always));
107 if (possi->up->up->clientdata->uprec == nullptr)
108 internerr("deppossi from package %s has nullptr clientdata's uprec",
109 pkg_name(possi->up->up, pnaw_always));
111 // cppcheck-suppress[constVariable]: false positive, operator() modifies it.
112 // cppcheck-suppress[constVariableReference]: idem, new name for the same.
113 varbuf& vb= possi->up->up->clientdata->relations;
114 vb(possi->ed->name);
115 vb(_(" does not appear to be available\n"));
118 bool
119 packagelist::add(dependency *depends, showpriority displayimportance)
121 debug(dbg_general, "packagelist[%p]::add(dependency[%p])", this, depends);
123 if (alreadydone(&depsdone, depends))
124 return false;
126 const char *comma= "";
127 varbuf depinfo;
128 depinfo(depends->up->set->name);
129 depinfo(' ');
130 depinfo(gettext(relatestrings[depends->type]));
131 depinfo(' ');
132 deppossi *possi;
133 for (possi=depends->list;
134 possi;
135 possi=possi->next, comma=(possi && possi->next ? ", " : _(" or "))) {
136 depinfo(comma);
137 depinfo(possi->ed->name);
138 if (possi->verrel != DPKG_RELATION_NONE) {
139 switch (possi->verrel) {
140 case DPKG_RELATION_LE:
141 depinfo(" (<= ");
142 break;
143 case DPKG_RELATION_GE:
144 depinfo(" (>= ");
145 break;
146 case DPKG_RELATION_LT:
147 depinfo(" (<< ");
148 break;
149 case DPKG_RELATION_GT:
150 depinfo(" (>> ");
151 break;
152 case DPKG_RELATION_EQ:
153 depinfo(" (= ");
154 break;
155 default:
156 internerr("unknown dpkg_relation %d", possi->verrel);
158 depinfo(versiondescribe(&possi->version, vdew_nonambig));
159 depinfo(")");
162 depinfo('\n');
163 add(depends->up, depinfo.string(), displayimportance);
164 for (possi=depends->list; possi; possi=possi->next) {
165 add(&possi->ed->pkg, depinfo.string(), displayimportance);
166 if (depends->type != dep_provides) {
167 /* Providers are not relevant if we are looking at a provider
168 * relationship already. */
169 deppossi *provider;
170 for (provider = possi->ed->depended.available;
171 provider;
172 provider = provider->rev_next) {
173 if (provider->up->type != dep_provides) continue;
174 add(provider->up->up, depinfo.string(), displayimportance);
175 add(provider->up,displayimportance);
179 return true;
182 void repeatedlydisplay(packagelist *sub,
183 showpriority initial,
184 packagelist *unredisplay) {
185 debug(dbg_general, "repeatedlydisplay(packagelist[%p])", sub);
186 if (sub->resolvesuggest() != 0 && sub->deletelessimp_anyleft(initial)) {
187 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) once", sub);
188 if (unredisplay) unredisplay->enddisplay();
189 for (;;) {
190 pkginfo **newl;
191 keybindings *kb;
193 /* Reset manual_install flag now that resolvesuggest() has seen it. */
194 manual_install = false;
195 newl= sub->display();
196 if (!newl) break;
197 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) newl", sub);
198 kb= sub->bindings; delete sub;
199 sub= new packagelist(kb,newl);
200 if (sub->resolvesuggest() <= 1) break;
201 if (!sub->deletelessimp_anyleft(dp_must)) break;
202 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) again", sub);
204 if (unredisplay) unredisplay->startdisplay();
206 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) done", sub);
207 delete sub;
210 int packagelist::deletelessimp_anyleft(showpriority than) {
211 debug(dbg_general, "packagelist[%p]::dli_al(%d): nitems=%d",
212 this, than, nitems);
213 int insat, runthr;
214 for (runthr=0, insat=0;
215 runthr < nitems;
216 runthr++) {
217 if (table[runthr]->dpriority < than) {
218 table[runthr]->free(recursive);
219 } else {
220 if (insat != runthr) table[insat]= table[runthr];
221 insat++;
224 nitems= insat;
225 debug(dbg_general, "packagelist[%p]::dli_al(%d) done; nitems=%d",
226 this, than, nitems);
227 return nitems;