[Aptitude-devel] [PATCH 2/3] Shamelessly copy installsize sortpolicy as size sortpolicy

Marcel Partap mpartap at gmx.net
Fri Jun 29 13:43:34 BST 2012


---
 src/load_sortpolicy.cc |   16 ++++++++++++++++
 src/pkg_sortpolicy.cc  |   15 +++++++++++++++
 src/pkg_sortpolicy.h   |    1 +
 3 files changed, 32 insertions(+)

diff --git a/src/load_sortpolicy.cc b/src/load_sortpolicy.cc
index 895573f..a84b2eb 100644
--- a/src/load_sortpolicy.cc
+++ b/src/load_sortpolicy.cc
@@ -94,6 +94,21 @@ pkg_sortpolicy *parse_priority_policy(const arglist &args,
   return pkg_sortpolicy_priority(chain, reversed);
 }
 
+
+pkg_sortpolicy *parse_size_policy(const arglist &args,
+					 pkg_sortpolicy *chain,
+					 bool reversed)
+{
+  if(args.size()>0)
+    {
+      _error->Error(_("Sorting policy '%s' takes no arguments"), "size");
+      return NULL;
+    }
+
+  return pkg_sortpolicy_size(chain, reversed);
+}
+
+
 static parser_map parse_types;
 
 static void init_parse_types()
@@ -105,6 +120,7 @@ static void init_parse_types()
       parse_types["name"]=parse_name_policy;
       parse_types["version"] = parse_ver_policy;
       parse_types["installsize"]=parse_installsize_policy;
+      parse_types["size"]=parse_size_policy;
       parse_types["priority"]=parse_priority_policy;
       initted_parse_types=true;
     }
diff --git a/src/pkg_sortpolicy.cc b/src/pkg_sortpolicy.cc
index bb0578a..39e9444 100644
--- a/src/pkg_sortpolicy.cc
+++ b/src/pkg_sortpolicy.cc
@@ -161,6 +161,21 @@ PKG_SORTPOLICY_SUBCLASS(pkg_sortpolicy_priority,
 			else // if(pri1>pri2)
 			  return 1;);
 
+// size-sorting, treats virtual packages as 0-size
+PKG_SORTPOLICY_SUBCLASS(pkg_sortpolicy_size,
+			if(ver1.end() && ver2.end())
+			  return 0;
+			else if(ver1.end())
+			  return 1;
+			else if(ver2.end())
+			  return -1;
+			else if(ver1->Size<ver2->Size)
+			  return -1;
+			else if(ver1->Size>ver2->Size)
+			  return 1;
+			else
+			  return 0;);
+
 // Sort by version number
 PKG_SORTPOLICY_SUBCLASS(pkg_sortpolicy_ver,
 			if(ver1.end())
diff --git a/src/pkg_sortpolicy.h b/src/pkg_sortpolicy.h
index 40866be..d8078db 100644
--- a/src/pkg_sortpolicy.h
+++ b/src/pkg_sortpolicy.h
@@ -63,6 +63,7 @@ public:
 pkg_sortpolicy *pkg_sortpolicy_name(pkg_sortpolicy *chain, bool reversed);
 pkg_sortpolicy *pkg_sortpolicy_ver(pkg_sortpolicy *chain, bool reversed);
 pkg_sortpolicy *pkg_sortpolicy_installed_size(pkg_sortpolicy *chain, bool reversed);
+pkg_sortpolicy *pkg_sortpolicy_size(pkg_sortpolicy *chain, bool reversed);
 pkg_sortpolicy *pkg_sortpolicy_priority(pkg_sortpolicy *chain, bool reversed);
 
 // ewwwwwwww.
-- 
1.7.10.4




More information about the Aptitude-devel mailing list