Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c035e5

Browse files
committed
pg_dump: Simplify internal archive version handling
The ArchiveHandle structure contained the archive format version numbertwice, once as a single field and once split into components. Simplifythat by just keeping the single field and adding some macros to extractthe components. Introduce some macros for composing version numbers, toeliminate the repeated use of magic formulas. Drop the unused trailingzero byte from the run-time composite version representation.reviewed by Tom Lane
1 parent78d1091 commit8c035e5

File tree

2 files changed

+53
-55
lines changed

2 files changed

+53
-55
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ PrintTOCSummary(Archive *AHX)
11051105
fmtName="UNKNOWN";
11061106
}
11071107

1108-
ahprintf(AH,"; Dump Version: %d.%d-%d\n",AH->vmaj,AH->vmin,AH->vrev);
1108+
ahprintf(AH,"; Dump Version: %d.%d-%d\n",
1109+
ARCHIVE_MAJOR(AH->version),ARCHIVE_MINOR(AH->version),ARCHIVE_REV(AH->version));
11091110
ahprintf(AH,"; Format: %s\n",fmtName);
11101111
ahprintf(AH,"; Integer: %d bytes\n", (int)AH->intSize);
11111112
ahprintf(AH,"; Offset: %d bytes\n", (int)AH->offSize);
@@ -2106,6 +2107,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
21062107
if (strncmp(sig,"PGDMP",5)==0)
21072108
{
21082109
intbyteread;
2110+
charvmaj,vmin,vrev;
21092111

21102112
/*
21112113
* Finish reading (most of) a custom-format header.
@@ -2115,31 +2117,30 @@ _discoverArchiveFormat(ArchiveHandle *AH)
21152117
if ((byteread=fgetc(fh))==EOF)
21162118
READ_ERROR_EXIT(fh);
21172119

2118-
AH->vmaj=byteread;
2120+
vmaj=byteread;
21192121

21202122
if ((byteread=fgetc(fh))==EOF)
21212123
READ_ERROR_EXIT(fh);
21222124

2123-
AH->vmin=byteread;
2125+
vmin=byteread;
21242126

21252127
/* Save these too... */
2126-
AH->lookahead[AH->lookaheadLen++]=AH->vmaj;
2127-
AH->lookahead[AH->lookaheadLen++]=AH->vmin;
2128+
AH->lookahead[AH->lookaheadLen++]=vmaj;
2129+
AH->lookahead[AH->lookaheadLen++]=vmin;
21282130

21292131
/* Check header version; varies from V1.0 */
2130-
if (AH->vmaj>1|| ((AH->vmaj==1)&&(AH->vmin>0)))/* Version > 1.0 */
2132+
if (vmaj>1|| (vmaj==1&&vmin>0))/* Version > 1.0 */
21312133
{
21322134
if ((byteread=fgetc(fh))==EOF)
21332135
READ_ERROR_EXIT(fh);
21342136

2135-
AH->vrev=byteread;
2136-
AH->lookahead[AH->lookaheadLen++]=AH->vrev;
2137+
vrev=byteread;
2138+
AH->lookahead[AH->lookaheadLen++]=vrev;
21372139
}
21382140
else
2139-
AH->vrev=0;
2141+
vrev=0;
21402142

2141-
/* Make a convenient integer <maj><min><rev>00 */
2142-
AH->version= ((AH->vmaj*256+AH->vmin)*256+AH->vrev)*256+0;
2143+
AH->version=MAKE_ARCHIVE_VERSION(vmaj,vmin,vrev);
21432144

21442145
if ((AH->intSize=fgetc(fh))==EOF)
21452146
READ_ERROR_EXIT(fh);
@@ -2234,12 +2235,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
22342235

22352236
/* AH->debugLevel = 100; */
22362237

2237-
AH->vmaj=K_VERS_MAJOR;
2238-
AH->vmin=K_VERS_MINOR;
2239-
AH->vrev=K_VERS_REV;
2240-
2241-
/* Make a convenient integer <maj><min><rev>00 */
2242-
AH->version= ((AH->vmaj*256+AH->vmin)*256+AH->vrev)*256+0;
2238+
AH->version=K_VERS_SELF;
22432239

22442240
/* initialize for backwards compatible string processing */
22452241
AH->public.encoding=0;/* PG_SQL_ASCII */
@@ -3528,9 +3524,9 @@ WriteHead(ArchiveHandle *AH)
35283524
structtmcrtm;
35293525

35303526
(*AH->WriteBufPtr) (AH,"PGDMP",5);/* Magic code */
3531-
(*AH->WriteBytePtr) (AH,AH->vmaj);
3532-
(*AH->WriteBytePtr) (AH,AH->vmin);
3533-
(*AH->WriteBytePtr) (AH,AH->vrev);
3527+
(*AH->WriteBytePtr) (AH,ARCHIVE_MAJOR(AH->version));
3528+
(*AH->WriteBytePtr) (AH,ARCHIVE_MINOR(AH->version));
3529+
(*AH->WriteBytePtr) (AH,ARCHIVE_REV(AH->version));
35343530
(*AH->WriteBytePtr) (AH,AH->intSize);
35353531
(*AH->WriteBytePtr) (AH,AH->offSize);
35363532
(*AH->WriteBytePtr) (AH,AH->format);
@@ -3563,24 +3559,26 @@ ReadHead(ArchiveHandle *AH)
35633559
*/
35643560
if (!AH->readHeader)
35653561
{
3562+
charvmaj,vmin,vrev;
3563+
35663564
(*AH->ReadBufPtr) (AH,tmpMag,5);
35673565

35683566
if (strncmp(tmpMag,"PGDMP",5)!=0)
35693567
exit_horribly(modulename,"did not find magic string in file header\n");
35703568

3571-
AH->vmaj= (*AH->ReadBytePtr) (AH);
3572-
AH->vmin= (*AH->ReadBytePtr) (AH);
3569+
vmaj= (*AH->ReadBytePtr) (AH);
3570+
vmin= (*AH->ReadBytePtr) (AH);
35733571

3574-
if (AH->vmaj>1|| ((AH->vmaj==1)&&(AH->vmin>0)))/* Version > 1.0 */
3575-
AH->vrev= (*AH->ReadBytePtr) (AH);
3572+
if (vmaj>1|| (vmaj==1&&vmin>0))/* Version > 1.0 */
3573+
vrev= (*AH->ReadBytePtr) (AH);
35763574
else
3577-
AH->vrev=0;
3575+
vrev=0;
35783576

3579-
AH->version=((AH->vmaj*256+AH->vmin)*256+AH->vrev)*256+0;
3577+
AH->version=MAKE_ARCHIVE_VERSION(vmaj,vmin,vrev);
35803578

35813579
if (AH->version<K_VERS_1_0||AH->version>K_VERS_MAX)
35823580
exit_horribly(modulename,"unsupported version (%d.%d) in file header\n",
3583-
AH->vmaj,AH->vmin);
3581+
vmaj,vmin);
35843582

35853583
AH->intSize= (*AH->ReadBytePtr) (AH);
35863584
if (AH->intSize>32)

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,40 @@ typedef struct _z_stream
6262
typedefz_stream*z_streamp;
6363
#endif
6464

65-
/* Current archive version number (the format we can output) */
66-
#defineK_VERS_MAJOR 1
67-
#defineK_VERS_MINOR 12
68-
#defineK_VERS_REV 0
69-
7065
/* Data block types */
7166
#defineBLK_DATA 1
7267
#defineBLK_BLOBS 3
7368

69+
/* Encode version components into a convenient integer <maj><min><rev> */
70+
#defineMAKE_ARCHIVE_VERSION(major,minor,rev) (((major) * 256 + (minor)) * 256 + (rev))
71+
72+
#defineARCHIVE_MAJOR(version) (((version) >> 16) & 255)
73+
#defineARCHIVE_MINOR(version) (((version) >> 8) & 255)
74+
#defineARCHIVE_REV(version) (((version) ) & 255)
75+
7476
/* Historical version numbers (checked in code) */
75-
#defineK_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0)
76-
#defineK_VERS_1_2 (( (1 * 256 + 2) * 256 + 0) * 256 + 0)/* Allow No ZLIB */
77-
#defineK_VERS_1_3 (( (1 * 256 + 3) * 256 + 0) * 256 + 0)/* BLOBs */
78-
#defineK_VERS_1_4 (( (1 * 256 + 4) * 256 + 0) * 256 + 0)/* Date & name in header */
79-
#defineK_VERS_1_5 (( (1 * 256 + 5) * 256 + 0) * 256 + 0)/* Handle dependencies */
80-
#defineK_VERS_1_6 (( (1 * 256 + 6) * 256 + 0) * 256 + 0)/* Schema field in TOCs */
81-
#defineK_VERS_1_7 (( (1 * 256 + 7) * 256 + 0) * 256 + 0)/* File Offset size in
82-
* header */
83-
#defineK_VERS_1_8 (( (1 * 256 + 8) * 256 + 0) * 256 + 0)/* change interpretation
84-
* of ID numbers and
85-
* dependencies */
86-
#defineK_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0)/* add default_with_oids
87-
* tracking */
88-
#defineK_VERS_1_10 (( (1 * 256 + 10) * 256 + 0) * 256 + 0)/* add tablespace */
89-
#defineK_VERS_1_11 (( (1 * 256 + 11) * 256 + 0) * 256 + 0)/* add toc section
90-
* indicator */
91-
#defineK_VERS_1_12 (( (1 * 256 + 12) * 256 + 0) * 256 + 0)/* add separate BLOB
92-
* entries */
77+
#defineK_VERS_1_0MAKE_ARCHIVE_VERSION(1, 0, 0)
78+
#defineK_VERS_1_2MAKE_ARCHIVE_VERSION(1, 2, 0)/* Allow No ZLIB */
79+
#defineK_VERS_1_3MAKE_ARCHIVE_VERSION(1, 3, 0)/* BLOBs */
80+
#defineK_VERS_1_4MAKE_ARCHIVE_VERSION(1, 4, 0)/* Date & name in header */
81+
#defineK_VERS_1_5MAKE_ARCHIVE_VERSION(1, 5, 0)/* Handle dependencies */
82+
#defineK_VERS_1_6MAKE_ARCHIVE_VERSION(1, 6, 0)/* Schema field in TOCs */
83+
#defineK_VERS_1_7MAKE_ARCHIVE_VERSION(1, 7, 0)/* File Offset size in header */
84+
#defineK_VERS_1_8MAKE_ARCHIVE_VERSION(1, 8, 0)/* change interpretation of ID
85+
numbers and dependencies */
86+
#defineK_VERS_1_9MAKE_ARCHIVE_VERSION(1, 9, 0)/* add default_with_oids tracking */
87+
#defineK_VERS_1_10MAKE_ARCHIVE_VERSION(1, 10, 0)/* add tablespace */
88+
#defineK_VERS_1_11MAKE_ARCHIVE_VERSION(1, 11, 0)/* add toc section indicator */
89+
#defineK_VERS_1_12MAKE_ARCHIVE_VERSION(1, 12, 0)/* add separate BLOB entries */
90+
91+
/* Current archive version number (the format we can output) */
92+
#defineK_VERS_MAJOR 1
93+
#defineK_VERS_MINOR 12
94+
#defineK_VERS_REV 0
95+
#defineK_VERS_SELFMAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV);
9396

9497
/* Newest format we can read */
95-
#defineK_VERS_MAX (( (1 * 256 + 12) * 256 +255) * 256 + 0)
98+
#defineK_VERS_MAXMAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR,255)
9699

97100

98101
/* Flags to indicate disposition of offsets stored in files */
@@ -205,10 +208,7 @@ typedef enum
205208
struct_archiveHandle
206209
{
207210
Archivepublic;/* Public part of archive */
208-
charvmaj;/* Version of file */
209-
charvmin;
210-
charvrev;
211-
intversion;/* Conveniently formatted version */
211+
intversion;/* Version of file */
212212

213213
char*archiveRemoteVersion;/* When reading an archive, the
214214
* version of the dumped DB */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp