{"thread":{"id":"59995","subject":"[PATCH] Prefer fgetc over fgets where possible","startedAt":"2023-07-17T15:38:30Z","lastAt":"2024-12-18T01:16:45Z","messageCount":4,"participants":["AtariDreams via GitGitGadget","Junio C Hamano","Taylor Blau","AreaZR via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"479575","messageId":"pull.1550.git.git.1689608291732.gitgitgadget@gmail.com","threadId":"59995","inReplyTo":null,"subject":"[PATCH] Prefer fgetc over fgets where possible","fromName":"AtariDreams via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-07-17T15:38:11Z","receivedAt":"2023-07-17T15:38:30Z","isPatch":true,"sender":{"key":"name:AtariDreams","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nfputc is meant for single characters,\nfputs is for strings. We are better off\ninserting sole \\n characters as\ncharacters, not whole strings.\n\nSigned-off-by: Seija Kijin doremylover123@gmail.com\n---\n    Prefer fgetc over fgets where possible\n    \n    fputc is meant for single characters, fputs is for strings. We are\n    better off inserting sole \\n characters as characters, not whole\n    strings.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1550%2FAtariDreams%2Ffgetc-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1550/AtariDreams/fgetc-v1\nPull-Request: https://github.com/git/git/pull/1550\n\n wt-status.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 8a1a4fb1f04..4c267395cdf 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1215,7 +1215,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)\n \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"%c\",\n \t\t\t\t comment_line_char);\n \telse\n-\t\tfputs(\"\\n\", s->fp);\n+\t\tfputc('\\n', s->fp);\n \tstrbuf_release(&sb);\n }\n \n@@ -1814,7 +1814,7 @@ static void wt_longstatus_print_state(struct wt_status *s)\n \tif (state->merge_in_progress) {\n \t\tif (state->rebase_interactive_in_progress) {\n \t\t\tshow_rebase_information(s, state_color);\n-\t\t\tfputs(\"\\n\", s->fp);\n+\t\t\tfputc('\\n', s->fp);\n \t\t}\n \t\tshow_merge_in_progress(s, state_color);\n \t} else if (state->am_in_progress)\n\nbase-commit: 830b4a04c45bf0a6db26defe02ed1f490acd18ee\n-- \ngitgitgadget\n"},{"id":"479580","messageId":"xmqq7cqyiiqp.fsf@gitster.g","threadId":"59995","inReplyTo":"pull.1550.git.git.1689608291732.gitgitgadget@gmail.com","subject":"Re: [PATCH] Prefer fgetc over fgets where possible","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-17T16:51:42Z","receivedAt":"2023-07-17T16:52:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"AtariDreams via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Seija Kijin <doremylover123@gmail.com>\n>\n> fputc is meant for single characters,\n> fputs is for strings. We are better off\n> inserting sole \\n characters as\n> characters, not whole strings.\n\nI do not see if these short lines are deliberate; are they meant to\nfollow some sort of poetry styles?\n\nIn any case, while the above is correct, I do not see the patch\nnoise is worth it in this particular case.  Yes, if we are writing\ncode snippets shown with the context in these hunks afresh, please\ncarefully choose between fputs() and fputc().  But once the code is\nwritten and it is in, it is not worth to go back and fix it, unless\nwe are fixing surrounding area and doing the clean-up as a \"while at\nit\" change.\n\nBy the way, because my mail program warned against an address that\napparently refuses to receive any replies, I had to manually remove\n\"AtariDreams <83477269+AtariDreams@users.noreply.github.com>\" while\ncomposing this message.  I'd appreciate it if you arrange to ensure\nthat your next patch will not have such addresses on your CC: line.\n\nThanks.\n\n"},{"id":"479582","messageId":"ZLWhLH2xRq20jFFY@nand.local","threadId":"59995","inReplyTo":"pull.1550.git.git.1689608291732.gitgitgadget@gmail.com","subject":"Re: [PATCH] Prefer fgetc over fgets where possible","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2023-07-17T20:14:36Z","receivedAt":"2023-07-17T20:14:42Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Jul 17, 2023 at 03:38:11PM +0000, AtariDreams via GitGitGadget wrote:\n> ---\n>     Prefer fgetc over fgets where possible\n>\n>     fputc is meant for single characters, fputs is for strings. We are\n>     better off inserting sole \\n characters as characters, not whole\n>     strings.\n>\n>     Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nI tend to agree with Junio's assessment that adding churn here isn't\nstrictly necessary / worth it, but if we do end up taking this patch,\nnote that the subject should reference `fputc()` and `fputs()` instead\nof `fgetc()` and `fgets()`.\n\nTaylor\n"},{"id":"509260","messageId":"pull.1550.v2.git.git.1734484601471.gitgitgadget@gmail.com","threadId":"59995","inReplyTo":"pull.1550.git.git.1689608291732.gitgitgadget@gmail.com","subject":"[PATCH v2] Prefer fgetc over fgets where possible","fromName":"AreaZR via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-12-18T01:16:41Z","receivedAt":"2024-12-18T01:16:45Z","isPatch":true,"sender":{"key":"name:AreaZR","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nfputc is meant for single characters,\nfputs is for strings. We are better off\ninserting sole \\n characters as\ncharacters, not whole strings.\n\nSigned-off-by: Seija Kijin doremylover123@gmail.com\n---\n    Prefer fgetc over fgets where possible\n    \n    fputc is meant for single characters, fputs is for strings. We are\n    better off inserting sole \\n characters as characters, not whole\n    strings.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1550%2FAreaZR%2Ffgetc-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1550/AreaZR/fgetc-v2\nPull-Request: https://github.com/git/git/pull/1550\n\nRange-diff vs v1:\n\n 1:  f833a7cc857 ! 1:  26f329befbd Prefer fgetc over fgets where possible\n     @@ Commit message\n      \n          Signed-off-by: Seija Kijin doremylover123@gmail.com\n      \n     + ## bisect.c ##\n     +@@ bisect.c: static void show_list(const char *debug, int counted, int nr,\n     + \t\tsubject_len = find_commit_subject(buf, &subject_start);\n     + \t\tif (subject_len)\n     + \t\t\tfprintf(stderr, \" %.*s\", subject_len, subject_start);\n     +-\t\tfprintf(stderr, \"\\n\");\n     ++\t\tfputc('\\n', stderr);\n     + \t}\n     + }\n     + \n     +\n     + ## commit-graph.c ##\n     +@@ commit-graph.c: static void graph_report(const char *fmt, ...)\n     + \tverify_commit_graph_error = 1;\n     + \tva_start(ap, fmt);\n     + \tvfprintf(stderr, fmt, ap);\n     +-\tfprintf(stderr, \"\\n\");\n     ++\tfputc('\\n', stderr);\n     + \tva_end(ap);\n     + }\n     + \n     +\n       ## wt-status.c ##\n      @@ wt-status.c: static void wt_longstatus_print_tracking(struct wt_status *s)\n     - \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"%c\",\n     - \t\t\t\t comment_line_char);\n     + \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"%s\",\n     + \t\t\t\t comment_line_str);\n       \telse\n      -\t\tfputs(\"\\n\", s->fp);\n      +\t\tfputc('\\n', s->fp);\n\n\n bisect.c       | 2 +-\n commit-graph.c | 2 +-\n wt-status.c    | 4 ++--\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex d71c4e4b44b..3b1e034013f 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -179,7 +179,7 @@ static void show_list(const char *debug, int counted, int nr,\n \t\tsubject_len = find_commit_subject(buf, &subject_start);\n \t\tif (subject_len)\n \t\t\tfprintf(stderr, \" %.*s\", subject_len, subject_start);\n-\t\tfprintf(stderr, \"\\n\");\n+\t\tfputc('\\n', stderr);\n \t}\n }\n \ndiff --git a/commit-graph.c b/commit-graph.c\nindex e2e2083951c..b649598916a 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -2696,7 +2696,7 @@ static void graph_report(const char *fmt, ...)\n \tverify_commit_graph_error = 1;\n \tva_start(ap, fmt);\n \tvfprintf(stderr, fmt, ap);\n-\tfprintf(stderr, \"\\n\");\n+\tfputc('\\n', stderr);\n \tva_end(ap);\n }\n \ndiff --git a/wt-status.c b/wt-status.c\nindex 6a8c05d1cff..75b8e900a4c 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1227,7 +1227,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)\n \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"%s\",\n \t\t\t\t comment_line_str);\n \telse\n-\t\tfputs(\"\\n\", s->fp);\n+\t\tfputc('\\n', s->fp);\n \tstrbuf_release(&sb);\n }\n \n@@ -1832,7 +1832,7 @@ static void wt_longstatus_print_state(struct wt_status *s)\n \tif (state->merge_in_progress) {\n \t\tif (state->rebase_interactive_in_progress) {\n \t\t\tshow_rebase_information(s, state_color);\n-\t\t\tfputs(\"\\n\", s->fp);\n+\t\t\tfputc('\\n', s->fp);\n \t\t}\n \t\tshow_merge_in_progress(s, state_color);\n \t} else if (state->am_in_progress)\n\nbase-commit: 063bcebf0c917140ca0e705cbe0fdea127e90086\n-- \ngitgitgadget\n"}]}