shared/pretty-print: skip redundant section headers with --tldr
If the same section appears consecutively in a given file, subsequent occurenced are not printed. [Slice] Foo=bar [Slice] # this is not printed Bar=bar Requested in https://github.com/systemd/systemd/pull/29553#pullrequestreview-1677310352.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user