diff options
author | Michael Vogt <mvo@ubuntu.com> | 2016-01-14 09:28:47 +0100 |
---|---|---|
committer | Michael Vogt <mvo@ubuntu.com> | 2016-01-14 09:28:47 +0100 |
commit | b0ce7c65309585d4b9752bb571a0e616036eb162 (patch) | |
tree | b41ea70d933f35eac3f19774e78a7de8982cd8fc /apt-private | |
parent | 7d2794a20bdab9b848bf5b4e88d73527405bad54 (diff) | |
download | apt-b0ce7c65309585d4b9752bb571a0e616036eb162.tar.gz |
Do not show multiple identical apt-cache showsrc entries
Closes: #734922
Diffstat (limited to 'apt-private')
-rw-r--r-- | apt-private/private-show.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index c2517e130..6fb3791f8 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -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); |