From d006da196dd4289ab3667817d218e6c6ac7bdb6b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 26 Sep 2017 22:23:05 +0200 Subject: use pkgTagSection::Key in srcRecords parser Using hardcoded array-indexes in the build-dependency parsing is efficient, but less discoverable and easier to break. We can avoid this by making it even more efficient (not that it would be noticeable) allowing us to do explicitly named comparisons instead. Gbp-Dch: Ignore --- apt-pkg/deb/debsrcrecords.cc | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index cd8840af2..1cabfe281 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -43,11 +44,10 @@ debSrcRecordParser::debSrcRecordParser(std::string const &File,pkgIndexFile cons } std::string debSrcRecordParser::Package() const /*{{{*/ { - auto const name = Sect.FindS("Package"); - if (iIndex == nullptr) - return name.empty() ? Sect.FindS("Source") : name; - else - return name; + auto const name = Sect.Find(pkgTagSection::Key::Package); + if (iIndex != nullptr || name.empty() == false) + return name.to_string(); + return Sect.Find(pkgTagSection::Key::Source).to_string(); } /*}}}*/ // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ @@ -60,7 +60,7 @@ std::string debSrcRecordParser::Package() const /*{{{*/ const char **debSrcRecordParser::Binaries() { const char *Start, *End; - if (Sect.Find("Binary", Start, End) == false) + if (Sect.Find(pkgTagSection::Key::Binary, Start, End) == false) return NULL; for (; isspace_ascii(*Start) != 0; ++Start); if (Start >= End) @@ -100,23 +100,22 @@ const char **debSrcRecordParser::Binaries() bool debSrcRecordParser::BuildDepends(std::vector &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch) { - unsigned int I; - const char *Start, *Stop; - BuildDepRec rec; - const char *fields[] = {"Build-Depends", - "Build-Depends-Indep", - "Build-Conflicts", - "Build-Conflicts-Indep", - "Build-Depends-Arch", - "Build-Conflicts-Arch"}; - BuildDeps.clear(); - for (I = 0; I < 6; I++) + pkgTagSection::Key const fields[] = { + pkgTagSection::Key::Build_Depends, + pkgTagSection::Key::Build_Depends_Indep, + pkgTagSection::Key::Build_Conflicts, + pkgTagSection::Key::Build_Conflicts_Indep, + pkgTagSection::Key::Build_Depends_Arch, + pkgTagSection::Key::Build_Conflicts_Arch, + }; + for (unsigned short I = 0; I < sizeof(fields) / sizeof(fields[0]); ++I) { - if (ArchOnly && (I == 1 || I == 3)) - continue; + if (ArchOnly && (fields[I] == pkgTagSection::Key::Build_Depends_Indep || fields[I] == pkgTagSection::Key::Build_Conflicts_Indep)) + continue; + const char *Start, *Stop; if (Sect.Find(fields[I], Start, Stop) == false) continue; @@ -125,31 +124,34 @@ bool debSrcRecordParser::BuildDepends(std::vectorError("Problem parsing dependency: %s", fields[I]); + BuildDepRec rec; + Start = debListParser::ParseDepends(Start, Stop, + rec.Package, rec.Version, rec.Op, true, StripMultiArch, true); + + if (Start == 0) + return _error->Error("Problem parsing dependency: %s", BuildDepType(I)); rec.Type = I; // We parsed a package that was ignored (wrong architecture restriction // or something). - if (rec.Package == "") { + if (rec.Package.empty()) + { // If we are in an OR group, we need to set the "Or" flag of the // previous entry to our value. - if (BuildDeps.size() > 0 && (BuildDeps[BuildDeps.size() - 1].Op & pkgCache::Dep::Or) == pkgCache::Dep::Or) { + if (BuildDeps.empty() == false && (BuildDeps[BuildDeps.size() - 1].Op & pkgCache::Dep::Or) == pkgCache::Dep::Or) + { BuildDeps[BuildDeps.size() - 1].Op &= ~pkgCache::Dep::Or; BuildDeps[BuildDeps.size() - 1].Op |= (rec.Op & pkgCache::Dep::Or); } } else { - BuildDeps.push_back(rec); + BuildDeps.emplace_back(std::move(rec)); } - - if (Start == Stop) + + if (Start == Stop) break; - } + } } - + return true; } /*}}}*/ @@ -185,7 +187,7 @@ bool debSrcRecordParser::Files2(std::vector &List) List.clear(); // Stash the / terminated directory prefix - string Base = Sect.FindS("Directory"); + std::string Base = Sect.Find(pkgTagSection::Key::Directory).to_string(); if (Base.empty() == false && Base[Base.length()-1] != '/') Base += '/'; -- cgit v1.2.3