This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup v2 5/5] Make user URLs sort last in the displayed site list
- From: Ken Brown <kbrown at cornell dot edu>
- To: cygwin-apps at cygwin dot com
- Date: Mon, 4 Dec 2017 10:18:08 -0500
- Subject: [PATCH setup v2 5/5] Make user URLs sort last in the displayed site list
- Authentication-results: sourceware.org; auth=none
- References: <20171204151808.4804-1-kbrown@cornell.edu>
Also fix load_site_list() so that when a mirror replaces an existing
entry, the sort order is updated.
Change site_list_type::operator== to compare URLs instead of sort
keys, since the key of a user URL no longer depends solely on the URL.
Introduce a new helper function merge_site().
---
site.cc | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/site.cc b/site.cc
index 9972a29..641a6bb 100644
--- a/site.cc
+++ b/site.cc
@@ -183,11 +183,13 @@ site_list_type::site_list_type (const string &_url,
idx = 0;
} while (idx > 0);
key += url;
- /* Display the full URL (without trailing slash) of a non-mirror. */
+ /* Display the full URL (without trailing slash) of non-mirrors, and
+ make them sort last. */
if (!from_mirrors_lst)
{
displayed_url = url;
displayed_url.erase (displayed_url.end () - 1);
+ key = "zzzz " + key;
}
}
@@ -218,7 +220,7 @@ site_list_type::operator= (site_list_type const &rhs)
bool
site_list_type::operator == (site_list_type const &rhs) const
{
- return stricmp (key.c_str(), rhs.key.c_str()) == 0;
+ return stricmp (url.c_str(), rhs.url.c_str()) == 0;
}
bool
@@ -306,6 +308,16 @@ remove_user_urls ()
all_site_list = result;
}
+static void
+merge_site (SiteList & sites, site_list_type newsite)
+{
+ SiteList result;
+ merge (sites.begin(), sites.end(),
+ &newsite, &newsite + 1,
+ inserter (result, result.begin()));
+ sites = result;
+}
+
// This is called only for lists of mirrors that came (now or in a
// previous setup run) from mirrors.lst.
void
@@ -361,17 +373,9 @@ load_site_list (SiteList& theSites, char *theString)
site_list_type newsite (bol, semi, semi2, semi3, true);
SiteList::iterator i = find (theSites.begin(),
theSites.end(), newsite);
- if (i == theSites.end())
- {
- SiteList result;
- merge (theSites.begin(), theSites.end(),
- &newsite, &newsite + 1,
- inserter (result, result.begin()));
- theSites = result;
- }
- else
- //TODO: remove and remerge
- *i = newsite;
+ if (i != theSites.end())
+ theSites.erase (i);
+ merge_site (theSites, newsite);
}
else
{
@@ -458,11 +462,8 @@ SiteSetting::registerSavedSite (const char * site)
|| strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0
|| strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0)
return;
- SiteList result;
- merge (all_site_list.begin(), all_site_list.end(),
- &tempSite, &tempSite + 1,
- inserter (result, result.begin()));
- all_site_list = result;
+
+ merge_site (all_site_list, tempSite);
site_list.push_back (tempSite);
}
else
--
2.15.1