Re: [PATCH] make commit message a little more consistent and conforting
flat view
From: Nicolas Pitre <hidden>
Date: 2016-08-11 19:36:40
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
Possibly related (same subject, not in this thread)
- 2016-08-11 · Re: [PATCH] make commit message a little more consistent and conforting · Junio C Hamano <hidden>
- 2016-08-11 · Re: [PATCH] make commit message a little more consistent and conforting · Junio C Hamano <hidden>
On Fri, 15 Dec 2006, Junio C Hamano wrote:
Nicolas Pitre [off-list ref] writes:quoted
So in short I do think there should be something shown after a successful commit, and including the commit sha1 doesn't hurt. ... And it is true that diffstat can be quite large. I wouldn't mind the diffstat to be added to the commit message summary in the text editor though. And displaying it when -v is used makes also a lot of sense. But not by default please.I agree with everything you said in your message, including that commit object name might help as a learning aid. We could give something like this, though, if we wanted to: $ git commit 4 files changed, 17 insertions(+), 10 deletions(-) mode change 100755 => 100644 test.sh
Actually that would really be nice to have all the time for the diff --summary output whenever --stat is not provided. Or maybe a --shortstat option. What about this (on top of my previous patch): Signed-off-by: Nicolas Pitre <redacted> ---
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 9cdd171..f12082e 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt@@ -21,6 +21,11 @@ deleted lines in decimal notation and pathname without abbreviation, to make it more machine friendly. +--shortstat:: + Output only the last line of the --stat format containing total + number of modified files, as well as number of added and deleted + lines. + --summary:: Output a condensed summary of extended header information such as creations, renames and mode changes.
diff --git a/diff.c b/diff.c
index 0b284b3..d754280 100644
--- a/diff.c
+++ b/diff.c@@ -809,6 +809,35 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options) set, total_files, adds, dels, reset); } +static void show_shortstats(struct diffstat_t* data) +{ + int i, adds = 0, dels = 0, total_files = data->nr; + + if (data->nr == 0) + return; + + for (i = 0; i < data->nr; i++) { + if (!data->files[i]->is_binary && + !data->files[i]->is_unmerged) { + int added = data->files[i]->added; + int deleted= data->files[i]->deleted; + if (!data->files[i]->is_renamed && + (added + deleted == 0)) { + total_files--; + } else { + adds += added; + dels += deleted; + } + } + free(data->files[i]->name); + free(data->files[i]); + } + free(data->files); + + printf(" %d files changed, %d insertions(+), %d deletions(-)\n", + total_files, adds, dels); +} + static void show_numstat(struct diffstat_t* data, struct diff_options *options) { int i;
@@ -1767,6 +1796,7 @@ int diff_setup_done(struct diff_options *options) options->output_format &= ~(DIFF_FORMAT_RAW | DIFF_FORMAT_NUMSTAT | DIFF_FORMAT_DIFFSTAT | + DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH);
@@ -1777,6 +1807,7 @@ int diff_setup_done(struct diff_options *options) if (options->output_format & (DIFF_FORMAT_PATCH | DIFF_FORMAT_NUMSTAT | DIFF_FORMAT_DIFFSTAT | + DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_CHECKDIFF)) options->recursive = 1;
@@ -1868,6 +1899,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) else if (!strcmp(arg, "--numstat")) { options->output_format |= DIFF_FORMAT_NUMSTAT; } + else if (!strcmp(arg, "--shortstat")) { + options->output_format |= DIFF_FORMAT_SHORTSTAT; + } else if (!strncmp(arg, "--stat", 6)) { char *end; int width = options->stat_width;
@@ -2642,7 +2676,7 @@ void diff_flush(struct diff_options *options) separator++; } - if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_NUMSTAT)) { + if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT)) { struct diffstat_t diffstat; memset(&diffstat, 0, sizeof(struct diffstat_t));
@@ -2656,6 +2690,8 @@ void diff_flush(struct diff_options *options) show_numstat(&diffstat, options); if (output_format & DIFF_FORMAT_DIFFSTAT) show_stats(&diffstat, options); + else if (output_format & DIFF_FORMAT_SHORTSTAT) + show_shortstats(&diffstat); separator++; }
diff --git a/diff.h b/diff.h
index 101b2b5..eff4455 100644
--- a/diff.h
+++ b/diff.h@@ -29,6 +29,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, #define DIFF_FORMAT_NUMSTAT 0x0004 #define DIFF_FORMAT_SUMMARY 0x0008 #define DIFF_FORMAT_PATCH 0x0010 +#define DIFF_FORMAT_SHORTSTAT 0x0020 /* These override all above */ #define DIFF_FORMAT_NAME 0x0100
diff --git a/git-commit.sh b/git-commit.sh
index 395bcd2..b9e49ea 100755
--- a/git-commit.sh
+++ b/git-commit.sh@@ -629,7 +629,7 @@ then if test -z "$quiet" then echo "Created${initial_commit:+ initial} commit $commit" - git-diff-tree --summary --root --no-commit-id HEAD + git-diff-tree --shortstat --summary --root --no-commit-id HEAD fi fi