From fe1af091b871f9af715d729e515f2e3a62802c6f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 16 Jul 2010 17:42:54 +0200 Subject: * cmdline/apt-cache.cc: - be able to omit dependency types in (r)depends (Closes: #319006) --- cmdline/apt-cache.cc | 77 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 15 deletions(-) (limited to 'cmdline/apt-cache.cc') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 338be7029..557996693 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -569,9 +569,18 @@ bool Depends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); - bool Important = _config->FindB("APT::Cache::Important",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); + bool const Installed = _config->FindB("APT::Cache::Installed", false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -594,12 +603,17 @@ bool Depends(CommandLine &CmdL) for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) { - // Important deps only - if (Important == true) - if (D->Type != pkgCache::Dep::PreDepends && - D->Type != pkgCache::Dep::Depends) - continue; - + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + pkgCache::PkgIterator Trg = D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) @@ -611,10 +625,12 @@ bool Depends(CommandLine &CmdL) cout << " "; // Show the package + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else - cout << D.DepType() << ": " << Trg.FullName(true) << endl; + cout << Trg.FullName(true) << endl; if (Recurse == true) Colours[D.TargetPkg()->ID]++; @@ -660,8 +676,18 @@ bool RDepends(CommandLine &CmdL) for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) Colours[Pkg->ID] = 1; - bool Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool Installed = _config->FindB("APT::Cache::Installed",false); + bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); + bool const Installed = _config->FindB("APT::Cache::Installed",false); + bool const Important = _config->FindB("APT::Cache::Important", false); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); + bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); + bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); + bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); + bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); + bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); + bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); + bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); + bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool DidSomething; do { @@ -684,7 +710,18 @@ bool RDepends(CommandLine &CmdL) cout << "Reverse Depends:" << endl; for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { + { + switch (D->Type) { + case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; + case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; + case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; + case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; + case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; + case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; + case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; + case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; + } + // Show the package pkgCache::PkgIterator Trg = D.ParentPkg(); @@ -696,8 +733,10 @@ bool RDepends(CommandLine &CmdL) else cout << " "; + if (ShowDepType == true) + cout << D.DepType() << ": "; if (Trg->VersionList == 0) - cout << D.DepType() << ": <" << Trg.FullName(true) << ">" << endl; + cout << "<" << Trg.FullName(true) << ">" << endl; else cout << Trg.FullName(true) << endl; @@ -1820,6 +1859,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {'c',"config-file",0,CommandLine::ConfigFile}, {'o',"option",0,CommandLine::ArbItem}, {0,"installed","APT::Cache::Installed",0}, + {0,"pre-depends","APT::Cache::ShowPreDepends",0}, + {0,"depends","APT::Cache::ShowDepends",0}, + {0,"recommends","APT::Cache::ShowRecommends",0}, + {0,"suggests","APT::Cache::ShowSuggests",0}, + {0,"replaces","APT::Cache::ShowReplaces",0}, + {0,"breaks","APT::Cache::ShowBreaks",0}, + {0,"conflicts","APT::Cache::ShowConflicts",0}, + {0,"enhances","APT::Cache::ShowEnhances",0}, {0,0,0,0}}; CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp}, {"add",&DoAdd}, -- cgit v1.2.3 From 8fde723961709118837153cdf94f150c680e10e9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Jul 2010 20:04:44 +0200 Subject: * apt-pkg/cacheset.cc: - move them back to the library as they look stable now --- cmdline/apt-cache.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cmdline/apt-cache.cc') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 557996693..1a1ddcb8c 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ #include #include -#include "cacheset.h" - #include #include -- cgit v1.2.3 From a5032f842366f482371173d030e505d79366fd19 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 09:22:53 +0200 Subject: add APT::Cache::ShowOnlyFirstOr option to print only the first alternative in the apt-cache (r)depends commands --- cmdline/apt-cache.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cmdline/apt-cache.cc') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 1a1ddcb8c..88bf3a049 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -580,6 +580,7 @@ bool Depends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -618,7 +619,7 @@ bool Depends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -650,6 +651,9 @@ bool Depends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } @@ -687,6 +691,7 @@ bool RDepends(CommandLine &CmdL) bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); + bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); bool DidSomething; do { @@ -727,7 +732,7 @@ bool RDepends(CommandLine &CmdL) if((Installed && Trg->CurrentVer != 0) || !Installed) { - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) cout << " |"; else cout << " "; @@ -758,6 +763,9 @@ bool RDepends(CommandLine &CmdL) if (Recurse == true) Colours[D.ParentPkg()->ID]++; } + + if (ShowOnlyFirstOr == true) + while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } } } -- cgit v1.2.3 From 3de4647b39216259678f40f4bf6e8122acd923b5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jul 2010 12:43:25 +0200 Subject: - show in (r)depends the canidate per default instead of newest - share the (r)depends code instead of codecopy --- cmdline/apt-cache.cc | 210 ++++++++++++++++----------------------------------- 1 file changed, 64 insertions(+), 146 deletions(-) (limited to 'cmdline/apt-cache.cc') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 88bf3a049..70732e4d0 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -551,27 +551,40 @@ bool DumpAvail(CommandLine &Cmd) return !_error->PendingError(); } /*}}}*/ -// Depends - Print out a dependency tree /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool Depends(CommandLine &CmdL) +// ShowDepends - Helper for printing out a dependency tree /*{{{*/ +class CacheSetHelperDepends: public APT::CacheSetHelper { +public: + APT::PackageSet virtualPkgs; + + virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { + virtualPkgs.insert(Pkg); + return pkgCache::VerIterator(Cache, 0); + } + + CacheSetHelperDepends() : CacheSetHelper(false) {} +}; +bool ShowDepends(CommandLine &CmdL, bool const RevDepends) { pkgCacheFile CacheFile; pkgCache *Cache = CacheFile.GetPkgCache(); if (unlikely(Cache == NULL)) return false; - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; + CacheSetHelperDepends helper; + APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + if (verset.empty() == true && helper.virtualPkgs.empty() == true) + return false; + std::vector Shown(Cache->Head().PackageCount); bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false); bool const Installed = _config->FindB("APT::Cache::Installed", false); bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",true); + bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false); bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); @@ -581,27 +594,20 @@ bool Depends(CommandLine &CmdL) bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do + + while (verset.empty() != true) { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - + pkgCache::VerIterator Ver = *verset.begin(); + verset.erase(verset.begin()); + pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + Shown[Pkg->ID] = true; + cout << Pkg.FullName(true) << endl; - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false; D++) + + if (RevDepends == true) + cout << "Reverse Depends:" << endl; + for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList(); + D.end() == false; D++) { switch (D->Type) { case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; @@ -614,7 +620,7 @@ bool Depends(CommandLine &CmdL) case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; } - pkgCache::PkgIterator Trg = D.TargetPkg(); + pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg(); if((Installed && Trg->CurrentVer != 0) || !Installed) { @@ -632,8 +638,11 @@ bool Depends(CommandLine &CmdL) else cout << Trg.FullName(true) << endl; - if (Recurse == true) - Colours[D.TargetPkg()->ID]++; + if (Recurse == true && Shown[Trg->ID] == false) + { + Shown[Trg->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::VersionSet::CANDIDATE, helper)); + } } @@ -647,131 +656,40 @@ bool Depends(CommandLine &CmdL) V->ParentPkg == D->Package) continue; cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; + + if (Recurse == true && Shown[V.ParentPkg()->ID] == false) + { + Shown[V.ParentPkg()->ID] = true; + verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::VersionSet::CANDIDATE, helper)); + } } if (ShowOnlyFirstOr == true) while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; } - } - } - while (DidSomething == true); - + } + + for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); + Pkg != helper.virtualPkgs.end(); ++Pkg) + cout << '<' << Pkg.FullName(true) << '>' << endl; + return true; } /*}}}*/ -// RDepends - Print out a reverse dependency tree - mbc /*{{{*/ +// Depends - Print out a dependency tree /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool Depends(CommandLine &CmdL) +{ + return ShowDepends(CmdL, false); +} + /*}}}*/ +// RDepends - Print out a reverse dependency tree /*{{{*/ // --------------------------------------------------------------------- /* */ bool RDepends(CommandLine &CmdL) { - pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - - SPtrArray Colours = new unsigned[Cache->Head().PackageCount]; - memset(Colours,0,sizeof(*Colours)*Cache->Head().PackageCount); - - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - Colours[Pkg->ID] = 1; - - bool const Recurse = _config->FindB("APT::Cache::RecurseDepends",false); - bool const Installed = _config->FindB("APT::Cache::Installed",false); - bool const Important = _config->FindB("APT::Cache::Important", false); - bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType",false); - bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true); - bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true); - bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false); - bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false); - bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false); - bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false); - bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false); - bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false); - bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false); - bool DidSomething; - do - { - DidSomething = false; - for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - if (Colours[Pkg->ID] != 1) - continue; - Colours[Pkg->ID] = 2; - DidSomething = true; - - pkgCache::VerIterator Ver = Pkg.VersionList(); - if (Ver.end() == true) - { - cout << '<' << Pkg.FullName(true) << '>' << endl; - continue; - } - - cout << Pkg.FullName(true) << endl; - - cout << "Reverse Depends:" << endl; - for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() == false; D++) - { - switch (D->Type) { - case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break; - case pkgCache::Dep::Depends: if (!ShowDepends) continue; break; - case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break; - case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break; - case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; - case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break; - case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break; - case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break; - } - - // Show the package - pkgCache::PkgIterator Trg = D.ParentPkg(); - - if((Installed && Trg->CurrentVer != 0) || !Installed) - { - - if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false) - cout << " |"; - else - cout << " "; - - if (ShowDepType == true) - cout << D.DepType() << ": "; - if (Trg->VersionList == 0) - cout << "<" << Trg.FullName(true) << ">" << endl; - else - cout << Trg.FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - - } - - // Display all solutions - SPtrArray List = D.AllTargets(); - pkgPrioSortList(*Cache,List); - for (pkgCache::Version **I = List; *I != 0; I++) - { - pkgCache::VerIterator V(*Cache,*I); - if (V != Cache->VerP + V.ParentPkg()->VersionList || - V->ParentPkg == D->Package) - continue; - cout << " " << V.ParentPkg().FullName(true) << endl; - - if (Recurse == true) - Colours[D.ParentPkg()->ID]++; - } - - if (ShowOnlyFirstOr == true) - while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D; - } - } - } - while (DidSomething == true); - - return true; + return ShowDepends(CmdL, true); } /*}}}*/ // xvcg - Generate a graph for xvcg /*{{{*/ -- cgit v1.2.3