@matheusbsbs / matheus-bagliano / commits / 946c3784a3
Fork 0

Print empty line between raw, stat, summary and patch

Signed-off-by: Timo Hirvonen <tihirvon@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Timo Hirvonen committed Jun 27, 2006 at 15:09 UTC 946c3784a3586e70c70c3a676f590654ca39a3cb
1 file changed +42 -5
diff.c
+42 -5
@@ -2093,15 +2093,43 @@ static void diff_summary(struct diff_filepair *p)
2093 }
2094 }
2095
2096 +static int is_summary_empty(const struct diff_queue_struct *q)
2097 +{
2098 + int i;
2099 +
2100 + for (i = 0; i < q->nr; i++) {
2101 + const struct diff_filepair *p = q->queue[i];
2102 +
2103 + switch (p->status) {
2104 + case DIFF_STATUS_DELETED:
2105 + case DIFF_STATUS_ADDED:
2106 + case DIFF_STATUS_COPIED:
2107 + case DIFF_STATUS_RENAMED:
2108 + return 0;
2109 + default:
2110 + if (p->score)
2111 + return 0;
2112 + if (p->one->mode && p->two->mode &&
2113 + p->one->mode != p->two->mode)
2114 + return 0;
2115 + break;
2116 + }
2117 + }
2118 + return 1;
2119 +}
2120 +
2121 void diff_flush(struct diff_options *options)
2122 {
2123 struct diff_queue_struct *q = &diff_queued_diff;
2124 int i, output_format = options->output_format;
2125 + int separator = 0;
2126
2127 /*
2128 * Order: raw, stat, summary, patch
2129 * or: name/name-status/checkdiff (other bits clear)
2130 */
2131 + if (!q->nr)
2132 + goto free_queue;
2133
2134 if (output_format & (DIFF_FORMAT_RAW |
2135 DIFF_FORMAT_NAME |
@@ -2112,11 +2140,15 @@ void diff_flush(struct diff_options *options)
2140 if (check_pair_status(p))
2141 flush_one_pair(p, options);
2142 }
2143 + separator++;
2144 }
2145
2146 if (output_format & DIFF_FORMAT_DIFFSTAT) {
2147 struct diffstat_t diffstat;
2148
2149 + if (separator++)
2150 + putchar('\n');
2151 +
2152 memset(&diffstat, 0, sizeof(struct diffstat_t));
2153 diffstat.xm.consume = diffstat_consume;
2154 for (i = 0; i < q->nr; i++) {
@@ -2127,18 +2159,22 @@ void diff_flush(struct diff_options *options)
2159 show_stats(&diffstat);
2160 }
2161
2130 - if (output_format & DIFF_FORMAT_SUMMARY) {
2162 + if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
2163 + if (separator++)
2164 + putchar('\n');
2165 +
2166 for (i = 0; i < q->nr; i++)
2167 diff_summary(q->queue[i]);
2168 }
2169
2170 if (output_format & DIFF_FORMAT_PATCH) {
2136 - if (output_format & (DIFF_FORMAT_DIFFSTAT |
2137 - DIFF_FORMAT_SUMMARY)) {
2138 - if (options->stat_sep)
2171 + if (separator) {
2172 + if (options->stat_sep) {
2173 + /* attach patch instead of inline */
2174 fputs(options->stat_sep, stdout);
2140 - else
2175 + } else {
2176 putchar(options->line_termination);
2177 + }
2178 }
2179
2180 for (i = 0; i < q->nr; i++) {
@@ -2150,6 +2186,7 @@ void diff_flush(struct diff_options *options)
2186
2187 for (i = 0; i < q->nr; i++)
2188 diff_free_filepair(q->queue[i]);
2189 +free_queue:
2190 free(q->queue);
2191 q->queue = NULL;
2192 q->nr = q->alloc = 0;