diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 1544b422da..e31edb88b0 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -149,7 +149,7 @@ static LineType classify_line_type(const char *line, CatFlags flags) { static int cat_file(const char *filename, bool newline, CatFlags flags) { _cleanup_fclose_ FILE *f = NULL; - _cleanup_free_ char *urlified = NULL, *section = NULL; + _cleanup_free_ char *urlified = NULL, *section = NULL, *old_section = NULL; int r; f = fopen(filename, "re"); @@ -189,11 +189,14 @@ static int cat_file(const char *filename, bool newline, CatFlags flags) { /* Before we print the actual line, print the last section header */ if (section) { - printf("%s%s%s\n", - ansi_highlight_cyan(), - section, - ansi_normal()); - section = mfree(section); + /* Do not print redundant section headers */ + if (!streq_ptr(section, old_section)) + printf("%s%s%s\n", + ansi_highlight_cyan(), + section, + ansi_normal()); + + free_and_replace(old_section, section); } }