summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Partap <mpartap@gmx.net>2012-06-29 14:43:34 +0200
committerDaniel Hartwig <mandyke@gmail.com>2012-06-30 19:28:58 +0800
commit727a5108ccd012e2cc04d12f0710987535272256 (patch)
treef2d95db95b6313be556bb276feb9cf6b9450ded0
parent99e7df86764dc815bbaf59551439824d22928641 (diff)
downloadaptitude-727a5108ccd012e2cc04d12f0710987535272256.tar.gz
Shamelessly copy installsize sortpolicy as debsize sortpolicy
-rw-r--r--NEWS3
-rw-r--r--src/load_sortpolicy.cc16
-rw-r--r--src/pkg_sortpolicy.cc15
-rw-r--r--src/pkg_sortpolicy.h1
4 files changed, 35 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 0b018390..9c5d3873 100644
--- a/NEWS
+++ b/NEWS
@@ -104,6 +104,9 @@ ii. to make the program more atomic and reliable when used
* [all]: Support downloading changelogs for packages on
third-party sites by guessing the URI. (LP: #563155)
+
+ * [all]: New sort policy 'debsize' for sorting by package size.
+ Thanks to Marcel Partap.
- Minor bugs:
diff --git a/src/load_sortpolicy.cc b/src/load_sortpolicy.cc
index 895573fc..7ec9b26a 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_debsize_policy(const arglist &args,
+ pkg_sortpolicy *chain,
+ bool reversed)
+{
+ if(args.size()>0)
+ {
+ _error->Error(_("Sorting policy '%s' takes no arguments"), "debsize");
+ return NULL;
+ }
+
+ return pkg_sortpolicy_debsize(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["debsize"]=parse_debsize_policy;
parse_types["priority"]=parse_priority_policy;
initted_parse_types=true;
}
diff --git a/src/pkg_sortpolicy.cc b/src/pkg_sortpolicy.cc
index bb0578ae..62081f6e 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;);
+// debsize-sorting, treats virtual packages as 0-size
+PKG_SORTPOLICY_SUBCLASS(pkg_sortpolicy_debsize,
+ 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 40866be3..3685ab1c 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_debsize(pkg_sortpolicy *chain, bool reversed);
pkg_sortpolicy *pkg_sortpolicy_priority(pkg_sortpolicy *chain, bool reversed);
// ewwwwwwww.