]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-show.cc
Do not show multiple identical apt-cache showsrc entries
[apt.git] / apt-private / private-show.cc
index aaa4268c628da8a7bdfa31b2d63a05fac30cd416..6fb3791f829cd4d7f34aed7d1691384fc6c4f5eb 100644 (file)
@@ -219,6 +219,7 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgCache::VerIterator const
    RW.push_back(pkgTagSection::Tag::Remove("Description"));
    RW.push_back(pkgTagSection::Tag::Remove("Description-md5"));
    // improve
+   RW.push_back(pkgTagSection::Tag::Rewrite("Package", V.ParentPkg().FullName(true)));
    RW.push_back(pkgTagSection::Tag::Rewrite("Installed-Size", installed_size));
    RW.push_back(pkgTagSection::Tag::Remove("Size"));
    RW.push_back(pkgTagSection::Tag::Rewrite("Download-Size", package_size));
@@ -298,6 +299,14 @@ bool ShowPackage(CommandLine &CmdL)                                        /*{{{*/
    return true;
 }
                                                                        /*}}}*/
+// XXX: move to hashes.h: HashString::FromString() ?                   /*{{{*/
+std::string Sha1FromString(std::string input)
+{
+   SHA1Summation sha1;
+   sha1.Add(input.c_str(), input.length());
+   return sha1.Result().Value();
+}
+                                                                       /*}}}*/
 bool ShowSrcPackage(CommandLine &CmdL)                                 /*{{{*/
 {
    pkgCacheFile CacheFile;
@@ -311,6 +320,8 @@ bool ShowSrcPackage(CommandLine &CmdL)                                      /*{{{*/
       return false;
 
    bool found = false;
+   // avoid showing identical records
+   std::set<std::string> seen;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
       SrcRecs.Restart();
@@ -322,9 +333,14 @@ bool ShowSrcPackage(CommandLine &CmdL)                                     /*{{{*/
         if (_config->FindB("APT::Cache::Only-Source", false) == true)
            if (Parse->Package() != *I)
               continue;
-        std::cout << Parse->AsStr() << std::endl;;
-        found = true;
-        found_this = true;
+         std::string sha1str = Sha1FromString(Parse->AsStr());
+         if (std::find(seen.begin(), seen.end(), sha1str) == seen.end())
+         {
+            std::cout << Parse->AsStr() << std::endl;;
+            found = true;
+            found_this = true;
+            seen.insert(sha1str);
+         }
       }
       if (found_this == false) {
         _error->Warning(_("Unable to locate package %s"),*I);
@@ -396,7 +412,7 @@ bool Policy(CommandLine &CmdL)
            continue;
         }
         // New code
-        for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) {
+        for (pkgCache::VerIterator V = I.VersionList(); !V.end(); ++V) {
            auto Prio = Plcy->GetPriority(V, false);
            if (Prio == 0)
               continue;