Subject: [PATCH 2/3] +also rearrange the functions to their original order..

From: Justin Pryzby <[email-masked]>
Date: Tue, 28 Feb 2023 13:34:06 -0600

This allows comparing like:
git diff --diff-algorithm=minimal -w e9960732a~:../src/bin/pg_dump/compress_io.c ../src/bin/pg_dump/compress_gzip.c
---
 src/bin/pg_dump/compress_gzip.c | 95 ++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 44 deletions(-)

diff --git a/src/bin/pg_dump/compress_gzip.c b/src/bin/pg_dump/compress_gzip.c
index dd769750c8f..f3f5e87c9a8 100644
--- a/src/bin/pg_dump/compress_gzip.c
+++ b/src/bin/pg_dump/compress_gzip.c
@@ -24,22 +24,73 @@
  * Compressor API
  *----------------------
  */
 typedef struct ZlibCompressorState
 {
 	z_streamp	zp;
 
 	void	   *outbuf;
 	size_t		outsize;
 } ZlibCompressorState;
 
+static void ReadDataFromArchiveZlib(ArchiveHandle *AH, CompressorState *cs);
+static void WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
+		const void *data, size_t dLen);
+static void EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs);
+static void DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs,
+		bool flush);
+
+/* Public routines that support zlib compressed data I/O */
+void
+InitCompressorZlib(CompressorState *cs,
+				   const pg_compress_specification compression_spec)
+{
+	ZlibCompressorState *gzipcs;
+
+	cs->readData = ReadDataFromArchiveZlib;
+	cs->writeData = WriteDataToArchiveZlib;
+	cs->end = EndCompressorZlib;
+
+	cs->compression_spec = compression_spec;
+
+	gzipcs = (ZlibCompressorState *) pg_malloc0(sizeof(ZlibCompressorState));
+
+	cs->private_data = gzipcs;
+}
+
+static void
+EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs)
+{
+	ZlibCompressorState *gzipcs = (ZlibCompressorState *) cs->private_data;
+	z_streamp	zp;
+
+	if (gzipcs->zp)
+	{
+		zp = gzipcs->zp;
+		zp->next_in = NULL;
+		zp->avail_in = 0;
+
+		/* Flush any remaining data from zlib buffer */
+		DeflateCompressorZlib(AH, cs, true);
+
+		if (deflateEnd(zp) != Z_OK)
+			pg_fatal("could not close compression stream: %s", zp->msg);
+
+		pg_free(gzipcs->outbuf);
+		pg_free(gzipcs->zp);
+	}
+
+	pg_free(gzipcs);
+	cs->private_data = NULL;
+}
+
 /* Private routines that support zlib compressed data I/O */
 static void
 DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
 {
 	ZlibCompressorState *gzipcs = (ZlibCompressorState *) cs->private_data;
 	z_streamp	zp = gzipcs->zp;
 	void	   *out = gzipcs->outbuf;
 	int			res = Z_OK;
 
 	while (gzipcs->zp->avail_in != 0 || flush)
 	{
@@ -67,48 +118,22 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
 				cs->writeF(AH, (char *) out, len);
 			}
 			zp->next_out = out;
 			zp->avail_out = gzipcs->outsize;
 		}
 
 		if (res == Z_STREAM_END)
 			break;
 	}
 }
 
-static void
-EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs)
-{
-	ZlibCompressorState *gzipcs = (ZlibCompressorState *) cs->private_data;
-	z_streamp	zp;
-
-	if (gzipcs->zp)
-	{
-		zp = gzipcs->zp;
-		zp->next_in = NULL;
-		zp->avail_in = 0;
-
-		/* Flush any remaining data from zlib buffer */
-		DeflateCompressorZlib(AH, cs, true);
-
-		if (deflateEnd(zp) != Z_OK)
-			pg_fatal("could not close compression stream: %s", zp->msg);
-
-		pg_free(gzipcs->outbuf);
-		pg_free(gzipcs->zp);
-	}
-
-	pg_free(gzipcs);
-	cs->private_data = NULL;
-}
-
 static void
 WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
 					   const void *data, size_t dLen)
 {
 	ZlibCompressorState *gzipcs = (ZlibCompressorState *) cs->private_data;
 	z_streamp	zp;
 
 	if (!gzipcs->zp)
 	{
 		zp = gzipcs->zp = (z_streamp) pg_malloc(sizeof(z_stream));
 		zp->zalloc = Z_NULL;
@@ -193,40 +218,22 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, CompressorState *cs)
 		ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
 	}
 
 	if (inflateEnd(zp) != Z_OK)
 		pg_fatal("could not close compression library: %s", zp->msg);
 
 	free(buf);
 	free(out);
 	free(zp);
 }
 
-/* Public routines that support zlib compressed data I/O */
-void
-InitCompressorZlib(CompressorState *cs,
-				   const pg_compress_specification compression_spec)
-{
-	ZlibCompressorState *gzipcs;
-
-	cs->readData = ReadDataFromArchiveZlib;
-	cs->writeData = WriteDataToArchiveZlib;
-	cs->end = EndCompressorZlib;
-
-	cs->compression_spec = compression_spec;
-
-	gzipcs = (ZlibCompressorState *) pg_malloc0(sizeof(ZlibCompressorState));
-
-	cs->private_data = gzipcs;
-}
-
 
 /*----------------------
  * Compress File API
  *----------------------
  */
 
 static size_t
 Gzip_read(void *ptr, size_t size, CompressFileHandle *CFH)
 {
 	gzFile		gzfp = (gzFile) CFH->private_data;
 	size_t		ret;
-- 
2.34.1

--eJnRUKwClWJh1Khz
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
 filename="0003-pg_dump-call-deflateInit-in-Init-rather-than-in-Writ.patch"