This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup 1/2] Improve the preparation of the package database
- From: Ken Brown <kbrown at cornell dot edu>
- To: cygwin-apps at cygwin dot com
- Date: Wed, 4 Apr 2018 11:51:00 -0400
- Subject: [PATCH setup 1/2] Improve the preparation of the package database
- References: <20180404155101.9620-1-kbrown@cornell.edu>
Introduce a new function packagedb::noChanges() to set the database to
a "no changes requested" state. Call it the first time the chooser
page is activated, before calling
ChooserPage::applyCommandLinePackageSelection().
Also use it to simplify the code in two places.
Remove code from ChooserPage::changeTrust() that was making changes to
the database after ChooserPage::applyCommandLinePackageSelection() had
already been called.
---
choose.cc | 26 ++++++--------------------
libsolv.cc | 11 +++--------
package_db.cc | 12 ++++++++++++
package_db.h | 2 ++
4 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/choose.cc b/choose.cc
index 1249efa..51d2fb6 100644
--- a/choose.cc
+++ b/choose.cc
@@ -329,6 +329,7 @@ ChooserPage::OnActivate()
{
// Do things which should only happen once, but rely on packagedb being
// ready to use, so OnInit() is too early
+ db.noChanges();
applyCommandLinePackageSelection();
initialUpdateState();
@@ -392,13 +393,7 @@ ChooserPage::keepClicked()
{
update_mode_id = IDC_CHOOSE_KEEP;
packagedb db;
- for (packagedb::packagecollection::iterator i = db.packages.begin ();
- i != db.packages.end (); ++i)
- {
- packagemeta & pkg = *(i->second);
- pkg.desired = pkg.installed;
- pkg.pick(false);
- }
+ db.noChanges();
chooser->refresh();
}
@@ -431,20 +426,11 @@ ChooserPage::changeTrust(int button, bool test, bool initial)
// usually we want to apply the solver to an empty task list to get the list
// of packages to upgrade (if any)
+ // but initially we want a task list with any package changes caused by
+ // command line options
if (initial)
- {
- // but initially we want a task list with any package changes caused by
- // command line options
- // (also note the installed version to avoid generating spurious taskKeep
- // or taskSkip tasks)
- for (packagedb::packagecollection::iterator p = db.packages.begin ();
- p != db.packages.end (); ++p)
- {
- packagemeta *pkg = p->second;
- pkg->default_version = pkg->installed;
- }
- q.setTasks();
- }
+ q.setTasks();
+
db.defaultTrust(q, mode, test);
// configure PickView so 'test' or 'curr' version is chosen when an
diff --git a/libsolv.cc b/libsolv.cc
index 2eb04e2..11394a2 100644
--- a/libsolv.cc
+++ b/libsolv.cc
@@ -658,14 +658,9 @@ void
SolverSolution::trans2db() const
{
packagedb db;
- // First reset all packages to the "no change" state
- for (packagedb::packagecollection::iterator i = db.packages.begin();
- i != db.packages.end(); i++)
- {
- packagemeta *pkg = i->second;
- pkg->desired = pkg->default_version = pkg->installed;
- pkg->pick(false);
- }
+ // First reset all packages to the "no changes" state
+ db.noChanges ();
+
// Now make changes according to trans. transErase requires some
// care; it could either be a "plain" uninstall, or it could be
// paired with a transInstall for an upgrade/downgrade or reinstall.
diff --git a/package_db.cc b/package_db.cc
index d12e841..9189e40 100644
--- a/package_db.cc
+++ b/package_db.cc
@@ -750,3 +750,15 @@ packagedb::prep()
prepped = true;
}
+
+void
+packagedb::noChanges ()
+{
+ for (packagecollection::iterator i = packages.begin();
+ i != packages.end(); i++)
+ {
+ packagemeta *pkg = i->second;
+ pkg->desired = pkg->default_version = pkg->installed;
+ pkg->pick(false);
+ }
+}
diff --git a/package_db.h b/package_db.h
index e500e4b..da73171 100644
--- a/package_db.h
+++ b/package_db.h
@@ -68,6 +68,8 @@ public:
/* 0 on success */
int flush ();
void prep();
+ /* Set the database to a "no changes requested" state. */
+ void noChanges ();
packagemeta * findBinary (PackageSpecification const &) const;
packageversion findBinaryVersion (PackageSpecification const &) const;
--
2.16.2