Просмотр исходного кода

* add Debug::pkgDepCache::Marker with more detailed debug output
* add Debug::pkgProblemResolver::ShowScores and make the scores
adjustable

Michael Vogt лет назад: 17
Родитель
Сommit
8b4894fe9e
5 измененных файлов с 84 добавлено и 31 удалено
  1. 65 26
      apt-pkg/algorithms.cc
  2. 3 1
      debian/changelog
  3. 11 0
      doc/apt.conf.5.xml
  4. 1 0
      doc/examples/configure-index
  5. 4 4
      po/apt-all.pot

+ 65 - 26
apt-pkg/algorithms.cc

@@ -489,6 +489,34 @@ void pkgProblemResolver::MakeScores()
    unsigned long Size = Cache.Head().PackageCount;
    unsigned long Size = Cache.Head().PackageCount;
    memset(Scores,0,sizeof(*Scores)*Size);
    memset(Scores,0,sizeof(*Scores)*Size);
 
 
+   // Important Required Standard Optional Extra
+   signed short PrioMap[] = {
+      0,
+      _config->FindI("pkgProblemResolver::Scores::Important",3),
+      _config->FindI("pkgProblemResolver::Scores::Required",2),
+      _config->FindI("pkgProblemResolver::Scores::Standard",1),
+      _config->FindI("pkgProblemResolver::Scores::Optional",-1),
+      _config->FindI("pkgProblemResolver::Scores::Extra",-2)
+   };
+   signed short PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100);
+   signed short PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1);
+   signed short PrioDepends = _config->FindI("pkgProblemResolver::Scores::Depends",1);
+   signed short AddProtected = _config->FindI("pkgProblemResolver::Scores::AddProtected",10000);
+   signed short AddEssential = _config->FindI("pkgProblemResolver::Scores::AddEssential",5000);
+
+   if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
+      clog << "Settings used to calculate pkgProblemResolver::Scores::" << endl
+         << "  Important => " << PrioMap[1] << endl
+         << "  Required => " << PrioMap[2] << endl
+         << "  Standard => " << PrioMap[3] << endl
+         << "  Optional => " << PrioMap[4] << endl
+         << "  Extra => " << PrioMap[5] << endl
+         << "  Essentials => " << PrioEssentials << endl
+         << "  InstalledAndNotObsolete => " << PrioInstalledAndNotObsolete << endl
+         << "  Depends => " << PrioDepends << endl
+         << "  AddProtected => " << AddProtected << endl
+         << "  AddEssential => " << AddEssential << endl;
+
    // Generate the base scores for a package based on its properties
    // Generate the base scores for a package based on its properties
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {
    {
@@ -502,11 +530,9 @@ void pkgProblemResolver::MakeScores()
 	 to allow an obsolete essential packages to be removed by
 	 to allow an obsolete essential packages to be removed by
 	 a conflicts on a powerfull normal package (ie libc6) */
 	 a conflicts on a powerfull normal package (ie libc6) */
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
-	 Score += 100;
+	 Score += PrioEssentials;
 
 
       // We transform the priority
       // We transform the priority
-      // Important Required Standard Optional Extra
-      signed short PrioMap[] = {0,3,2,1,-1,-2};
       if (Cache[I].InstVerIter(Cache)->Priority <= 5)
       if (Cache[I].InstVerIter(Cache)->Priority <= 5)
 	 Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority];
 	 Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority];
       
       
@@ -515,7 +541,7 @@ void pkgProblemResolver::MakeScores()
 	 if those are not obsolete
 	 if those are not obsolete
       */
       */
       if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable())
       if (I->CurrentVer != 0 && Cache[I].CandidateVer != 0 && Cache[I].CandidateVerIter(Cache).Downloadable())
-	 Score += 1;
+	 Score += PrioInstalledAndNotObsolete;
    }
    }
 
 
    // Now that we have the base scores we go and propogate dependencies
    // Now that we have the base scores we go and propogate dependencies
@@ -527,7 +553,7 @@ void pkgProblemResolver::MakeScores()
       for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
       for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
       {
       {
 	 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
 	 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
-	    Scores[D.TargetPkg()->ID]++;
+	    Scores[D.TargetPkg()->ID]+= PrioDepends;
       }
       }
    }   
    }   
    
    
@@ -572,10 +598,10 @@ void pkgProblemResolver::MakeScores()
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {
    {
       if ((Flags[I->ID] & Protected) != 0)
       if ((Flags[I->ID] & Protected) != 0)
-	 Scores[I->ID] += 10000;
+	 Scores[I->ID] += AddProtected;
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
-	 Scores[I->ID] += 5000;
-   }   
+	 Scores[I->ID] += AddEssential;
+   }
 }
 }
 									/*}}}*/
 									/*}}}*/
 // ProblemResolver::DoUpgrade - Attempt to upgrade this package		/*{{{*/
 // ProblemResolver::DoUpgrade - Attempt to upgrade this package		/*{{{*/
@@ -751,19 +777,21 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
       *PEnd++ = I;
       *PEnd++ = I;
    This = this;
    This = this;
    qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
    qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
-   
-/* for (pkgCache::Package **K = PList; K != PEnd; K++)
-      if (Scores[(*K)->ID] != 0)
-      {
-	 pkgCache::PkgIterator Pkg(Cache,*K);
-	 clog << Scores[(*K)->ID] << ' ' << Pkg.Name() <<
-	    ' ' << (pkgCache::Version *)Pkg.CurrentVer() << ' ' << 
-	    Cache[Pkg].InstallVer << ' ' << Cache[Pkg].CandidateVer << endl;
-      } */
+
+   if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
+   {
+      clog << "Show Scores" << endl;
+      for (pkgCache::Package **K = PList; K != PEnd; K++)
+         if (Scores[(*K)->ID] != 0)
+         {
+           pkgCache::PkgIterator Pkg(Cache,*K);
+           clog << Scores[(*K)->ID] << ' ' << Pkg << std::endl;
+         }
+   }
 
 
    if (Debug == true)
    if (Debug == true)
       clog << "Starting 2" << endl;
       clog << "Starting 2" << endl;
-   
+
    /* Now consider all broken packages. For each broken package we either
    /* Now consider all broken packages. For each broken package we either
       remove the package or fix it's problem. We do this once, it should
       remove the package or fix it's problem. We do this once, it should
       not be possible for a loop to form (that is a < b < c and fixing b by
       not be possible for a loop to form (that is a < b < c and fixing b by
@@ -878,7 +906,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix)
 	    }
 	    }
 	    
 	    
 	    if (Debug == true)
 	    if (Debug == true)
-	       clog << "Package " << I.Name() << " has broken dep on " << Start.TargetPkg().Name() << endl;
+	       clog << "Package " << I.Name() << " has broken " << Start.DepType() << " on " << Start.TargetPkg().Name() << endl;
 
 
 	    /* Look across the version list. If there are no possible
 	    /* Look across the version list. If there are no possible
 	       targets then we keep the package and bail. This is necessary
 	       targets then we keep the package and bail. This is necessary
@@ -1137,9 +1165,6 @@ bool pkgProblemResolver::ResolveByKeep()
 
 
    unsigned long Size = Cache.Head().PackageCount;
    unsigned long Size = Cache.Head().PackageCount;
 
 
-   if (Debug == true)      
-      clog << "Entering ResolveByKeep" << endl;
-   
    MakeScores();
    MakeScores();
    
    
    /* We have to order the packages so that the broken fixing pass 
    /* We have to order the packages so that the broken fixing pass 
@@ -1152,7 +1177,21 @@ bool pkgProblemResolver::ResolveByKeep()
       *PEnd++ = I;
       *PEnd++ = I;
    This = this;
    This = this;
    qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
    qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
-   
+
+   if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
+   {
+      clog << "Show Scores" << endl;
+      for (pkgCache::Package **K = PList; K != PEnd; K++)
+         if (Scores[(*K)->ID] != 0)
+         {
+           pkgCache::PkgIterator Pkg(Cache,*K);
+           clog << Scores[(*K)->ID] << ' ' << Pkg << std::endl;
+         }
+   }
+
+   if (Debug == true)
+      clog << "Entering ResolveByKeep" << endl;
+
    // Consider each broken package 
    // Consider each broken package 
    pkgCache::Package **LastStop = 0;
    pkgCache::Package **LastStop = 0;
    for (pkgCache::Package **K = PList; K != PEnd; K++)
    for (pkgCache::Package **K = PList; K != PEnd; K++)
@@ -1198,8 +1237,8 @@ bool pkgProblemResolver::ResolveByKeep()
 	 while (true)
 	 while (true)
 	 {
 	 {
 	    if (Debug == true)
 	    if (Debug == true)
-	       clog << "Package " << I.Name() << " has broken dep on " << Start.TargetPkg().Name() << endl;
-	    
+	       clog << "Package " << I.Name() << " has broken " << Start.DepType() << " on " << Start.TargetPkg().Name() << endl;
+
 	    // Look at all the possible provides on this package
 	    // Look at all the possible provides on this package
 	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
 	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
 	    for (pkgCache::Version **V = VList; *V != 0; V++)
 	    for (pkgCache::Version **V = VList; *V != 0; V++)
@@ -1215,7 +1254,7 @@ bool pkgProblemResolver::ResolveByKeep()
 	       if ((Flags[I->ID] & Protected) == 0)
 	       if ((Flags[I->ID] & Protected) == 0)
 	       {
 	       {
 		  if (Debug == true)
 		  if (Debug == true)
-		     clog << "  Keeping Package " << Pkg.Name() << " due to dep" << endl;
+		     clog << "  Keeping Package " << Pkg.Name() << " due to " << Start.DepType() << endl;
 		  Cache.MarkKeep(Pkg, false, false);
 		  Cache.MarkKeep(Pkg, false, false);
 	       }
 	       }
 	       
 	       

+ 3 - 1
debian/changelog

@@ -24,8 +24,10 @@ apt (0.7.22) UNRELEASED; urgency=low
   * support running "--simulate" as user
   * support running "--simulate" as user
   * add depth information to the debug output and show what depends
   * add depth information to the debug output and show what depends
     type triggers a autoinst (closes: #458389)
     type triggers a autoinst (closes: #458389)
-  * add debug::pkgDepCache::Marker with more detailed debug output 
+  * add Debug::pkgDepCache::Marker with more detailed debug output 
     (closes: #87520)
     (closes: #87520)
+  * add Debug::pkgProblemResolver::ShowScores and make the scores
+    adjustable
 
 
   [ Julian Andres Klode ]
   [ Julian Andres Klode ]
   * apt-pkg/contrib/configuration.cc: Fix a small memory leak in
   * apt-pkg/contrib/configuration.cc: Fix a small memory leak in

+ 11 - 0
doc/apt.conf.5.xml

@@ -777,6 +777,17 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
        </listitem>
        </listitem>
      </varlistentry>
      </varlistentry>
 
 
+     <varlistentry>
+       <term><literal>Debug::pkgProblemResolver::ShowScores</literal></term>
+       <listitem>
+        <para>
+          Display a list of all installed packages with their calculated score
+          used by the pkgProblemResolver. The description of the package
+          is the same as described in <literal>Debug::pkgDepCache::Marker</literal>
+        </para>
+       </listitem>
+     </varlistentry>
+
      <varlistentry>
      <varlistentry>
        <term><literal>Debug::sourceList</literal></term>
        <term><literal>Debug::sourceList</literal></term>
 
 

+ 1 - 0
doc/examples/configure-index

@@ -288,6 +288,7 @@ DPkg
 Debug 
 Debug 
 {
 {
   pkgProblemResolver "false";
   pkgProblemResolver "false";
+  pkgProblemResolver::ShowScores "false";
   pkgDepCache::AutoInstall "false"; // what packages apt install to satify dependencies
   pkgDepCache::AutoInstall "false"; // what packages apt install to satify dependencies
   pkgDepCache::Marker "false"; 
   pkgDepCache::Marker "false"; 
   pkgAcquire "false";
   pkgAcquire "false";

+ 4 - 4
po/apt-all.pot

@@ -780,7 +780,7 @@ msgstr ""
 msgid "Do you want to continue [Y/n]? "
 msgid "Do you want to continue [Y/n]? "
 msgstr ""
 msgstr ""
 
 
-#: cmdline/apt-get.cc:984 cmdline/apt-get.cc:2223 apt-pkg/algorithms.cc:1349
+#: cmdline/apt-get.cc:984 cmdline/apt-get.cc:2223 apt-pkg/algorithms.cc:1388
 #, c-format
 #, c-format
 msgid "Failed to fetch %s  %s\n"
 msgid "Failed to fetch %s  %s\n"
 msgstr ""
 msgstr ""
@@ -2302,17 +2302,17 @@ msgid ""
 "The package %s needs to be reinstalled, but I can't find an archive for it."
 "The package %s needs to be reinstalled, but I can't find an archive for it."
 msgstr ""
 msgstr ""
 
 
-#: apt-pkg/algorithms.cc:1107
+#: apt-pkg/algorithms.cc:1135
 msgid ""
 msgid ""
 "Error, pkgProblemResolver::Resolve generated breaks, this may be caused by "
 "Error, pkgProblemResolver::Resolve generated breaks, this may be caused by "
 "held packages."
 "held packages."
 msgstr ""
 msgstr ""
 
 
-#: apt-pkg/algorithms.cc:1109
+#: apt-pkg/algorithms.cc:1137
 msgid "Unable to correct problems, you have held broken packages."
 msgid "Unable to correct problems, you have held broken packages."
 msgstr ""
 msgstr ""
 
 
-#: apt-pkg/algorithms.cc:1375 apt-pkg/algorithms.cc:1377
+#: apt-pkg/algorithms.cc:1414 apt-pkg/algorithms.cc:1416
 msgid ""
 msgid ""
 "Some index files failed to download, they have been ignored, or old ones "
 "Some index files failed to download, they have been ignored, or old ones "
 "used instead."
 "used instead."