diff options
author | Daniel Hartwig <mandyke@gmail.com> | 2012-06-30 17:38:56 +0800 |
---|---|---|
committer | Daniel Hartwig <mandyke@gmail.com> | 2012-06-30 17:38:56 +0800 |
commit | b6855eaa5128fee88b31a0d67f41f1a745a9afcf (patch) | |
tree | 7e4ce87af125b5adbb32c95f893d0e19cea76ae0 | |
parent | 89427f77665e3d66d7229fea4233de6d153ccdeb (diff) | |
download | aptitude-b6855eaa5128fee88b31a0d67f41f1a745a9afcf.tar.gz |
Treat debtags always as strings; unify ept/non-ept interface to debtags
The behaviour of the non-ept interface has been updated
and corrected, so that, for example, the debtags browser
works correctly.
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/desc_render.cc | 17 | ||||
-rw-r--r-- | src/generic/apt/apt.cc | 6 | ||||
-rw-r--r-- | src/generic/apt/matching/match.cc | 19 | ||||
-rw-r--r-- | src/generic/apt/tags.cc | 198 | ||||
-rw-r--r-- | src/generic/apt/tags.h | 223 | ||||
-rw-r--r-- | src/gtk/gui.cc | 17 | ||||
-rw-r--r-- | src/pkg_grouppolicy.cc | 83 |
8 files changed, 155 insertions, 409 deletions
@@ -177,7 +177,6 @@ ii. to make the program more atomic and reliable when used - Build system changes: * Using libept is optional; use --disable-ept to disable it. - Debtags are not properly supported without libept. - Documentation: diff --git a/src/desc_render.cc b/src/desc_render.cc index 0bc640c7..c0bb4c5f 100644 --- a/src/desc_render.cc +++ b/src/desc_render.cc @@ -103,30 +103,19 @@ cw::fragment *make_tags_fragment(const pkgCache::PkgIterator &pkg) if(pkg.end()) return NULL; -#ifdef HAVE_EPT using aptitude::apt::get_fullname; using aptitude::apt::get_tags; using aptitude::apt::tag; -#endif -#ifdef HAVE_EPT - const set<tag> realS(get_tags(pkg)); - const set<tag> * const s(&realS); -#else - const set<tag> * const s(get_tags(pkg)); -#endif + const set<tag> s(get_tags(pkg)); vector<cw::fragment *> rval; - if(s != NULL && !s->empty()) + if(s.empty() == false) { vector<cw::fragment *> tags; - for(set<tag>::const_iterator i = s->begin(); i != s->end(); ++i) + for(set<tag>::const_iterator i = s.begin(); i != s.end(); ++i) { -#ifdef HAVE_EPT std::string name(get_fullname(*i)); -#else - const std::string name(i->str()); -#endif tags.push_back(cw::text_fragment(name)); } diff --git a/src/generic/apt/apt.cc b/src/generic/apt/apt.cc index d534b436..39641202 100644 --- a/src/generic/apt/apt.cc +++ b/src/generic/apt/apt.cc @@ -486,11 +486,7 @@ void apt_load_cache(OpProgress *progress_bar, bool do_initselections, LOG_TRACE(logger, "Loading task information."); aptitude::apt::load_tasks(*progress_bar); LOG_TRACE(logger, "Loading tags."); -#ifndef HAVE_EPT - load_tags(*progress_bar); -#else - aptitude::apt::load_tags(); -#endif + aptitude::apt::load_tags(progress_bar); if(user_pkg_hier) { diff --git a/src/generic/apt/matching/match.cc b/src/generic/apt/matching/match.cc index b59d6c74..7f66f7d4 100644 --- a/src/generic/apt/matching/match.cc +++ b/src/generic/apt/matching/match.cc @@ -1598,29 +1598,20 @@ namespace aptitude { pkgCache::PkgIterator pkg(target.get_package_iterator(cache)); -#ifdef HAVE_EPT using aptitude::apt::get_fullname; using aptitude::apt::get_tags; using aptitude::apt::tag; -#endif -#ifdef HAVE_EPT - const std::set<tag> realTags(get_tags(pkg)); - const std::set<tag> * const tags(&realTags); -#else - const std::set<tag> * const tags(get_tags(pkg)); -#endif + const std::set<tag> tags(get_tags(pkg)); - if(tags == NULL) + if(tags.empty() == true) return NULL; - for(std::set<tag>::const_iterator i=tags->begin(); i!=tags->end(); ++i) + for(std::set<tag>::const_iterator i = tags.begin(); + i != tags.end(); + ++i) { -#ifdef HAVE_EPT std::string name(get_fullname(*i)); -#else - const std::string name = i->str().c_str(); -#endif ref_ptr<match> rval = evaluate_regexp(p, p->get_tag_regex_info(), diff --git a/src/generic/apt/tags.cc b/src/generic/apt/tags.cc index 0e906e98..57cf54e2 100644 --- a/src/generic/apt/tags.cc +++ b/src/generic/apt/tags.cc @@ -30,7 +30,7 @@ #include <map> #include <utility> -#include <ctype.h> +#include <cctype> #include <string.h> #include <sigc++/functors/mem_fun.h> @@ -42,71 +42,69 @@ #include <cwidget/generic/util/eassert.h> using namespace std; +using aptitude::apt::tag; -tag::tag(std::string::const_iterator start, - std::string::const_iterator finish) +class tag_list { - while(start != finish && isspace(*start)) - ++start; - - while(start != finish && isspace(*(finish-1))) - --finish; + // The string to parse. + std::string s; +public: + class const_iterator + { + std::string::const_iterator start, finish, limit; + public: + const_iterator(const std::string::const_iterator &_start, + const std::string::const_iterator &_finish, + const std::string::const_iterator &_limit) + :start(_start), finish(_finish), limit(_limit) + { + } - s.assign(start, finish); -} + const_iterator operator=(const const_iterator &other) + { + start = other.start; + finish = other.finish; + limit = other.limit; -tag::const_iterator &tag::const_iterator::operator++() -{ - start = finish; - while(start != limit && (*start)==':') - ++start; + return *this; + } - if(start == limit) - finish = limit; - else + bool operator==(const const_iterator &other) { - finish = start+1; - while(finish != limit && (*finish) != ':') - ++finish; + return other.start == start && other.finish == finish && other.limit == limit; } - return *this; -} + bool operator!=(const const_iterator &other) + { + return other.start != start || other.finish != finish || other.limit != limit; + } -tag::const_iterator tag::begin() const -{ - tag::const_iterator rval(s.begin(), s.begin(), s.end()); + const_iterator &operator++(); - ++rval; + tag operator*() + { + return tag(start, finish); + } + }; - return rval; -} + tag_list(const char *start, const char *finish) + :s(start, finish) + { + } -int tag::cmp(const tag &other) const -{ - const_iterator myT=begin(), otherT=other.begin(); + tag_list &operator=(const tag_list &other) + { + s=other.s; - while(myT != end() && otherT != other.end()) - { - // ew, rather slow - if(lexicographical_compare(myT.start, myT.finish, - otherT.start, otherT.finish)) - return -1; - else if(lexicographical_compare(otherT.start, otherT.finish, - myT.start, myT.finish)) - return 1; - - ++myT; - ++otherT; - } + return *this; + } - if(otherT != other.end()) - return -1; - else if(myT != end()) - return 1; - else - return 0; -} + const_iterator begin() const; + const_iterator end() const + { + return const_iterator(s.end(), s.end(), s.end()); + } +}; tag_list::const_iterator &tag_list::const_iterator::operator++() { @@ -118,6 +116,9 @@ tag_list::const_iterator &tag_list::const_iterator::operator++() if(start != limit) // Push past the comma. ++start; + while(start != limit && isspace(*start)) + ++start; + if(start == limit) finish = limit; else @@ -181,16 +182,16 @@ static void reset_tags() tagDB = NULL; } -const set<tag> *get_tags(const pkgCache::PkgIterator &pkg) +const std::set<tag> aptitude::apt::get_tags(const pkgCache::PkgIterator &pkg) { if(!apt_cache_file || !tagDB) - return NULL; + return std::set<tag>(); - return tagDB + pkg->ID; + return tagDB[pkg->ID]; } bool initialized_reset_signal; -void load_tags(OpProgress &progress) +void aptitude::apt::load_tags(OpProgress *progress) { eassert(apt_cache_file && apt_package_records); @@ -214,23 +215,24 @@ void load_tags(OpProgress &progress) sort(verfiles.begin(), verfiles.end(), location_compare()); - progress.OverallProgress(0, verfiles.size(), 1, - _("Building tag database")); + if(progress != NULL) + progress->OverallProgress(0, verfiles.size(), 1, + _("Building tag database")); size_t n=0; for(std::vector<loc_pair>::iterator i=verfiles.begin(); i!=verfiles.end(); ++i) { insert_tags(i->first, i->second); ++n; - progress.OverallProgress(n, verfiles.size(), 1, _("Building tag database")); + if(progress != NULL) + progress->OverallProgress(n, verfiles.size(), 1, + _("Building tag database")); } - progress.Done(); + if(progress != NULL) + progress->Done(); } - - - // TAG VOCABULARY FILE typedef map<string, string> facet_description_map; typedef map<string, string> tag_description_map; @@ -285,10 +287,12 @@ static void init_vocabulary() } } -string facet_description(const std::string &facet) +std::string aptitude::apt::get_facet_long_description(const tag &t) { init_vocabulary(); + const string facet(get_facet_name(t)); + facet_description_map::const_iterator found = facet_descriptions->find(facet); @@ -298,12 +302,20 @@ string facet_description(const std::string &facet) return found->second; } -string tag_description(const std::string &tag) +// FIXME: This code to split long/short descriptions is repeated in +// too many places. +std::string aptitude::apt::get_facet_short_description(const tag &t) +{ + const string desc(get_facet_long_description(t)); + return string(desc, 0, desc.find('\n')); +} + +std::string aptitude::apt::get_tag_long_description(const tag &t) { init_vocabulary(); tag_description_map::const_iterator found = - tag_descriptions->find(tag); + tag_descriptions->find(t); if(found == tag_descriptions->end()) return string(); @@ -311,6 +323,12 @@ string tag_description(const std::string &tag) return found->second; } +std::string aptitude::apt::get_tag_short_description(const tag &t) +{ + const string desc = get_tag_long_description(t); + return string(desc, 0, desc.find('\n')); +} + #else // HAVE_EPT #if defined(HAVE_EPT_DEBTAGS_VOCABULARY_FACET_DATA) || defined(HAVE_EPT_DEBTAGS_VOCABULARY_TAG_DATA) @@ -349,7 +367,7 @@ namespace aptitude } bool initialized_reset_signal; - void load_tags() + void load_tags(OpProgress *progress) { if(!initialized_reset_signal) { @@ -392,26 +410,6 @@ namespace aptitude } } - std::string get_facet_name(const tag &t) - { - const std::string name = get_fullname(t); - std::size_t split_pos = name.find("::"); - if(split_pos == std::string::npos) - return _("legacy"); - else - return std::string(name, 0, split_pos); - } - - std::string get_tag_name(const tag &t) - { - const std::string name = get_fullname(t); - std::size_t split_pos = name.find("::"); - if(split_pos == std::string::npos) - return name; - else - return std::string(name, split_pos + 2); - } - #ifdef HAVE_EPT_DEBTAGS_VOCABULARY_FACET_DATA std::string get_facet_long_description(const tag &t) { @@ -483,3 +481,29 @@ namespace aptitude } #endif // HAVE_EPT + +namespace aptitude +{ + namespace apt + { + std::string get_facet_name(const tag &t) + { + const std::string name = get_fullname(t); + std::size_t split_pos = name.find("::"); + if(split_pos == std::string::npos) + return _("legacy"); + else + return std::string(name, 0, split_pos); + } + + std::string get_tag_name(const tag &t) + { + const std::string name = get_fullname(t); + std::size_t split_pos = name.find("::"); + if(split_pos == std::string::npos) + return name; + else + return std::string(name, split_pos + 2); + } + } +} diff --git a/src/generic/apt/tags.h b/src/generic/apt/tags.h index 6ec61a14..c4f27e8b 100644 --- a/src/generic/apt/tags.h +++ b/src/generic/apt/tags.h @@ -25,215 +25,30 @@ #include <config.h> #endif -// If ept is unavailable, we use our own (broken!) code to build an -// in-memory database of package tags. Otherwise, this code just -// handles initializing it, destroying it, and extracting information -// from it. Note that this means that all callers have to be -// conditionalized on HAVE_EPT: the "tag" class this used to return is -// broken wrt hierarchies and just using ept is simpler. +#ifdef HAVE_EPT +#include <ept/debtags/debtags.h> +#endif // HAVE_EPT -#ifndef HAVE_EPT +#include <apt-pkg/pkgcache.h> #include <set> #include <string> -#include <apt-pkg/pkgcache.h> - -/** \brief A parser for tags. - * - * \file tags.h - */ +#ifndef HAVE_EPT +#define DEBTAGS_ARE_STRINGS 1 +#else +#ifdef EPT_DEBTAGS_GETTAGSOFITEM_RETURNS_STRINGS +#define DEBTAGS_ARE_STRINGS 1 +#endif +#endif class OpProgress; -class tag -{ - std::string s; - - int cmp(const tag &other) const; -public: - class const_iterator - { - std::string::const_iterator start, finish, limit; - - friend class tag; - public: - const_iterator(const std::string::const_iterator &_start, - const std::string::const_iterator &_finish, - const std::string::const_iterator &_limit) - :start(_start), finish(_finish), limit(_limit) - { - } - - const_iterator &operator++(); - - const_iterator &operator=(const const_iterator &other) - { - start = other.start; - finish = other.finish; - limit = other.limit; - - return *this; - } - - bool operator==(const const_iterator &other) const - { - return start == other.start && finish == other.finish && limit == other.limit; - } - - bool operator!=(const const_iterator &other) const - { - return start != other.start || finish != other.finish || limit != other.limit; - } - - std::string operator*() const - { - return std::string(start, finish); - } - }; - - tag(std::string::const_iterator _start, - std::string::const_iterator _finish); - - tag &operator=(const tag &other) - { - s = other.s; - - return *this; - } - - bool operator<(const tag &other) const - { - return cmp(other) < 0; - } - - bool operator<=(const tag &other) const - { - return cmp(other) <= 0; - } - - bool operator==(const tag &other) const - { - return cmp(other) == 0; - } - - bool operator!=(const tag &other) const - { - return cmp(other) != 0; - } - - bool operator>(const tag &other) const - { - return cmp(other) > 0; - } - - bool operator>=(const tag &other) const - { - return cmp(other) >= 0; - } - - const_iterator begin() const; - const_iterator end() const - { - return const_iterator(s.end(), s.end(), s.end()); - } - - std::string str() const - { - return s; - } -}; - -class tag_list -{ - // The string to parse. - std::string s; -public: - class const_iterator - { - std::string::const_iterator start, finish, limit; - public: - const_iterator(const std::string::const_iterator &_start, - const std::string::const_iterator &_finish, - const std::string::const_iterator &_limit) - :start(_start), finish(_finish), limit(_limit) - { - } - - const_iterator operator=(const const_iterator &other) - { - start = other.start; - finish = other.finish; - limit = other.limit; - - return *this; - } - - bool operator==(const const_iterator &other) - { - return other.start == start && other.finish == finish && other.limit == limit; - } - - bool operator!=(const const_iterator &other) - { - return other.start != start || other.finish != finish || other.limit != limit; - } - - const_iterator &operator++(); - - tag operator*() - { - return tag(start, finish); - } - }; - - tag_list(const char *start, const char *finish) - :s(start, finish) - { - } - - tag_list &operator=(const tag_list &other) - { - s=other.s; - - return *this; - } - - const_iterator begin() const; - const_iterator end() const - { - return const_iterator(s.end(), s.end(), s.end()); - } -}; - -// Grab the tags for the given package: -const std::set<tag> *get_tags(const pkgCache::PkgIterator &pkg); - -// Load tags for all packages (call before get_tags) -void load_tags(OpProgress &progress); - - - -// Interface to the tag vocabulary file; tag vocabularies are assumed -// to not change over time. -std::string facet_description(const std::string &facet); - -// Here "Tag" is a fully qualified tag name. -std::string tag_description(const std::string &tag); - -#else // HAVE_EPT - -#include <apt-pkg/pkgcache.h> - -#include <ept/debtags/debtags.h> - -#include <set> - namespace aptitude { namespace apt { -#ifdef EPT_DEBTAGS_GETTAGSOFITEM_RETURNS_STRINGS +#ifdef DEBTAGS_ARE_STRINGS typedef std::string tag; inline std::string get_fullname(const std::string &t) { @@ -245,10 +60,11 @@ namespace aptitude #error "Don't know how to represent a debtags tag." #endif - const std::set<tag> get_tags(const pkgCache::PkgIterator &pkg); - /** \brief Initialize the cache of debtags information. */ - void load_tags(); + void load_tags(OpProgress *progress = NULL); + + /** /brief Grab the tags for the given package. */ + const std::set<tag> get_tags(const pkgCache::PkgIterator &pkg); /** \brief Get the name of the facet corresponding to a tag. */ std::string get_facet_name(const tag &t); @@ -276,6 +92,11 @@ namespace aptitude } } -#endif // HAVE_EPT +// If ept is unavailable, we use our own (broken!) code to build an +// in-memory database of package tags. Otherwise, this code just +// handles initializing it, destroying it, and extracting information +// from it. Note that this means that all callers have to be +// conditionalized on HAVE_EPT: the "tag" class this used to return is +// broken wrt hierarchies and just using ept is simpler. #endif diff --git a/src/gtk/gui.cc b/src/gtk/gui.cc index b1715bb5..e846f6f2 100644 --- a/src/gtk/gui.cc +++ b/src/gtk/gui.cc @@ -1272,32 +1272,23 @@ namespace gui if(pkg.end()) return where; -#ifdef HAVE_EPT using aptitude::apt::get_fullname; using aptitude::apt::get_tags; using aptitude::apt::tag; - const std::set<tag> realS(get_tags(pkg)); - const std::set<tag> * const s(&realS); -#else - const std::set<tag> * const s(get_tags(pkg)); -#endif + const std::set<tag> s(get_tags(pkg)); - if(s != NULL && !s->empty()) + if(s->empty() == false) { bool first = true; where = buffer->insert_with_tag(where, ssprintf(_("Tags of %s:\n"), pkg.Name()), headerTag); // TODO: indent all the tags. - for(std::set<tag>::const_iterator it = s->begin(); - it != s->end(); ++it) + for(std::set<tag>::const_iterator it = s.begin(); + it != s.end(); ++it) { -#ifdef HAVE_EPT const std::string name(get_fullname(*it)); -#else - const std::string name(it->str()); -#endif if(first) first = false; diff --git a/src/pkg_grouppolicy.cc b/src/pkg_grouppolicy.cc index 5bd8f4af..bc9a5574 100644 --- a/src/pkg_grouppolicy.cc +++ b/src/pkg_grouppolicy.cc @@ -1399,29 +1399,21 @@ public: virtual void add_package(const pkgCache::PkgIterator &pkg, pkg_subtree *root) { -#ifdef HAVE_EPT using aptitude::apt::get_facet_name; using aptitude::apt::get_tag_long_description; using aptitude::apt::get_tag_name; using aptitude::apt::get_tag_short_description; using aptitude::apt::get_tags; using aptitude::apt::tag; -#endif -#ifdef HAVE_EPT - const set<tag> realTags(get_tags(pkg)); - const set<tag> * const tags(&realTags); -#else - const set<tag> * const tags(get_tags(pkg)); -#endif + const set<tag> tags(get_tags(pkg)); - if(tags != NULL) + if(tags.empty() == true) return; - for(set<tag>::const_iterator ti = tags->begin(); - ti != tags->end(); ++ti) + for(set<tag>::const_iterator ti = tags.begin(); + ti != tags.end(); ++ti) { -#ifdef HAVE_EPT const std::string thisfacet = get_facet_name(*ti); // Don't create items for tags that aren't in our facet. @@ -1432,23 +1424,6 @@ public: // call it? std::string tagname = get_tag_name(*ti); -#else // HAVE_EPT - tag::const_iterator j = ti->begin(); - if(j == ti->end()) - continue; - - string thisfacet = *j; - - if(thisfacet != match_facet) - continue; - - ++j; - if(j == ti->end()) - continue; - - string tagname = *j; -#endif // HAVE_EPT - childmap::const_iterator found = children.find(tagname); @@ -1457,13 +1432,8 @@ public: if(found == children.end()) { -#ifdef HAVE_EPT const std::string desc = get_tag_long_description(*ti); const std::string shortdesc = get_tag_short_description(*ti); -#else // HAVE_EPT - string desc = tag_description(ti->str()); - string shortdesc(desc, 0, desc.find('\n')); -#endif subtree = new pkg_subtree(swsprintf(L"%s - %s", tagname.c_str(), @@ -1538,20 +1508,13 @@ public: virtual void add_package(const pkgCache::PkgIterator &pkg, pkg_subtree *root) { -#ifdef HAVE_EPT using aptitude::apt::get_tags; using aptitude::apt::tag; -#endif -#ifdef HAVE_EPT - const set<tag> realTags(get_tags(pkg)); - const set<tag> * const tags(&realTags); -#else - const set<tag> * const tags(get_tags(pkg)); -#endif + const set<tag> tags(get_tags(pkg)); // Put all untagged, non-virtual packages into a separate list. - if((tags == NULL || tags->empty()) && !pkg.VersionList().end()) + if(tags.empty() == true && !pkg.VersionList().end()) { if(untagged_tree == NULL) { @@ -1569,13 +1532,12 @@ public: untagged_policy->add_package(pkg, untagged_tree); } - if(tags == NULL) + if(tags.empty() == true) return; - for(set<tag>::const_iterator ti = tags->begin(); - ti != tags->end(); ++ti) + for(set<tag>::const_iterator ti = tags.begin(); + ti != tags.end(); ++ti) { -#ifdef HAVE_EPT using aptitude::apt::get_facet_long_description; using aptitude::apt::get_facet_name; using aptitude::apt::get_facet_short_description; @@ -1585,23 +1547,6 @@ public: std::string thisfacet(get_facet_name(*ti)); std::string thistag(get_tag_name(*ti)); -#else // HAVE_EPT - tag::const_iterator j = ti->begin(); - - eassert(j != ti->end()); - - string thisfacet = *j; - - if(j != ti->end()) - ++j; - - string thistag; - - if(j == ti->end()) - thistag = _("MISSING TAG"); - else - thistag = *j; -#endif facetmap::const_iterator facetfound = children.find(thisfacet); @@ -1611,13 +1556,8 @@ public: if(facetfound == children.end()) { -#ifdef HAVE_EPT string desc(get_facet_long_description(*ti)); string shortdesc(get_facet_short_description(*ti)); -#else // HAVE_EPT - string desc = facet_description(thisfacet); - string shortdesc(desc, 0, desc.find('\n')); -#endif if(!shortdesc.empty()) tagtree = new pkg_subtree(swsprintf(L"%s - %s", @@ -1649,13 +1589,8 @@ public: if(tagfound == tagchildren->end()) { -#ifdef HAVE_EPT string desc(get_tag_long_description(*ti)); string shortdesc(get_tag_short_description(*ti)); -#else // HAVE_EPT - string desc = tag_description(ti->str()); - string shortdesc(desc, 0, desc.find('\n')); -#endif if(!shortdesc.empty()) subtree = new pkg_subtree(swsprintf(L"%s - %s", |