{"thread":{"id":"46615","subject":"[PATCH] diff: retire sane_truncate_fn","startedAt":"2017-08-17T17:27:37Z","lastAt":"2017-08-17T17:42:06Z","messageCount":2,"participants":["Junio C Hamano","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"326610","messageId":"xmqq1soahzpb.fsf@gitster.mtv.corp.google.com","threadId":"46615","inReplyTo":null,"subject":"[PATCH] diff: retire sane_truncate_fn","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-17T17:27:28Z","receivedAt":"2017-08-17T17:27:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Long time ago, 23707811 (\"diff: do not chomp hunk-header in the\nmiddle of a character\", 2008-01-02) introduced sane_truncate_line()\nhelper function to trim the \"function header\" line that is shown at\nthe end of the hunk header line, in order to avoid chomping it in\nthe middle of a single UTF-8 character.  It also added a facility to\ndefine a custom callback function to make it possible to extend it\nto non UTF-8 encodings.  \n\nDuring the following 8 1/2 years, nobody found need for this custom\ncallback facility.\n\nA custom callback function is a wrong design to use here anyway---if\nyour contents need support for non UTF-8 encoding, you shouldn't\nhave to write a custom function and recompile Git to plumb it in.  A\nbetter approach would be to extend sane_truncate_line() function and\nhave a new member in emit_callback to conditionally trigger it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c | 5 -----\n 1 file changed, 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex a628ac3a95..4bdaed8197 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -408,8 +408,6 @@ static struct diff_tempfile {\n \tstruct tempfile tempfile;\n } diff_temp[2];\n \n-typedef unsigned long (*sane_truncate_fn)(char *line, unsigned long len);\n-\n struct emit_callback {\n \tint color_diff;\n \tunsigned ws_rule;\n@@ -417,7 +415,6 @@ struct emit_callback {\n \tint blank_at_eof_in_postimage;\n \tint lno_in_preimage;\n \tint lno_in_postimage;\n-\tsane_truncate_fn truncate;\n \tconst char **label_path;\n \tstruct diff_words_data *diff_words;\n \tstruct diff_options *opt;\n@@ -1246,8 +1243,6 @@ static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, u\n \tunsigned long allot;\n \tsize_t l = len;\n \n-\tif (ecb->truncate)\n-\t\treturn ecb->truncate(line, len);\n \tcp = line;\n \tallot = l;\n \twhile (0 < l) {\n"},{"id":"326614","messageId":"CAGZ79kZgUCBd0uUjuwvKsUSaAUfpU-wxe6+nVPO_1BXroiCd4w@mail.gmail.com","threadId":"46615","inReplyTo":"xmqq1soahzpb.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] diff: retire sane_truncate_fn","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-08-17T17:42:00Z","receivedAt":"2017-08-17T17:42:06Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Aug 17, 2017 at 10:27 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Long time ago, 23707811 (\"diff: do not chomp hunk-header in the\n> middle of a character\", 2008-01-02) introduced sane_truncate_line()\n> helper function to trim the \"function header\" line that is shown at\n> the end of the hunk header line, in order to avoid chomping it in\n> the middle of a single UTF-8 character.  It also added a facility to\n> define a custom callback function to make it possible to extend it\n> to non UTF-8 encodings.\n>\n> During the following 8 1/2 years, nobody found need for this custom\n> callback facility.\n>\n> A custom callback function is a wrong design to use here anyway---if\n> your contents need support for non UTF-8 encoding, you shouldn't\n> have to write a custom function and recompile Git to plumb it in.  A\n> better approach would be to extend sane_truncate_line() function and\n> have a new member in emit_callback to conditionally trigger it.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\nThis patch is\nReviewed-by: Stefan Beller <sbeller@google.com>\n\nHowever while strolling around in code nearby, I do\nwonder if sane_truncate_line needs to make use\nof the return value of utf8_width. But that is not the case\nas we're interested in the byte length, not the print length.\n\nThanks\nStefan\n"}]}