btrfs-progs: change formatting for plain text lines
Line continuations and not simple "\n" for the json output, this got inherited to the plain text output, but this is not necessary. This also caused problems in fstests btrfs/006 where the extra newline does not match the golden output and the test fails, when printing device stats that now use the output formatter. Change the plain text formatting to always expect that a fmt_print or a manual line print (like is for the device stats) will append the newline and remove it from the end of formatting. Link: https://lore.kernel.org/linux-btrfs/CAL3q7H4b7QhL02aSOpN0-k_9P2EAbj1t+NkA6VwidKEg4S996w@mail.gmail.com Reported-by: Filipe Manana <fdmanana@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a7eca5cfe4
commit
ce2de8282b
|
@ -123,10 +123,7 @@ void fmt_end(struct format_ctx *fctx)
|
|||
fprintf(stderr, "WARNING: wrong nesting\n");
|
||||
|
||||
/* Close, no continuation to print */
|
||||
|
||||
if (bconf.output_format & CMD_FORMAT_TEXT)
|
||||
putchar('\n');
|
||||
else if (bconf.output_format & CMD_FORMAT_JSON) {
|
||||
if (bconf.output_format & CMD_FORMAT_JSON) {
|
||||
fmt_dec_depth(fctx);
|
||||
fmt_separator(fctx);
|
||||
printf("}\n");
|
||||
|
@ -168,8 +165,15 @@ void fmt_start_value(struct format_ctx *fctx, const struct rowspec *row)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Newline depends on format type:
|
||||
* - json does delayed continuation "," in case there's a following object
|
||||
* - plain text always ends with a newline
|
||||
*/
|
||||
void fmt_end_value(struct format_ctx *fctx, const struct rowspec *row)
|
||||
{
|
||||
if (bconf.output_format == CMD_FORMAT_TEXT)
|
||||
putchar('\n');
|
||||
if (bconf.output_format == CMD_FORMAT_JSON) {
|
||||
if (strcmp(row->fmt, "list") == 0) {
|
||||
} else if (strcmp(row->fmt, "map") == 0) {
|
||||
|
@ -242,7 +246,7 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
|
|||
const bool print_colon = row->out_text[0];
|
||||
int len;
|
||||
|
||||
putchar('\n');
|
||||
/* Print indented key name */
|
||||
fmt_indent1(fctx->indent);
|
||||
len = strlen(row->out_text);
|
||||
|
||||
|
@ -251,6 +255,7 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
|
|||
putchar(':');
|
||||
len++;
|
||||
}
|
||||
/* Align start for the value */
|
||||
fmt_indent1(fctx->width - len);
|
||||
} else if (bconf.output_format == CMD_FORMAT_JSON) {
|
||||
if (strcmp(row->fmt, "list") == 0) {
|
||||
|
@ -312,6 +317,5 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
|
|||
}
|
||||
|
||||
fmt_end_value(fctx, row);
|
||||
/* No newline here, the line is closed by next value or group end */
|
||||
va_end(args);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue