Browse Source

versionmatch: Extract version match checking out of Find()

Refactor version matching to allow us to check if a version matches
a pin. This will aid the per-version pinning implementation.
Julian Andres Klode 8 years ago
parent
commit
5bfd306ee1
2 changed files with 26 additions and 13 deletions
  1. 25 13
      apt-pkg/versionmatch.cc
  2. 1 0
      apt-pkg/versionmatch.h

+ 25 - 13
apt-pkg/versionmatch.cc

@@ -164,25 +164,37 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg)
    pkgCache::VerIterator Ver = Pkg.VersionList();
    for (; Ver.end() == false; ++Ver)
    {
-      if (Type == Version)
-      {
-	 if (MatchVer(Ver.VerStr(),VerStr,VerPrefixMatch) == true)
-	    return Ver;
-	 if (ExpressionMatches(VerStr, Ver.VerStr()) == true)
-	    return Ver;
-	 continue;
-      }
-      
-      for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF)
-	 if (FileMatch(VF.File()) == true)
-	    return Ver;
+      if (VersionMatches(Ver))
+	 return Ver;
    }
-      
+
    // This will be Ended by now.
    return Ver;
 }
 									/*}}}*/
 
+// VersionMatch::Find - Locate the best match for the select type	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgVersionMatch::VersionMatches(pkgCache::VerIterator Ver)
+{
+   if (Type == Version)
+   {
+      if (MatchVer(Ver.VerStr(),VerStr,VerPrefixMatch) == true)
+	 return true;
+      if (ExpressionMatches(VerStr, Ver.VerStr()) == true)
+	 return true;
+      return false;
+   }
+
+   for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF)
+      if (FileMatch(VF.File()) == true)
+	 return true;
+
+   return false;
+}
+									/*}}}*/
+
 #ifndef FNM_CASEFOLD
 #define FNM_CASEFOLD 0
 #endif

+ 1 - 0
apt-pkg/versionmatch.h

@@ -74,6 +74,7 @@ class pkgVersionMatch
    static bool ExpressionMatches(const std::string& pattern, const char *string);
    bool FileMatch(pkgCache::PkgFileIterator File);
    pkgCache::VerIterator Find(pkgCache::PkgIterator Pkg);
+   bool VersionMatches(pkgCache::VerIterator Ver);
 
    pkgVersionMatch(std::string Data,MatchType Type);
 };