]> git.saurik.com Git - apt.git/blame - apt-private/private-depends.cc
Add bash-completion support for the "apt" command
[apt.git] / apt-private / private-depends.cc
CommitLineData
9055d5e6
DK
1// Include Files /*{{{*/
2#include<config.h>
3
4#include <apt-pkg/algorithms.h>
5#include <apt-pkg/cachefile.h>
6#include <apt-pkg/cacheiterators.h>
7#include <apt-pkg/cacheset.h>
8#include <apt-pkg/configuration.h>
9#include <apt-pkg/cmndline.h>
10#include <apt-pkg/error.h>
11#include <apt-pkg/pkgcache.h>
12
13#include <apt-private/private-cacheset.h>
14#include <apt-private/private-depends.h>
15
16#include <iostream>
17#include <string>
18#include <vector>
19
20#include <stddef.h>
21
22#include <apti18n.h>
23 /*}}}*/
24
25// ShowDepends - Helper for printing out a dependency tree /*{{{*/
26static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
27{
28 pkgCacheFile CacheFile;
29 pkgCache *Cache = CacheFile.GetPkgCache();
30 if (unlikely(Cache == NULL))
31 return false;
32
33 CacheSetHelperVirtuals helper(false);
34 APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
35 if (verset.empty() == true && helper.virtualPkgs.empty() == true)
36 return _error->Error(_("No packages found"));
37 std::vector<bool> Shown(Cache->Head().PackageCount);
38
39 bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
40 bool const Installed = _config->FindB("APT::Cache::Installed", false);
41 bool const Important = _config->FindB("APT::Cache::Important", false);
42 bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
43 bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
44 bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
45 bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
46 bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
47 bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
48 bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
49 bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
50 bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
51 bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
52 bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
53 bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
54
55 while (verset.empty() != true)
56 {
57 pkgCache::VerIterator Ver = *verset.begin();
58 verset.erase(verset.begin());
59 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
60 Shown[Pkg->ID] = true;
61
62 std::cout << Pkg.FullName(true) << std::endl;
63
64 if (RevDepends == true)
65 std::cout << "Reverse Depends:" << std::endl;
66 for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
67 D.end() == false; ++D)
68 {
69 switch (D->Type) {
70 case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
71 case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
72 case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
73 case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
74 case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
75 case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
76 case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
77 case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
78 }
79 if (ShowImplicit == false && D.IsImplicit())
80 continue;
81
82 pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
83
84 if((Installed && Trg->CurrentVer != 0) || !Installed)
85 {
86
87 if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
88 std::cout << " |";
89 else
90 std::cout << " ";
91
92 // Show the package
93 if (ShowDepType == true)
94 std::cout << D.DepType() << ": ";
95 if (Trg->VersionList == 0)
96 std::cout << "<" << Trg.FullName(true) << ">";
97 else
98 std::cout << Trg.FullName(true);
99 if (ShowVersion == true && D->Version != 0)
100 std::cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
101 std::cout << std::endl;
102
103 if (Recurse == true && Shown[Trg->ID] == false)
104 {
105 Shown[Trg->ID] = true;
106 verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
107 }
108
109 }
110
111 // Display all solutions
112 std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
113 pkgPrioSortList(*Cache,List.get());
114 for (pkgCache::Version **I = List.get(); *I != 0; I++)
115 {
116 pkgCache::VerIterator V(*Cache,*I);
117 if (V != Cache->VerP + V.ParentPkg()->VersionList ||
118 V->ParentPkg == D->Package)
119 continue;
120 std::cout << " " << V.ParentPkg().FullName(true) << std::endl;
121
122 if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
123 {
124 Shown[V.ParentPkg()->ID] = true;
125 verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
126 }
127 }
128
129 if (ShowOnlyFirstOr == true)
130 while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
131 }
132 }
133
134 for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
135 Pkg != helper.virtualPkgs.end(); ++Pkg)
136 std::cout << '<' << Pkg.FullName(true) << '>' << std::endl;
137
138 return true;
139}
140 /*}}}*/
141// Depends - Print out a dependency tree /*{{{*/
142bool Depends(CommandLine &CmdL)
143{
144 return ShowDepends(CmdL, false);
145}
146 /*}}}*/
147// RDepends - Print out a reverse dependency tree /*{{{*/
148bool RDepends(CommandLine &CmdL)
149{
150 return ShowDepends(CmdL, true);
151}
152 /*}}}*/