* [PATCH] Print empty line between raw, stat, summary and patch
@ 2006-06-27 12:09 Timo Hirvonen
2006-06-27 18:03 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Timo Hirvonen @ 2006-06-27 12:09 UTC (permalink / raw)
To: junkio; +Cc: git
Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
---
Should we print options->line_termination instead of \n between all
fields? The old code didn't support as many combinations of raw,
stat, summary and patch so I'm not 100% sure about this.
diff.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index 8880150..2c47f11 100644
--- a/diff.c
+++ b/diff.c
@@ -2040,15 +2040,43 @@ static void diff_summary(struct diff_fil
}
}
+static int is_summary_empty(const struct diff_queue_struct *q)
+{
+ int i;
+
+ for (i = 0; i < q->nr; i++) {
+ const struct diff_filepair *p = q->queue[i];
+
+ switch (p->status) {
+ case DIFF_STATUS_DELETED:
+ case DIFF_STATUS_ADDED:
+ case DIFF_STATUS_COPIED:
+ case DIFF_STATUS_RENAMED:
+ return 0;
+ default:
+ if (p->score)
+ return 0;
+ if (p->one->mode && p->two->mode &&
+ p->one->mode != p->two->mode)
+ return 0;
+ break;
+ }
+ }
+ return 1;
+}
+
void diff_flush(struct diff_options *options)
{
struct diff_queue_struct *q = &diff_queued_diff;
int i, output_format = options->output_format;
+ int separator = 0;
/*
* Order: raw, stat, summary, patch
* or: name/name-status/checkdiff (other bits clear)
*/
+ if (!q->nr)
+ goto free_queue;
if (output_format & (DIFF_FORMAT_RAW |
DIFF_FORMAT_NAME |
@@ -2059,11 +2087,15 @@ void diff_flush(struct diff_options *opt
if (check_pair_status(p))
flush_one_pair(p, options);
}
+ separator++;
}
if (output_format & DIFF_FORMAT_DIFFSTAT) {
struct diffstat_t diffstat;
+ if (separator++)
+ putchar('\n');
+
memset(&diffstat, 0, sizeof(struct diffstat_t));
diffstat.xm.consume = diffstat_consume;
for (i = 0; i < q->nr; i++) {
@@ -2074,18 +2106,22 @@ void diff_flush(struct diff_options *opt
show_stats(&diffstat);
}
- if (output_format & DIFF_FORMAT_SUMMARY) {
+ if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
+ if (separator++)
+ putchar('\n');
+
for (i = 0; i < q->nr; i++)
diff_summary(q->queue[i]);
}
if (output_format & DIFF_FORMAT_PATCH) {
- if (output_format & (DIFF_FORMAT_DIFFSTAT |
- DIFF_FORMAT_SUMMARY)) {
- if (options->stat_sep)
+ if (separator) {
+ if (options->stat_sep) {
+ /* attach patch instead of inline */
fputs(options->stat_sep, stdout);
- else
+ } else {
putchar(options->line_termination);
+ }
}
for (i = 0; i < q->nr; i++) {
@@ -2097,6 +2133,7 @@ void diff_flush(struct diff_options *opt
for (i = 0; i < q->nr; i++)
diff_free_filepair(q->queue[i]);
+free_queue:
free(q->queue);
q->queue = NULL;
q->nr = q->alloc = 0;
--
1.4.1.rc1.g8637
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] Print empty line between raw, stat, summary and patch
2006-06-27 12:09 [PATCH] Print empty line between raw, stat, summary and patch Timo Hirvonen
@ 2006-06-27 18:03 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2006-06-27 18:03 UTC (permalink / raw)
To: Timo Hirvonen; +Cc: git
Timo Hirvonen <tihirvon@gmail.com> writes:
> Signed-off-by: Timo Hirvonen <tihirvon@gmail.com>
> ---
>
> Should we print options->line_termination instead of \n between all
> fields?
I personally do not think it is a big deal since combination of
stat, summary and patch are primarily for human consumption, but
somebody might want to write a frontend GUI on top of this
output and having an easy way to seperate the parts for machine
consumption might be helpful.
> The old code didn't support as many combinations of raw,
> stat, summary and patch so I'm not 100% sure about this.
Think of it as an opportunity to come up with the most sensible
without having to worry about backward compatibility ;-) I'll
let you know what I think after I stare at its output for some
time.
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-06-27 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27 12:09 [PATCH] Print empty line between raw, stat, summary and patch Timo Hirvonen
2006-06-27 18:03 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).