From feab34c5216941ca95aae1a389238a77b662d1de Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Apr 2014 17:59:09 +0200 Subject: add support for apt-get build-dep foo.dsc --- apt-pkg/tagfile.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index d5b62e76d..d1a24ba45 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -105,6 +105,8 @@ class pkgTagFile unsigned long Offset(); bool Jump(pkgTagSection &Tag,unsigned long long Offset); + void Init(FileFd *F,unsigned long long Size = 32*1024); + pkgTagFile(FileFd *F,unsigned long long Size = 32*1024); virtual ~pkgTagFile(); }; -- cgit v1.2.3 From 8710a36a01c0cb1648926792c2ad05185535558e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 10 May 2014 11:24:44 +0200 Subject: improve pkgTagSection scanning and parsing Removes the 256 fields limit, deals consistently with spaces littered all over the place and is even a tiny bit faster than before. Even comes with a bunch of new tests to validate these claims. --- apt-pkg/tagfile.h | 63 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 21 deletions(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index d1a24ba45..b0cfab759 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -25,6 +25,8 @@ #include #include +#include +#include #ifndef APT_8_CLEANER_HEADERS #include @@ -35,23 +37,20 @@ class FileFd; class pkgTagSection { const char *Section; - // We have a limit of 256 tags per section. - unsigned int Indexes[256]; - unsigned int AlphaIndexes[0x100]; - unsigned int TagCount; + struct TagData { + unsigned int StartTag; + unsigned int EndTag; + unsigned int StartValue; + unsigned int NextInBucket; + + TagData(unsigned int const StartTag) : StartTag(StartTag), NextInBucket(0) {} + }; + std::vector Tags; + unsigned int LookupTable[0x100]; + // dpointer placeholder (for later in case we need it) void *d; - /* This very simple hash function for the last 8 letters gives - very good performance on the debian package files */ - inline static unsigned long AlphaHash(const char *Text, const char *End = 0) - { - unsigned long Res = 0; - for (; Text != End && *Text != ':' && *Text != 0; Text++) - Res = ((unsigned long)(*Text) & 0xDF) ^ (Res << 1); - return Res & 0xFF; - } - protected: const char *Stop; @@ -69,17 +68,39 @@ class pkgTagSection unsigned long Flag) const; bool static FindFlag(unsigned long &Flags, unsigned long Flag, const char* Start, const char* Stop); - bool Scan(const char *Start,unsigned long MaxLength); + + /** \brief searches the boundaries of the current section + * + * While parameter Start marks the beginning of the section, this method + * will search for the first double newline in the data stream which marks + * the end of the section. It also does a first pass over the content of + * the section parsing it as encountered for processing later on by Find + * + * @param Start is the beginning of the section + * @param MaxLength is the size of valid data in the stream pointed to by Start + * @param Restart if enabled internal state will be cleared, otherwise it is + * assumed that now more data is available in the stream and the parsing will + * start were it encountered insufficent data the last time. + * + * @return \b true if section end was found, \b false otherwise. + * Beware that internal state will be inconsistent if \b false is returned! + */ + APT_MUSTCHECK bool Scan(const char *Start, unsigned long MaxLength, bool const Restart = true); inline unsigned long size() const {return Stop - Section;}; void Trim(); virtual void TrimRecord(bool BeforeRecord, const char* &End); - - inline unsigned int Count() const {return TagCount;}; - bool Exists(const char* const Tag); - + + /** \brief amount of Tags in the current section + * + * Note: if a Tag is mentioned repeatly it will be counted multiple + * times, but only the last occurance is available via Find methods. + */ + unsigned int Count() const; + bool Exists(const char* const Tag) const; + inline void Get(const char *&Start,const char *&Stop,unsigned int I) const - {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];} - + {Start = Section + Tags[I].StartTag; Stop = Section + Tags[I+1].StartTag;} + inline void GetSection(const char *&Start,const char *&Stop) const { Start = Section; -- cgit v1.2.3 From a2fdb57ff93c1b1f35b796c3c99878ec3ae54a06 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 May 2014 17:36:09 +0200 Subject: Add APT::Acquire::$(host)::By-Hash=1 knob, add Acquire-By-Hash to Release file The by-hash can be configured on a per-hostname basis and a Release file can indicate that it has by-hash support via a new flag. The location of the hash now matches the AptByHash spec --- apt-pkg/tagfile.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index b0cfab759..db43bfbf9 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -62,7 +62,8 @@ class pkgTagSection bool Find(const char *Tag,const char *&Start, const char *&End) const; bool Find(const char *Tag,unsigned int &Pos) const; std::string FindS(const char *Tag) const; - signed int FindI(const char *Tag,signed long Default = 0) const ; + signed int FindI(const char *Tag,signed long Default = 0) const; + bool FindB(const char *Tag, bool const &Default = false) const; unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const; bool FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const; -- cgit v1.2.3 From c029a8368d0f90d749ccba73fc9afe46e77d8b2f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 21:47:59 +0200 Subject: fix occurrence typo in tagfile comment Reported-By: codespell Git-Dch: Ignore --- apt-pkg/tagfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index db43bfbf9..3e84d8fd4 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -94,7 +94,7 @@ class pkgTagSection /** \brief amount of Tags in the current section * * Note: if a Tag is mentioned repeatly it will be counted multiple - * times, but only the last occurance is available via Find methods. + * times, but only the last occurrence is available via Find methods. */ unsigned int Count() const; bool Exists(const char* const Tag) const; -- cgit v1.2.3 From 25613a61f6f3b9e54d5229af7e2278d0fa54bdd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Sep 2014 22:16:26 +0200 Subject: fix: Member variable 'X' is not initialized in the constructor. Reported-By: cppcheck Git-Dch: Ignore --- apt-pkg/tagfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 3e84d8fd4..39ec94d86 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -43,7 +43,7 @@ class pkgTagSection unsigned int StartValue; unsigned int NextInBucket; - TagData(unsigned int const StartTag) : StartTag(StartTag), NextInBucket(0) {} + TagData(unsigned int const StartTag) : StartTag(StartTag), EndTag(0), StartValue(0), NextInBucket(0) {} }; std::vector Tags; unsigned int LookupTable[0x100]; -- cgit v1.2.3 From 862bafea48af2ceaf96345db237b461307a021f6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Oct 2014 08:05:57 +0200 Subject: do not inline virtual destructors with d-pointers Reimplementing an inline method is opening a can of worms we don't want to open if we ever want to us a d-pointer in those classes, so we do the only thing which can save us from hell: move the destructors into the cc sources and we are good. Technically not an ABI break as the methods inline or not do the same (nothing), so a program compiled against the old version still works with the new version (beside that this version is still in experimental, so nothing really has been build against this library anyway). Git-Dch: Ignore --- apt-pkg/tagfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 39ec94d86..4cd99b2fc 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -109,7 +109,7 @@ class pkgTagSection }; pkgTagSection(); - virtual ~pkgTagSection() {}; + virtual ~pkgTagSection(); }; class pkgTagFilePrivate; -- cgit v1.2.3 From 02e20767719873fa8f1919bd0e7a75f63e00c484 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 7 Nov 2014 17:49:36 +0100 Subject: guard const-ification API changes Git-Dch: Ignore --- apt-pkg/tagfile.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 4cd99b2fc..99e2a8d93 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -97,7 +97,11 @@ class pkgTagSection * times, but only the last occurrence is available via Find methods. */ unsigned int Count() const; +#if APT_PKG_ABI >= 413 bool Exists(const char* const Tag) const; +#else + bool Exists(const char* const Tag); +#endif inline void Get(const char *&Start,const char *&Stop,unsigned int I) const {Start = Section + Tags[I].StartTag; Stop = Section + Tags[I+1].StartTag;} -- cgit v1.2.3 From fa5404ab01bdf06eaf147d9f133139e6c89b906a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 7 Nov 2014 18:18:14 +0100 Subject: explicit overload methods instead of adding parameters Adding a new parameter (with a default) is an ABI break, but you can overload a method, which is "just" an API break for everyone doing references to this method (aka: nobody). Git-Dch: Ignore --- apt-pkg/tagfile.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 99e2a8d93..ac6d42089 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -86,7 +86,13 @@ class pkgTagSection * @return \b true if section end was found, \b false otherwise. * Beware that internal state will be inconsistent if \b false is returned! */ +#if APT_PKG_ABI >= 413 APT_MUSTCHECK bool Scan(const char *Start, unsigned long MaxLength, bool const Restart = true); +#else + APT_MUSTCHECK bool Scan(const char *Start, unsigned long MaxLength, bool const Restart); + APT_MUSTCHECK bool Scan(const char *Start, unsigned long MaxLength); +#endif + inline unsigned long size() const {return Stop - Section;}; void Trim(); virtual void TrimRecord(bool BeforeRecord, const char* &End); -- cgit v1.2.3 From bc4ccfeb6096fc6f9a74e2abff3abe31261b5df2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 7 Nov 2014 21:52:31 +0100 Subject: restore ABI of pkgTagSection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have a d-pointer available here, so go ahead and use it which also helps in hidding some dirty details here. The "hard" part is keeping the abi for the inlined methods so that they don't break – at least not more than before as much of the point beside a speedup is support for more than 256 fields in a single section. --- apt-pkg/tagfile.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index ac6d42089..d09e7046c 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -33,23 +33,22 @@ #endif class FileFd; +class pkgTagSectionPrivate; class pkgTagSection { const char *Section; - struct TagData { - unsigned int StartTag; - unsigned int EndTag; - unsigned int StartValue; - unsigned int NextInBucket; - - TagData(unsigned int const StartTag) : StartTag(StartTag), EndTag(0), StartValue(0), NextInBucket(0) {} - }; - std::vector Tags; - unsigned int LookupTable[0x100]; + // We have a limit of 256 tags per section with the old abi +#if APT_PKG_ABI < 413 + APT_DEPRECATED unsigned int Indexes[256]; +#endif + unsigned int AlphaIndexes[0x100]; +#if APT_PKG_ABI < 413 + APT_DEPRECATED unsigned int TagCount; +#endif // dpointer placeholder (for later in case we need it) - void *d; + pkgTagSectionPrivate *d; protected: const char *Stop; @@ -109,8 +108,7 @@ class pkgTagSection bool Exists(const char* const Tag); #endif - inline void Get(const char *&Start,const char *&Stop,unsigned int I) const - {Start = Section + Tags[I].StartTag; Stop = Section + Tags[I+1].StartTag;} + void Get(const char *&Start,const char *&Stop,unsigned int I) const; inline void GetSection(const char *&Start,const char *&Stop) const { -- cgit v1.2.3 From 8d058ea53b18348f81229049a27d14282bd8d8c1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 May 2015 22:53:15 +0200 Subject: implement a more c++-style TFRewrite alternative TFRewrite is okay, but it has obscure limitations (256 Tags), even more obscure bugs (order for renames is defined by the old name) and the interface is very c-style encouraging bad usage like we do it in apt-ftparchive passing massive amounts of c_str() from std::string in. The old-style is marked as deprecated accordingly. The next commit will fix all places in the apt code to not use the old-style anymore. --- apt-pkg/tagfile.h | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'apt-pkg/tagfile.h') diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index d09e7046c..118954541 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -54,13 +54,14 @@ class pkgTagSection const char *Stop; public: - + inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;}; inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;}; - + bool Find(const char *Tag,const char *&Start, const char *&End) const; bool Find(const char *Tag,unsigned int &Pos) const; std::string FindS(const char *Tag) const; + std::string FindRawS(const char *Tag) const; signed int FindI(const char *Tag,signed long Default = 0) const; bool FindB(const char *Tag, bool const &Default = false) const; unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const; @@ -115,9 +116,32 @@ class pkgTagSection Start = Section; Stop = this->Stop; }; - + pkgTagSection(); virtual ~pkgTagSection(); + + struct Tag + { + enum ActionType { REMOVE, RENAME, REWRITE } Action; + std::string Name; + std::string Data; + + static Tag Remove(std::string const &Name); + static Tag Rename(std::string const &OldName, std::string const &NewName); + static Tag Rewrite(std::string const &Name, std::string const &Data); + private: + Tag(ActionType const Action, std::string const &Name, std::string const &Data) : + Action(Action), Name(Name), Data(Data) {} + }; + + /** Write this section (with optional rewrites) to a file + * + * @param File to write the section to + * @param Order in which tags should appear in the file + * @param Rewrite is a set of tags to be renamed, rewitten and/or removed + * @return \b true if successful, otherwise \b false + */ + bool Write(FileFd &File, char const * const * const Order = NULL, std::vector const &Rewrite = std::vector()) const; }; class pkgTagFilePrivate; @@ -141,20 +165,19 @@ class pkgTagFile virtual ~pkgTagFile(); }; -/* This is the list of things to rewrite. The rewriter - goes through and changes or adds each of these headers - to suit. A zero forces the header to be erased, an empty string - causes the old value to be used. (rewrite rule ignored) */ -struct TFRewriteData +extern const char **TFRewritePackageOrder; +extern const char **TFRewriteSourceOrder; + +// Use pkgTagSection::Tag and pkgTagSection::Write() instead +APT_IGNORE_DEPRECATED_PUSH +struct APT_DEPRECATED TFRewriteData { const char *Tag; const char *Rewrite; const char *NewTag; }; -extern const char **TFRewritePackageOrder; -extern const char **TFRewriteSourceOrder; - -bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], +APT_DEPRECATED bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], TFRewriteData *Rewrite); +APT_IGNORE_DEPRECATED_POP #endif -- cgit v1.2.3