]>
git.saurik.com Git - apt.git/blob - apt-private/private-depends.cc
1 // Include Files /*{{{*/
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>
13 #include <apt-private/private-cacheset.h>
14 #include <apt-private/private-depends.h>
25 // ShowDepends - Helper for printing out a dependency tree /*{{{*/
26 static bool ShowDepends(CommandLine
&CmdL
, bool const RevDepends
)
28 pkgCacheFile CacheFile
;
29 pkgCache
* const Cache
= CacheFile
.GetPkgCache();
30 if (unlikely(Cache
== nullptr || CacheFile
.GetDepCache() == nullptr))
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
);
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);
55 while (verset
.empty() != true)
57 pkgCache::VerIterator Ver
= *verset
.begin();
58 verset
.erase(verset
.begin());
59 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
60 Shown
[Pkg
->ID
] = true;
62 std::cout
<< Pkg
.FullName(true) << std::endl
;
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
)
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;
79 if (ShowImplicit
== false && D
.IsImplicit())
82 pkgCache::PkgIterator Trg
= RevDepends
? D
.ParentPkg() : D
.TargetPkg();
84 if((Installed
&& Trg
->CurrentVer
!= 0) || !Installed
)
87 if ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
&& ShowOnlyFirstOr
== false)
93 if (ShowDepType
== true)
94 std::cout
<< D
.DepType() << ": ";
95 if (Trg
->VersionList
== 0)
96 std::cout
<< "<" << Trg
.FullName(true) << ">";
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
;
103 if (Recurse
== true && Shown
[Trg
->ID
] == false)
105 Shown
[Trg
->ID
] = true;
106 verset
.insert(APT::VersionSet::FromPackage(CacheFile
, Trg
, APT::CacheSetHelper::CANDIDATE
, helper
));
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
++)
116 pkgCache::VerIterator
V(*Cache
,*I
);
117 if (V
!= Cache
->VerP
+ V
.ParentPkg()->VersionList
||
118 V
->ParentPkg
== D
->Package
)
120 std::cout
<< " " << V
.ParentPkg().FullName(true) << std::endl
;
122 if (Recurse
== true && Shown
[V
.ParentPkg()->ID
] == false)
124 Shown
[V
.ParentPkg()->ID
] = true;
125 verset
.insert(APT::VersionSet::FromPackage(CacheFile
, V
.ParentPkg(), APT::CacheSetHelper::CANDIDATE
, helper
));
129 if (ShowOnlyFirstOr
== true)
130 while ((D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
) ++D
;
134 for (APT::PackageSet::const_iterator Pkg
= helper
.virtualPkgs
.begin();
135 Pkg
!= helper
.virtualPkgs
.end(); ++Pkg
)
136 std::cout
<< '<' << Pkg
.FullName(true) << '>' << std::endl
;
141 // Depends - Print out a dependency tree /*{{{*/
142 bool Depends(CommandLine
&CmdL
)
144 return ShowDepends(CmdL
, false);
147 // RDepends - Print out a reverse dependency tree /*{{{*/
148 bool RDepends(CommandLine
&CmdL
)
150 return ShowDepends(CmdL
, true);