pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Japin Li <japinli@hotmail.com>
Subject: [PATCH v2] Replace the hard-coded dump headers with macros
Date: Wed, 3 Jun 2026 15:18:20 +0800

This commit repleaces the hard-coded dump headers with the existing macros to
improve maintainability and consistency:

  - In pg_backup_archiver.c, use TEXT_DUMP_HEADER instead of a duplicate
    hard-coded string for database dump header.
  - Move TEXT_DUMPALL_HEADER from pg_backup_archiver.c to pg_backup_archiver.h
    so it can be shared across files.
  - In pg_dumpall.c, replace the hard-coded cluster dump header with the newly
    exposed TEXT_DUMPALL_HEADER macro.

This avoids unnecessary duplication and ensures that any future changes to the
header text only need to be made in one place.

Author: Japin Li <japinli@hotmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
---
 src/bin/pg_dump/pg_backup_archiver.c | 3 +--
 src/bin/pg_dump/pg_backup_archiver.h | 2 ++
 src/bin/pg_dump/pg_dumpall.c         | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

inline patch 1: src/bin/pg_dump/pg_backup_archiver.c, src/bin/pg_dump/pg_backup_archiver.h, src/bin/pg_dump/pg_dumpall.c (+4/-3 lines) download inline-1.patchdiff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 2fd773ad84f..85d103464be 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -47,7 +47,6 @@ #include "pgtar.h" #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n" -#define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n" #define TOC_PREFIX_NONE "" #define TOC_PREFIX_DATA "Data for " @@ -466,7 +465,7 @@ RestoreArchive(Archive *AHX, bool append_data) if (ropt->filename || ropt->compression_spec.algorithm != PG_COMPRESSION_NONE) SetOutput(AH, ropt->filename, ropt->compression_spec, append_data); - ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n"); + ahprintf(AH, TEXT_DUMP_HEADER); /* * If generating plain-text output, enter restricted mode to block any diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index 1218bf6a6a1..21f226295a5 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -30,6 +30,8 @@ #include "pg_backup.h" #include "pqexpbuffer.h" +#define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n" + #define LOBBUFSIZE 16384 /* Data block types */ diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index c1f43113c53..49ae222211e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -740,7 +740,7 @@ main(int argc, char *argv[]) } else { - fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n"); + fprintf(OPF, TEXT_DUMPALL_HEADER); if (verbose) dumpTimestamp("Started on"); -- 2.53.0
--=-=-=--

Message-ID: <no-message-id-479841@localhost>
Permalink:  ../no-message-id-479841@localhost/
Also on:    postgresql.org/message-id/no-message-id-479841@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: japinli@hotmail.com
  Subject: Re: [PATCH v2] Replace the hard-coded dump headers with macros
  In-Reply-To: <no-message-id-479841@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox