>From ad81bc49f0ce63e30dbadf9b11b8d484b2a0ddf6 Mon Sep 17 00:00:00 2001
From: Niels Thykier <niels@thykier.net>
Date: Sun, 27 Nov 2016 10:54:33 +0000
Subject: [PATCH] ParseDepends: Support passing the desired architecture

This is useful for e.g. Britney, where the Build-Depends would have to
be parsed for multiple architectures.  With this change, the call can
choose the architecture without having to mess with the config.

Signed-off-by: Niels Thykier <niels@thykier.net>
---
 apt-pkg/deb/deblistparser.cc | 28 +++++++++++++++++++++++++---
 apt-pkg/deb/deblistparser.h  | 16 ++++++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 0fc08d8..5f16752 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -547,11 +547,23 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 					bool const &StripMultiArch,
 					bool const &ParseRestrictionsList)
 {
+   return debListParser::ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags,
+                                      StripMultiArch, ParseRestrictionsList,
+                                      _config->Find("APT::Architecture"));
+}
+
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+					string &Package,string &Ver,
+					unsigned int &Op, bool const &ParseArchFlags,
+					bool const &StripMultiArch,
+					bool const &ParseRestrictionsList,
+                                        const string Arch)
+{
    StringView PackageView;
    StringView VerView;
 
    auto res = ParseDepends(Start, Stop, PackageView, VerView, Op, (bool)ParseArchFlags,
-   (bool) StripMultiArch, (bool) ParseRestrictionsList);
+   (bool) StripMultiArch, (bool) ParseRestrictionsList, Arch);
    Package = PackageView.to_string();
    Ver = VerView.to_string();
 
@@ -563,6 +575,17 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 					bool StripMultiArch,
 					bool ParseRestrictionsList)
 {
+   return debListParser::ParseDepends(Start, Stop, Package, Ver, Op, ParseArchFlags,
+                                      StripMultiArch, ParseRestrictionsList,
+                                      _config->Find("APT::Architecture"));
+}
+
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+					StringView &Package,StringView &Ver,
+					unsigned int &Op, bool ParseArchFlags,
+					bool StripMultiArch,
+					bool ParseRestrictionsList, string const Arch)
+{
    // Strip off leading space
    for (;Start != Stop && isspace_ascii(*Start) != 0; ++Start);
    
@@ -630,8 +653,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 
    if (unlikely(ParseArchFlags == true))
    {
-      string const arch = _config->Find("APT::Architecture");
-      APT::CacheFilter::PackageArchitectureMatchesSpecification matchesArch(arch, false);
+      APT::CacheFilter::PackageArchitectureMatchesSpecification matchesArch(Arch, false);
 
       // Parse an architecture
       if (I != Stop && *I == '[')
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index 3d50659..9162717 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -102,6 +102,16 @@ class APT_HIDDEN debListParser : public pkgCacheListParser
 	 std::string &Package,std::string &Ver,unsigned int &Op,
 	 bool const &ParseArchFlags, bool const &StripMultiArch,
 	 bool const &ParseRestrictionsList);
+   APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
+	 std::string &Package,std::string &Ver,unsigned int &Op,
+	 bool const &ParseArchFlags, bool const &StripMultiArch,
+	 bool const &ParseRestrictionsList);
+
+   APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop,
+	 std::string &Package,std::string &Ver,unsigned int &Op,
+	 bool const &ParseArchFlags, bool const &StripMultiArch,
+	 bool const &ParseRestrictionsList,
+	 string const Arch);
 
 #ifdef APT_PKG_EXPOSE_STRING_VIEW
    APT_HIDDEN static const char *ParseDepends(const char *Start,const char *Stop,
@@ -109,6 +119,12 @@ class APT_HIDDEN debListParser : public pkgCacheListParser
     APT::StringView &Ver,unsigned int &Op,
 	 bool const ParseArchFlags = false, bool StripMultiArch = true,
 	 bool const ParseRestrictionsList = false);
+   APT_HIDDEN static const char *ParseDepends(const char *Start,const char *Stop,
+	 APT::StringView &Package,
+	 APT::StringView &Ver,unsigned int &Op,
+	 bool const ParseArchFlags = false, bool StripMultiArch = true,
+	 bool const ParseRestrictionsList = false,
+	 string const Arch);
 #endif
 
    APT_PUBLIC static const char *ConvertRelation(const char *I,unsigned int &Op);
-- 
2.10.2

