diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2016-10-25 12:00:00 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2016-10-25 17:02:22 -0400 |
commit | 8c035e55c4807dc5844f563dcbbc44ffe2fdd4d6 (patch) | |
tree | 20ef5919c61e791098f344e306acf4e068c8437b /src/bin/pg_dump/pg_backup_archiver.c | |
parent | 78d109150bf133c38bcdc6d8c5bd9ff546ed1171 (diff) | |
download | postgresql-8c035e55c4807dc5844f563dcbbc44ffe2fdd4d6.tar.gz postgresql-8c035e55c4807dc5844f563dcbbc44ffe2fdd4d6.zip |
pg_dump: Simplify internal archive version handling
The ArchiveHandle structure contained the archive format version number
twice, once as a single field and once split into components. Simplify
that by just keeping the single field and adding some macros to extract
the components. Introduce some macros for composing version numbers, to
eliminate the repeated use of magic formulas. Drop the unused trailing
zero byte from the run-time composite version representation.
reviewed by Tom Lane
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index e237b4a9c90..0e209853509 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -1105,7 +1105,8 @@ PrintTOCSummary(Archive *AHX) fmtName = "UNKNOWN"; } - ahprintf(AH, "; Dump Version: %d.%d-%d\n", AH->vmaj, AH->vmin, AH->vrev); + ahprintf(AH, "; Dump Version: %d.%d-%d\n", + ARCHIVE_MAJOR(AH->version), ARCHIVE_MINOR(AH->version), ARCHIVE_REV(AH->version)); ahprintf(AH, "; Format: %s\n", fmtName); ahprintf(AH, "; Integer: %d bytes\n", (int) AH->intSize); ahprintf(AH, "; Offset: %d bytes\n", (int) AH->offSize); @@ -2106,6 +2107,7 @@ _discoverArchiveFormat(ArchiveHandle *AH) if (strncmp(sig, "PGDMP", 5) == 0) { int byteread; + char vmaj, vmin, vrev; /* * Finish reading (most of) a custom-format header. @@ -2115,31 +2117,30 @@ _discoverArchiveFormat(ArchiveHandle *AH) if ((byteread = fgetc(fh)) == EOF) READ_ERROR_EXIT(fh); - AH->vmaj = byteread; + vmaj = byteread; if ((byteread = fgetc(fh)) == EOF) READ_ERROR_EXIT(fh); - AH->vmin = byteread; + vmin = byteread; /* Save these too... */ - AH->lookahead[AH->lookaheadLen++] = AH->vmaj; - AH->lookahead[AH->lookaheadLen++] = AH->vmin; + AH->lookahead[AH->lookaheadLen++] = vmaj; + AH->lookahead[AH->lookaheadLen++] = vmin; /* Check header version; varies from V1.0 */ - if (AH->vmaj > 1 || ((AH->vmaj == 1) && (AH->vmin > 0))) /* Version > 1.0 */ + if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */ { if ((byteread = fgetc(fh)) == EOF) READ_ERROR_EXIT(fh); - AH->vrev = byteread; - AH->lookahead[AH->lookaheadLen++] = AH->vrev; + vrev = byteread; + AH->lookahead[AH->lookaheadLen++] = vrev; } else - AH->vrev = 0; + vrev = 0; - /* Make a convenient integer <maj><min><rev>00 */ - AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0; + AH->version = MAKE_ARCHIVE_VERSION(vmaj, vmin, vrev); if ((AH->intSize = fgetc(fh)) == EOF) READ_ERROR_EXIT(fh); @@ -2234,12 +2235,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, /* AH->debugLevel = 100; */ - AH->vmaj = K_VERS_MAJOR; - AH->vmin = K_VERS_MINOR; - AH->vrev = K_VERS_REV; - - /* Make a convenient integer <maj><min><rev>00 */ - AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0; + AH->version = K_VERS_SELF; /* initialize for backwards compatible string processing */ AH->public.encoding = 0; /* PG_SQL_ASCII */ @@ -3528,9 +3524,9 @@ WriteHead(ArchiveHandle *AH) struct tm crtm; (*AH->WriteBufPtr) (AH, "PGDMP", 5); /* Magic code */ - (*AH->WriteBytePtr) (AH, AH->vmaj); - (*AH->WriteBytePtr) (AH, AH->vmin); - (*AH->WriteBytePtr) (AH, AH->vrev); + (*AH->WriteBytePtr) (AH, ARCHIVE_MAJOR(AH->version)); + (*AH->WriteBytePtr) (AH, ARCHIVE_MINOR(AH->version)); + (*AH->WriteBytePtr) (AH, ARCHIVE_REV(AH->version)); (*AH->WriteBytePtr) (AH, AH->intSize); (*AH->WriteBytePtr) (AH, AH->offSize); (*AH->WriteBytePtr) (AH, AH->format); @@ -3563,24 +3559,26 @@ ReadHead(ArchiveHandle *AH) */ if (!AH->readHeader) { + char vmaj, vmin, vrev; + (*AH->ReadBufPtr) (AH, tmpMag, 5); if (strncmp(tmpMag, "PGDMP", 5) != 0) exit_horribly(modulename, "did not find magic string in file header\n"); - AH->vmaj = (*AH->ReadBytePtr) (AH); - AH->vmin = (*AH->ReadBytePtr) (AH); + vmaj = (*AH->ReadBytePtr) (AH); + vmin = (*AH->ReadBytePtr) (AH); - if (AH->vmaj > 1 || ((AH->vmaj == 1) && (AH->vmin > 0))) /* Version > 1.0 */ - AH->vrev = (*AH->ReadBytePtr) (AH); + if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */ + vrev = (*AH->ReadBytePtr) (AH); else - AH->vrev = 0; + vrev = 0; - AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0; + AH->version = MAKE_ARCHIVE_VERSION(vmaj, vmin, vrev); if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX) exit_horribly(modulename, "unsupported version (%d.%d) in file header\n", - AH->vmaj, AH->vmin); + vmaj, vmin); AH->intSize = (*AH->ReadBytePtr) (AH); if (AH->intSize > 32) |