summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
authorDaniel Hartwig <mandyke@gmail.com>2012-06-30 17:38:56 +0800
committerDaniel Hartwig <mandyke@gmail.com>2012-06-30 17:38:56 +0800
commitb6855eaa5128fee88b31a0d67f41f1a745a9afcf (patch)
tree7e4ce87af125b5adbb32c95f893d0e19cea76ae0 /src/generic
parent89427f77665e3d66d7229fea4233de6d153ccdeb (diff)
downloadaptitude-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.
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/apt/apt.cc6
-rw-r--r--src/generic/apt/matching/match.cc19
-rw-r--r--src/generic/apt/tags.cc198
-rw-r--r--src/generic/apt/tags.h223
4 files changed, 139 insertions, 307 deletions
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