Skip to contentSkip to conversation

btrfs-progs: format-output: remove newline in fmt_end text mode

RFC In review Sidong Yang 3 participants 5 messages Feb 16, 2021 – Feb 22, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

RFC 1/1 btrfs-progs: format-output: remove newline in fmt_end text mode

Remove a code that inserting new line in fmt_end() for text mode. Old code made a failure in fstest btrfs/006.

---
Hi, I've just read mail that Filipe written that some failure about fstest. I'm worried about this patch makes other problem. So make it RFC. Thanks.

---
 common/format-output.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
common/format-output.c +1 -3
index f5b12548..96e0dfef 100644
@@ -124,9 +124,7 @@ void fmt_end(struct format_ctx *fctx)
 
 	/* 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");
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Sidong Yang

Remove a code that inserting new line in fmt_end() for text mode. Old code made a failure in fstest btrfs/006.

---
Hi, I've just read mail that Filipe written that some failure about fstest. I'm worried about this patch makes other problem. So make it RFC. Thanks.

Fixes the test failure indeed, thanks!

Quoted 22 lines
---
 common/format-output.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
common/format-output.c +1 -4
index f5b12548..96e0dfef 100644
@@ -124,9 +124,7 @@ void fmt_end(struct format_ctx *fctx)
 
        /* 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");
--

2.25.1

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
In reply to Sidong Yang
Quoted 7 lines · Sidong Yang

Remove a code that inserting new line in fmt_end() for text mode. Old code made a failure in fstest btrfs/006.

---
Hi, I've just read mail that Filipe written that some failure about fstest. I'm worried about this patch makes other problem. So make it RFC. Thanks.

I found the discussion under the device stats patch adding json, the added line was known and "hopefully not causing problems", but the fstests seem to notice.

I think we can fix that by removing the fmt_end newline but we also need to update how the fmt_print is done for the text output. Ie. for json there are some strict rules for line continuations (",") but for the textual output, each line ended by "\n" right away, without delaying that to the next fmt_* call should work.

#3 lore raw
Quoted 13 lines · David Sterba
Quoted 7 lines · Sidong Yang

Remove a code that inserting new line in fmt_end() for text mode. Old code made a failure in fstest btrfs/006.

---
Hi, I've just read mail that Filipe written that some failure about fstest. I'm worried about this patch makes other problem. So make it RFC. Thanks.

I found the discussion under the device stats patch adding json, the added line was known and "hopefully not causing problems", but the fstests seem to notice.

Quoted 5 lines

I think we can fix that by removing the fmt_end newline but we also need to update how the fmt_print is done for the text output. Ie. for json there are some strict rules for line continuations (",") but for the textual output, each line ended by "\n" right away, without delaying that to the next fmt_* call should work.

You mean that if this patch applied and the code prints device stats for text format manually replaced to fmt_print(), there is no last new line for text output? fmt_print() prints new line before print some value now. I think that it should prints new line at the end of each fmt_print(). like below

common/format-output.c +2 -1
index f5b12548..9a9f5bf7 100644
@@ -242,7 +239,6 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
                const bool print_colon = row->out_text[0];
                int len;
 
-               putchar('\n');
                fmt_indent1(fctx->indent);
                len = strlen(row->out_text);
 
@@ -312,6 +308,8 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
        }
 
        fmt_end_value(fctx, row);
+       if (bconf.output_format == CMD_FORMAT_TEXT)
+               putchar('\n');
        /* No newline here, the line is closed by next value or group end */
        va_end(args);
 }

Thanks,
Sidong

#4 lore raw
Quoted 39 lines · Sidong Yang
Quoted 13 lines · David Sterba
Quoted 7 lines · Sidong Yang

Remove a code that inserting new line in fmt_end() for text mode. Old code made a failure in fstest btrfs/006.

---
Hi, I've just read mail that Filipe written that some failure about fstest. I'm worried about this patch makes other problem. So make it RFC. Thanks.

I found the discussion under the device stats patch adding json, the added line was known and "hopefully not causing problems", but the fstests seem to notice.

Quoted 5 lines

I think we can fix that by removing the fmt_end newline but we also need to update how the fmt_print is done for the text output. Ie. for json there are some strict rules for line continuations (",") but for the textual output, each line ended by "\n" right away, without delaying that to the next fmt_* call should work.

You mean that if this patch applied and the code prints device stats for text format manually replaced to fmt_print(), there is no last new line for text output? fmt_print() prints new line before print some value now. I think that it should prints new line at the end of each fmt_print(). like below

common/format-output.c +0 -1
index f5b12548..9a9f5bf7 100644
@@ -242,7 +239,6 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
                const bool print_colon = row->out_text[0];
                int len;
 
-               putchar('\n');
                fmt_indent1(fctx->indent);
                len = strlen(row->out_text);
 

common/format-output.c void fmt_print(struct format_ctx *fctx, const char* key, ...) · line 312

Quoted 5 lines
common/format-output.c +2 -0
@@ -312,6 +308,8 @@ void fmt_print(struct format_ctx *fctx, const char* key, ...)
        }
 
        fmt_end_value(fctx, row);
+       if (bconf.output_format == CMD_FORMAT_TEXT)
+               putchar('\n');

Yeah effectively that, but inside fmt_end_value and removing it from fmt_end. It's fixed in devel now with some comments updated as the plain text and json are different.