{"thread":{"id":"4679","subject":"[PATCH] Print empty line between raw, stat, summary and patch","startedAt":"2006-06-27T12:09:17Z","lastAt":"2006-06-27T18:03:24Z","messageCount":2,"participants":["Timo Hirvonen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22666","messageId":"20060627150917.7eabde58.tihirvon@gmail.com","threadId":"4679","inReplyTo":null,"subject":"[PATCH] Print empty line between raw, stat, summary and patch","fromName":"Timo Hirvonen","fromEmail":"tihirvon@gmail.com","sentAt":"2006-06-27T12:09:17Z","receivedAt":"2006-06-27T12:09:17Z","isPatch":true,"sender":{"key":"tihirvon@gmail.com","avatar":null},"body":"Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>\n---\n\n  Should we print options->line_termination instead of \\n between all\n  fields?  The old code didn't support as many combinations of raw,\n  stat, summary and patch so I'm not 100% sure about this.\n\n diff.c |   47 ++++++++++++++++++++++++++++++++++++++++++-----\n 1 files changed, 42 insertions(+), 5 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 8880150..2c47f11 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2040,15 +2040,43 @@ static void diff_summary(struct diff_fil\n \t}\n }\n \n+static int is_summary_empty(const struct diff_queue_struct *q)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < q->nr; i++) {\n+\t\tconst struct diff_filepair *p = q->queue[i];\n+\n+\t\tswitch (p->status) {\n+\t\tcase DIFF_STATUS_DELETED:\n+\t\tcase DIFF_STATUS_ADDED:\n+\t\tcase DIFF_STATUS_COPIED:\n+\t\tcase DIFF_STATUS_RENAMED:\n+\t\t\treturn 0;\n+\t\tdefault:\n+\t\t\tif (p->score)\n+\t\t\t\treturn 0;\n+\t\t\tif (p->one->mode && p->two->mode &&\n+\t\t\t    p->one->mode != p->two->mode)\n+\t\t\t\treturn 0;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\treturn 1;\n+}\n+\n void diff_flush(struct diff_options *options)\n {\n \tstruct diff_queue_struct *q = &diff_queued_diff;\n \tint i, output_format = options->output_format;\n+\tint separator = 0;\n \n \t/*\n \t * Order: raw, stat, summary, patch\n \t * or:    name/name-status/checkdiff (other bits clear)\n \t */\n+\tif (!q->nr)\n+\t\tgoto free_queue;\n \n \tif (output_format & (DIFF_FORMAT_RAW |\n \t\t\t     DIFF_FORMAT_NAME |\n@@ -2059,11 +2087,15 @@ void diff_flush(struct diff_options *opt\n \t\t\tif (check_pair_status(p))\n \t\t\t\tflush_one_pair(p, options);\n \t\t}\n+\t\tseparator++;\n \t}\n \n \tif (output_format & DIFF_FORMAT_DIFFSTAT) {\n \t\tstruct diffstat_t diffstat;\n \n+\t\tif (separator++)\n+\t\t\tputchar('\\n');\n+\n \t\tmemset(&diffstat, 0, sizeof(struct diffstat_t));\n \t\tdiffstat.xm.consume = diffstat_consume;\n \t\tfor (i = 0; i < q->nr; i++) {\n@@ -2074,18 +2106,22 @@ void diff_flush(struct diff_options *opt\n \t\tshow_stats(&diffstat);\n \t}\n \n-\tif (output_format & DIFF_FORMAT_SUMMARY) {\n+\tif (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {\n+\t\tif (separator++)\n+\t\t\tputchar('\\n');\n+\n \t\tfor (i = 0; i < q->nr; i++)\n \t\t\tdiff_summary(q->queue[i]);\n \t}\n \n \tif (output_format & DIFF_FORMAT_PATCH) {\n-\t\tif (output_format & (DIFF_FORMAT_DIFFSTAT |\n-\t\t\t\t     DIFF_FORMAT_SUMMARY)) {\n-\t\t\tif (options->stat_sep)\n+\t\tif (separator) {\n+\t\t\tif (options->stat_sep) {\n+\t\t\t\t/* attach patch instead of inline */\n \t\t\t\tfputs(options->stat_sep, stdout);\n-\t\t\telse\n+\t\t\t} else {\n \t\t\t\tputchar(options->line_termination);\n+\t\t\t}\n \t\t}\n \n \t\tfor (i = 0; i < q->nr; i++) {\n@@ -2097,6 +2133,7 @@ void diff_flush(struct diff_options *opt\n \n \tfor (i = 0; i < q->nr; i++)\n \t\tdiff_free_filepair(q->queue[i]);\n+free_queue:\n \tfree(q->queue);\n \tq->queue = NULL;\n \tq->nr = q->alloc = 0;\n-- \n1.4.1.rc1.g8637\n"},{"id":"22681","messageId":"7vhd268oib.fsf@assigned-by-dhcp.cox.net","threadId":"4679","inReplyTo":"20060627150917.7eabde58.tihirvon@gmail.com","subject":"Re: [PATCH] Print empty line between raw, stat, summary and patch","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-27T18:03:24Z","receivedAt":"2006-06-27T18:03:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Timo Hirvonen <tihirvon@gmail.com> writes:\n\n> Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>\n> ---\n>\n>   Should we print options->line_termination instead of \\n between all\n>   fields?\n\nI personally do not think it is a big deal since combination of\nstat, summary and patch are primarily for human consumption, but\nsomebody might want to write a frontend GUI on top of this\noutput and having an easy way to seperate the parts for machine\nconsumption might be helpful.\n\n>   The old code didn't support as many combinations of raw,\n>   stat, summary and patch so I'm not 100% sure about this.\n\nThink of it as an opportunity to come up with the most sensible\nwithout having to worry about backward compatibility ;-)  I'll\nlet you know what I think after I stare at its output for some\ntime.\n\nThanks.\n"}]}