summaryrefslogtreecommitdiff
path: root/src/cmdline/cmdline_util.cc
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2008-03-04 21:09:43 -0800
committerDaniel Burrows <dburrows@debian.org>2008-03-04 21:09:43 -0800
commit751774f43bd3d161809e4dcae16275d961826025 (patch)
tree96bff02984f92bb07256c87582a9666ddff52012 /src/cmdline/cmdline_util.cc
parentd1e9f91dbe95ed1266839d0db47166c71a01568a (diff)
downloadaptitude-751774f43bd3d161809e4dcae16275d961826025.tar.gz
Add support for adding user tags to the packages modified by a command.
I've gone back and forth a few times on the ideal semantics here. It might be nice if the program could automagically guess the packages that the user "meant" to target and only tag up those, but this requires some smarts and I suspect it would be unpredictable (bad!). The current compromise is that implicit tagging (with no pattern saying which packages should be tagged up) will just tag up anything that's being installed, upgraded, or removed; that covers several common cases and is straightforward to implement and understand. Perhaps once this is in the wild I'll have more information about how people use it on which to base an informed decision.
Diffstat (limited to 'src/cmdline/cmdline_util.cc')
-rw-r--r--src/cmdline/cmdline_util.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/cmdline/cmdline_util.cc b/src/cmdline/cmdline_util.cc
index 25a21d3b..4197bdf2 100644
--- a/src/cmdline/cmdline_util.cc
+++ b/src/cmdline/cmdline_util.cc
@@ -16,6 +16,7 @@
#include <generic/apt/config_signal.h>
#include <generic/apt/download_manager.h>
#include <generic/apt/download_signal_log.h>
+#include <generic/apt/matchers.h>
#include <cwidget/fragment.h>
#include <cwidget/toplevel.h>
@@ -362,3 +363,49 @@ bool cmdline_is_search_pattern(const std::string &s)
{
return s.find_first_of("~?") != s.npos;
}
+
+namespace aptitude
+{
+ namespace cmdline
+ {
+ void apply_user_tags(const std::vector<tag_application> &user_tags)
+ {
+ using namespace matching;
+ for(pkgCache::PkgIterator pkg = (*apt_cache_file)->PkgBegin();
+ !pkg.end(); ++pkg)
+ {
+ for(std::vector<tag_application>::const_iterator it =
+ user_tags.begin(); it != user_tags.end(); ++it)
+ {
+ bool applicable = false;
+ if(it->get_matcher() != NULL)
+ {
+ if(matching::apply_matcher(it->get_matcher(), pkg,
+ *apt_cache_file,
+ *apt_package_records))
+ applicable = true;
+ }
+ else
+ {
+ const pkgDepCache::StateCache &state = (*apt_cache_file)[pkg];
+ // Perhaps we should somehow filter out automatic
+ // changes here, but that's hard and might be
+ // unpredictable (which would make the user sad).
+ // Instead we just add the tag to all packages that
+ // are being modified.
+ if(!state.Keep())
+ applicable = true;
+ }
+
+ if(applicable)
+ {
+ if(it->get_is_add())
+ (*apt_cache_file)->attach_user_tag(pkg, it->get_tag(), NULL);
+ else
+ (*apt_cache_file)->detach_user_tag(pkg, it->get_tag(), NULL);
+ }
+ }
+ }
+ }
+ }
+}