From 590590d0eef2fe6903574a956f83f0fd3d0a31f1 Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Thu, 28 Jun 2012 12:09:44 +0800 Subject: ?architecture supports arch specification strings, wildcards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See Debian Policy § 11.1 for more info. --- NEWS | 5 +++ doc/en/aptitude.xml | 12 +++++++ src/generic/apt/matching/compare_patterns.cc | 3 +- src/generic/apt/matching/match.cc | 6 ++-- src/generic/apt/matching/pattern.cc | 11 ++++++ src/generic/apt/matching/pattern.h | 53 +++++++++++++++++++++++----- src/generic/apt/matching/serialize.cc | 2 +- 7 files changed, 80 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index dbd69371..6d65be82 100644 --- a/NEWS +++ b/NEWS @@ -118,6 +118,11 @@ behaviour is desirable for two reasons: * New configuration item: Aptitude::CmdLine::Sorting, equivalent to --sort + * [all]: ?architecture search terms now support using specification + strings and wildcards (for example, “linux-any”) as defined + in Debian Policy § 11.1 “Architecture specification + strings”. + - Minor bugs: * handle "-qq" like other apt-utils diff --git a/doc/en/aptitude.xml b/doc/en/aptitude.xml index 3c3711b5..4f448720 100644 --- a/doc/en/aptitude.xml +++ b/doc/en/aptitude.xml @@ -6212,6 +6212,18 @@ e: Examine !: Apply .: Next ,: Previous special values native and foreign. + + + The value of architecture can + also be an architecture specification string as defined + in Debian Policy § 11.1 Architecture + specification strings. These are strings of the + form os-arch, + where either component can be the wildcard + any. For example, + any-i386 or + linux-any. + diff --git a/src/generic/apt/matching/compare_patterns.cc b/src/generic/apt/matching/compare_patterns.cc index 7e5159ef..f8414aef 100644 --- a/src/generic/apt/matching/compare_patterns.cc +++ b/src/generic/apt/matching/compare_patterns.cc @@ -99,7 +99,8 @@ namespace aptitude p2->get_any_version_pattern()); case pattern::architecture: - return p1->get_architecture_architecture().compare(p2->get_architecture_architecture()); + return p1->get_architecture_arch_specification()->get_specification() + .compare(p2->get_architecture_arch_specification()->get_specification()); case pattern::automatic: return 0; diff --git a/src/generic/apt/matching/match.cc b/src/generic/apt/matching/match.cc index 0fc2e191..20545294 100644 --- a/src/generic/apt/matching/match.cc +++ b/src/generic/apt/matching/match.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -907,8 +908,9 @@ namespace aptitude { pkgCache::VerIterator ver(target.get_version_iterator(cache)); - if(p->get_architecture_architecture().empty() == true || - p->get_architecture_architecture() == ver.Arch()) + const ref_ptr spec(p->get_architecture_arch_specification()); + + if(spec->matches(ver.Arch()) == true) return match::make_atomic(p, ver.Arch()); else return NULL; diff --git a/src/generic/apt/matching/pattern.cc b/src/generic/apt/matching/pattern.cc index 5743a2a7..56cea314 100644 --- a/src/generic/apt/matching/pattern.cc +++ b/src/generic/apt/matching/pattern.cc @@ -71,6 +71,17 @@ namespace aptitude return 0 == regexec(&r, s, num_matches, matches, eflags); } + arch_specification::arch_specification(const std::string &_spec) + : pams(_spec), + spec(_spec) + { + } + + bool arch_specification::matches(const char * const &arch) + { + return pams(arch); + } + cwidget::util::ref_ptr pattern::make_action(const action_type act) { diff --git a/src/generic/apt/matching/pattern.h b/src/generic/apt/matching/pattern.h index 5aad42f8..b1870acd 100644 --- a/src/generic/apt/matching/pattern.h +++ b/src/generic/apt/matching/pattern.h @@ -33,6 +33,8 @@ #include #include +#include + namespace aptitude { @@ -55,6 +57,28 @@ namespace aptitude std::string errmsg() const; }; + /** \brief Ref-counted wrapper for PackageArchitectureMatchesSpecification. + */ + class arch_specification : public util::refcounted_base_threadsafe + { + APT::CacheFilter::PackageArchitectureMatchesSpecification pams; + const std::string spec; + + public: + arch_specification(const std::string &_spec); + + bool matches(const char * const &arch); + inline bool matches(const pkgCache::VerIterator &ver) + { + return matches(ver.Arch()); + } + + inline const std::string &get_specification() const + { + return spec; + } + }; + /** \brief C++ wrapper for regular expression objects. * * This class turns compilation errors into exceptions and @@ -238,11 +262,12 @@ namespace aptitude * Fields: pattern. */ any_version, - /** \brief ?architecture(PATTERN) + /** \brief ?architecture(SPECIFICATION) * - * Matches packages by their architecture. + * Matches packages whose architecture meets the given + * SPECIFICATION string (see Debian Policy section 11.1). * - * Fields: regex_info. + * Fields: arch_specification. */ architecture, /** \brief ?automatic @@ -669,6 +694,8 @@ namespace aptitude // to the action match information. std::string string_info; + cwidget::util::ref_ptr arch_spec; + // Groups several POD values that aren't used simultaneously. union { @@ -804,6 +831,14 @@ namespace aptitude info.multiarch = multiarch_type; } + // Allocate a pattern that has an architecture specification. + pattern(type _tp, + const cwidget::util::ref_ptr &spec) + : tp(_tp), + arch_spec(spec) + { + } + public: /** \name archive term constructor and accessors. */ @@ -907,19 +942,21 @@ namespace aptitude /** \brief Create an ?architecture term. * - * \param arch The architecture to match. + * \param spec The architecture specification string to match. */ static cwidget::util::ref_ptr - make_architecture(const std::string &arch) + make_architecture(const std::string &spec) { - return new pattern(architecture, arch); + return new pattern(architecture, + new arch_specification(spec)); } - const std::string &get_architecture_architecture() const + const cwidget::util::ref_ptr & + get_architecture_arch_specification() const { eassert(tp == architecture); - return string_info; + return arch_spec; } // @} diff --git a/src/generic/apt/matching/serialize.cc b/src/generic/apt/matching/serialize.cc index 428bc30c..ea506b1f 100644 --- a/src/generic/apt/matching/serialize.cc +++ b/src/generic/apt/matching/serialize.cc @@ -254,7 +254,7 @@ namespace aptitude case pattern::architecture: out << "?architecture("; - serialize_string(p->get_architecture_architecture(), out); + serialize_string(p->get_architecture_arch_specification()->get_specification(), out); out.put(')'); break; -- cgit v1.2.3