]> git.saurik.com Git - apt.git/commitdiff
Do not show multiple identical apt-cache showsrc entries
authorMichael Vogt <mvo@ubuntu.com>
Thu, 14 Jan 2016 08:28:47 +0000 (09:28 +0100)
committerMichael Vogt <mvo@ubuntu.com>
Thu, 14 Jan 2016 08:28:47 +0000 (09:28 +0100)
Closes: #734922
apt-private/private-show.cc
test/integration/test-bug-734922-apt-showsrc-duplicate [new file with mode: 0755]

index c2517e1301943dd1ccb82af702a95829cc1961c8..6fb3791f829cd4d7f34aed7d1691384fc6c4f5eb 100644 (file)
@@ -299,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;
@@ -312,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();
@@ -323,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);
diff --git a/test/integration/test-bug-734922-apt-showsrc-duplicate b/test/integration/test-bug-734922-apt-showsrc-duplicate
new file mode 100755 (executable)
index 0000000..d4370e2
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386' 
+
+# foo is identical, show it only once in showsrc
+insertpackage "unstable" "foo" "i386" "1.0"
+insertpackage "testing" "foo" "i386" "1.0"
+insertsource "unstable" "foo" "i386" "1.0"
+insertsource "testing" "foo" "i386" "1.0"
+
+# bar is different, show twice
+insertsource "unstable" "bar" "i386" "1.0"
+insertsource "testing" "bar" "i386" "2.0"
+
+setupaptarchive
+
+# ensure "foo" is not shown twice
+aptcache showsrc foo bar|grep ^Package: > out.txt
+testequal "Package: foo
+Package: bar
+Package: bar" cat out.txt