summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2011-04-10 18:43:19 -0700
committerDaniel Burrows <dburrows@debian.org>2011-04-10 18:44:51 -0700
commit66adb6c872f7b49279da43601e7d3ff199996c1a (patch)
treeb29728a0632182c775c8faffcedc4830ffe8d495 /src
parent9bccc6745be8f133b2fc3af86ce939b822fc6f35 (diff)
downloadaptitude-66adb6c872f7b49279da43601e7d3ff199996c1a.tar.gz
Add a new "source" grouping policy, which groups packages according to their source package.
Closes: #497206; thanks to Thadeu Lima de Sourza Cascardo for the patch. Didn't merge the part of the patch that adds an entry to the Views menu, as I don't personally believe that this grouping needs its own entry there.
Diffstat (limited to 'src')
-rw-r--r--src/load_grouppolicy.cc13
-rw-r--r--src/pkg_grouppolicy.cc64
-rw-r--r--src/pkg_grouppolicy.h14
3 files changed, 91 insertions, 0 deletions
diff --git a/src/load_grouppolicy.cc b/src/load_grouppolicy.cc
index 83ed79c6..a75e21e2 100644
--- a/src/load_grouppolicy.cc
+++ b/src/load_grouppolicy.cc
@@ -536,6 +536,18 @@ class firstchar_policy_parser : public string_policy_parser
}
};
+class source_policy_parser : public string_policy_parser
+{
+public:
+ group_policy_parse_node *create_node(const vector<string> &args)
+ {
+ if(args.size()!=0)
+ throw GroupParseException(_("Too many arguments to by-source grouping policy"));
+
+ return new policy_node0<pkg_grouppolicy_source_factory>;
+ }
+};
+
class ver_policy_parser : public string_policy_parser
{
group_policy_parse_node *create_node(const vector<string> &args)
@@ -758,6 +770,7 @@ static void init_parse_types()
parse_types["action"]=new mode_policy_parser;
parse_types["filter"]=new filter_policy_parser;
parse_types["firstchar"]=new firstchar_policy_parser;
+ parse_types["source"]=new source_policy_parser;
parse_types["versions"]=new ver_policy_parser;
parse_types["deps"]=new dep_policy_parser;
diff --git a/src/pkg_grouppolicy.cc b/src/pkg_grouppolicy.cc
index 2510e581..29eee4b9 100644
--- a/src/pkg_grouppolicy.cc
+++ b/src/pkg_grouppolicy.cc
@@ -1659,3 +1659,67 @@ pkg_grouppolicy_facet_tag_factory::~pkg_grouppolicy_facet_tag_factory()
{
delete chain;
}
+
+
+/*****************************************************************************/
+
+// Groups packages by source package
+class pkg_grouppolicy_source:public pkg_grouppolicy
+{
+ typedef map<string,
+ pair<pkg_grouppolicy *, pkg_subtree *> > childmap;
+
+ childmap children;
+ pkg_grouppolicy_factory *chain;
+
+ pkg_grouppolicy *spillover;
+public:
+ pkg_grouppolicy_source(pkg_grouppolicy_factory *_chain,
+ pkg_signal *_sig, desc_signal *_desc_sig)
+ :pkg_grouppolicy(_sig, _desc_sig),
+ chain(_chain),
+ spillover(_chain->instantiate(get_sig(), get_desc_sig()))
+ {
+ }
+
+ ~pkg_grouppolicy_source()
+ {
+ for(childmap::iterator i = children.begin(); i != children.end(); ++i)
+ delete i->second.first;
+ }
+
+ void add_package(const pkgCache::PkgIterator &pkg, pkg_subtree *root)
+ {
+ if(pkg.VersionList().end() || pkg.VersionList().FileList().end())
+ return;
+ std::string source_package_name =
+ apt_package_records->Lookup(pkg.VersionList().FileList()).SourcePkg();
+ if(source_package_name.length() == 0)
+ source_package_name = pkg.Name();
+
+ childmap::iterator found = children.find(source_package_name);
+
+ if(found != children.end())
+ found->second.first->add_package(pkg, found->second.second);
+ else
+ {
+ pkg_subtree *newtree = new pkg_subtree(cw::util::transcode(source_package_name),
+ L"",
+ get_desc_sig());
+ pkg_grouppolicy *newchild = chain->instantiate(get_sig(),
+ get_desc_sig());
+ children[source_package_name].first = newchild;
+ children[source_package_name].second = newtree;
+ root->add_child(newtree);
+ newtree->set_num_packages_parent(root);
+
+ newchild->add_package(pkg, newtree);
+ }
+ }
+};
+
+pkg_grouppolicy *pkg_grouppolicy_source_factory::instantiate(pkg_signal *sig,
+ desc_signal *desc_sig)
+{
+ return new pkg_grouppolicy_source(chain, sig, desc_sig);
+}
diff --git a/src/pkg_grouppolicy.h b/src/pkg_grouppolicy.h
index 70e38447..f9169e21 100644
--- a/src/pkg_grouppolicy.h
+++ b/src/pkg_grouppolicy.h
@@ -377,4 +377,18 @@ public:
~pkg_grouppolicy_facet_tag_factory();
};
+// Groups by source package
+class pkg_grouppolicy_source_factory:public pkg_grouppolicy_factory
+{
+ pkg_grouppolicy_factory *chain;
+public:
+ pkg_grouppolicy_source_factory(pkg_grouppolicy_factory *_chain):chain(_chain) {}
+
+ pkg_grouppolicy *instantiate(pkg_signal *_sig,
+ desc_signal *_desc_sig);
+
+ virtual ~pkg_grouppolicy_source_factory()
+ {delete chain;}
+};
+
#endif