{"thread":{"id":"47618","subject":"[PATCH] diff.c: flush stdout before printing rename warnings","startedAt":"2018-01-16T09:25:31Z","lastAt":"2018-01-17T01:04:59Z","messageCount":3,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"336649","messageId":"20180116092349.11330-1-pclouds@gmail.com","threadId":"47618","inReplyTo":null,"subject":"[PATCH] diff.c: flush stdout before printing rename warnings","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-01-16T09:23:49Z","receivedAt":"2018-01-16T09:25:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The diff output is buffered in a FILE object and could still be\npartially buffered when we print these warnings (directly to fd 2).\nThe output is messed up like this\n\n worktree.c                                   |   138 +-\n worktree.h        warning: inexact rename detection was skipped due to too many files.\n                           |    12 +-\n wrapper.c                                    |    83 +-\n\nIt gets worse if the warning is printed after color codes for the graph\npart are already printed. You'll get a warning in green or red.\n\nFlush stdout first, so we can get something like this instead:\n\n xdiff/xutils.c                               |    42 +-\n xdiff/xutils.h                               |     4 +-\n 1033 files changed, 150824 insertions(+), 69395 deletions(-)\nwarning: inexact rename detection was skipped due to too many files.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff.c | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/diff.c b/diff.c\nindex fb22b19f09..5545c25640 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5454,6 +5454,7 @@ N_(\"you may want to set your %s variable to at least \"\n \n void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc)\n {\n+\tfflush(stdout);\n \tif (degraded_cc)\n \t\twarning(_(degrade_cc_to_c_warning));\n \telse if (needed)\n-- \n2.15.1.600.g899a5f85c6\n\n"},{"id":"336669","messageId":"xmqqd129vd17.fsf@gitster.mtv.corp.google.com","threadId":"47618","inReplyTo":"20180116092349.11330-1-pclouds@gmail.com","subject":"Re: [PATCH] diff.c: flush stdout before printing rename warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-01-16T19:06:44Z","receivedAt":"2018-01-16T19:06:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> The diff output is buffered in a FILE object and could still be\n> partially buffered when we print these warnings (directly to fd 2).\n> The output is messed up like this\n>\n>  worktree.c                                   |   138 +-\n>  worktree.h        warning: inexact rename detection was skipped due to too many files.\n>                            |    12 +-\n>  wrapper.c                                    |    83 +-\n>\n> It gets worse if the warning is printed after color codes for the graph\n> part are already printed. You'll get a warning in green or red.\n>\n> Flush stdout first, so we can get something like this instead:\n>\n>  xdiff/xutils.c                               |    42 +-\n>  xdiff/xutils.h                               |     4 +-\n>  1033 files changed, 150824 insertions(+), 69395 deletions(-)\n> warning: inexact rename detection was skipped due to too many files.\n\nThe patch sort-of makes sense, and I am not sure if any of the\nissues that show rooms for potential improvements I'll mention are\nworth doing.\n\n - This matters only when the standard output and the starndard error\n   are going to the same place.  It also would be conceptually nicer to\n   flush stderr as well even though it is by default not fully\n   buffered.\n\n - Also this function can take two bools and gives a warning that\n   potentially cause the issue three out of four combinations, so one\n   out of four cases we would be unnecessarily flushing.\n\n\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  diff.c | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/diff.c b/diff.c\n> index fb22b19f09..5545c25640 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -5454,6 +5454,7 @@ N_(\"you may want to set your %s variable to at least \"\n>  \n>  void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc)\n>  {\n> +\tfflush(stdout);\n>  \tif (degraded_cc)\n>  \t\twarning(_(degrade_cc_to_c_warning));\n>  \telse if (needed)\n"},{"id":"336687","messageId":"CACsJy8AzU_WUFvhBKZ76korGJoMy9-6XXx7kZUKyz2GoHgxXGg@mail.gmail.com","threadId":"47618","inReplyTo":"xmqqd129vd17.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] diff.c: flush stdout before printing rename warnings","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-01-17T01:04:21Z","receivedAt":"2018-01-17T01:04:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jan 17, 2018 at 2:06 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>> The diff output is buffered in a FILE object and could still be\n>> partially buffered when we print these warnings (directly to fd 2).\n>> The output is messed up like this\n>>\n>>  worktree.c                                   |   138 +-\n>>  worktree.h        warning: inexact rename detection was skipped due to too many files.\n>>                            |    12 +-\n>>  wrapper.c                                    |    83 +-\n>>\n>> It gets worse if the warning is printed after color codes for the graph\n>> part are already printed. You'll get a warning in green or red.\n>>\n>> Flush stdout first, so we can get something like this instead:\n>>\n>>  xdiff/xutils.c                               |    42 +-\n>>  xdiff/xutils.h                               |     4 +-\n>>  1033 files changed, 150824 insertions(+), 69395 deletions(-)\n>> warning: inexact rename detection was skipped due to too many files.\n>\n> The patch sort-of makes sense, and I am not sure if any of the\n> issues that show rooms for potential improvements I'll mention are\n> worth doing.\n>\n>  - This matters only when the standard output and the starndard error\n>    are going to the same place.\n\nWhich is usually true when pager is involved because we redirect\nstderr to the pager too 61b80509e3 (sending errors to stdout under\n$PAGER - 2008-02-16)\n\n>    It also would be conceptually nicer to\n>    flush stderr as well even though it is by default not fully\n>    buffered.\n\nThere's more than that. I briefly considered if the same thing could\nhappen elsewhere, this is not the only place we use buffered stdio.\nBut since it's just a minor annoyance, I stuck to minimal fixes and\nthe \"fix as we see\" approach instead of scanning the whole code base\nand preventing similar cases.\n-- \nDuy\n"}]}