From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Frederik Schwarzer" <schwarzerf@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] Correct singular form in diff summary line for human interaction
Date: Tue, 31 Jan 2012 21:24:00 +0700 [thread overview]
Message-ID: <1328019840-6168-1-git-send-email-pclouds@gmail.com> (raw)
"git diff --stat" and "git apply --stat" now learn to print the line
"%d files changed, %d insertions(+), %d deletions(-)" in singular form
whenever applicable.
This change uncondtionally would upset scripts because scripts are not
nice. They simply hate changes. They can be very hostile when that
happens. So only adjust the line for human consumption.
Convenient function interactive_use() is added for this purpose. The
command thinks it's in human hands when:
- GIT_SCRIPTING environment variable is not set
- pager is on or
- both stdout and stderr point to tty device
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
The third attempt in the last couple months to remove three "s" in
one line. I did not upset the test suite with this and hopefully
won't upset any scripts around. Good start?
builtin/apply.c | 3 ++-
cache.h | 1 +
diff.c | 33 ++++++++++++++++++++++++++++-----
diff.h | 3 +++
| 7 +++++++
5 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index c24dc54..389898f 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -14,6 +14,7 @@
#include "builtin.h"
#include "string-list.h"
#include "dir.h"
+#include "diff.h"
#include "parse-options.h"
/*
@@ -3241,7 +3242,7 @@ static void stat_patch_list(struct patch *patch)
show_stats(patch);
}
- printf(" %d files changed, %d insertions(+), %d deletions(-)\n", files, adds, dels);
+ print_stat_summary(stdout, files, adds, dels);
}
static void numstat_patch_list(struct patch *patch)
diff --git a/cache.h b/cache.h
index 10afd71..7e0bb2b 100644
--- a/cache.h
+++ b/cache.h
@@ -1175,6 +1175,7 @@ extern void setup_pager(void);
extern const char *pager_program;
extern int pager_in_use(void);
extern int pager_use_color;
+extern int interactive_use(void);
extern const char *editor_program;
extern const char *askpass_program;
diff --git a/diff.c b/diff.c
index 7e15426..2d63e9c 100644
--- a/diff.c
+++ b/diff.c
@@ -1322,6 +1322,32 @@ static void fill_print_name(struct diffstat_file *file)
file->print_name = pname;
}
+int print_stat_summary(FILE *fp, int files, int insertions, int deletions)
+{
+ struct strbuf sb = STRBUF_INIT;
+ int ret;
+
+ if (!interactive_use())
+ return fprintf(fp, " %d files changed, %d insertions(+), %d deletions(-)\n",
+ files, insertions, deletions);
+
+ strbuf_addf(&sb,
+ ngettext(" %d file changed,", " %d files changed,",
+ files),
+ files);
+ strbuf_addf(&sb,
+ ngettext(" %d insertion(+),", " %d insertions(+),",
+ insertions),
+ insertions);
+ strbuf_addf(&sb,
+ ngettext(" %d deletion(-)\n", " %d deletions(-)\n",
+ deletions),
+ deletions);
+ ret = fputs(sb.buf, fp);
+ strbuf_release(&sb);
+ return ret;
+}
+
static void show_stats(struct diffstat_t *data, struct diff_options *options)
{
int i, len, add, del, adds = 0, dels = 0;
@@ -1475,9 +1501,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
extra_shown = 1;
}
fprintf(options->file, "%s", line_prefix);
- fprintf(options->file,
- " %d files changed, %d insertions(+), %d deletions(-)\n",
- total_files, adds, dels);
+ print_stat_summary(options->file, total_files, adds, dels);
}
static void show_shortstats(struct diffstat_t *data, struct diff_options *options)
@@ -1507,8 +1531,7 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option
options->output_prefix_data);
fprintf(options->file, "%s", msg->buf);
}
- fprintf(options->file, " %d files changed, %d insertions(+), %d deletions(-)\n",
- total_files, adds, dels);
+ print_stat_summary(options->file, total_files, adds, dels);
}
static void show_numstat(struct diffstat_t *data, struct diff_options *options)
diff --git a/diff.h b/diff.h
index ae71f4c..7af5f1e 100644
--- a/diff.h
+++ b/diff.h
@@ -324,4 +324,7 @@ extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
extern int parse_rename_score(const char **cp_p);
+extern int print_stat_summary(FILE *fp, int files,
+ int insertions, int deletions);
+
#endif /* DIFF_H */
--git a/pager.c b/pager.c
index 975955b..9a3d3d8 100644
--- a/pager.c
+++ b/pager.c
@@ -110,3 +110,10 @@ int pager_in_use(void)
env = getenv("GIT_PAGER_IN_USE");
return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
}
+
+int interactive_use(void)
+{
+ const char *env;
+ env = getenv("GIT_SCRIPTING");
+ return !env && (pager_in_use() || (isatty(1) && isatty(2)));
+}
--
1.7.8.36.g69ee2
next reply other threads:[~2012-01-31 14:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-31 14:24 Nguyễn Thái Ngọc Duy [this message]
2012-01-31 15:20 ` [PATCH] Correct singular form in diff summary line for human interaction Jonathan Nieder
2012-01-31 17:50 ` Junio C Hamano
2012-02-01 1:32 ` Nguyen Thai Ngoc Duy
2012-02-01 1:45 ` Thomas Dickey
2012-02-01 1:56 ` Thomas Dickey
2012-02-01 2:37 ` Nguyen Thai Ngoc Duy
2012-02-01 3:04 ` Junio C Hamano
2012-02-01 9:40 ` Thomas Dickey
2012-02-01 12:55 ` [PATCH v2] Use correct grammar in diffstat summary line Nguyễn Thái Ngọc Duy
2012-02-01 21:26 ` Junio C Hamano
2012-02-02 14:22 ` Nguyen Thai Ngoc Duy
2012-02-02 18:24 ` Junio C Hamano
2012-02-03 1:11 ` Nguyen Thai Ngoc Duy
2012-02-03 1:18 ` Junio C Hamano
2012-02-03 12:24 ` Jeff King
2012-02-01 23:35 ` Jonathan Nieder
2012-02-02 0:20 ` [RFC/PATCH] i18n: do not define gettext/ngettext in NO_GETTEXT case Jonathan Nieder
2012-02-02 0:27 ` [PATCH v2] Use correct grammar in diffstat summary line Jonathan Nieder
2012-02-02 0:31 ` Jonathan Nieder
2012-03-13 4:51 ` [RFC/PATCH 0/7] tests: diffstat summary line varies by locale (Re: [PATCH v2] Use correct grammar in diffstat summary line) Jonathan Nieder
2012-03-13 4:54 ` [PATCH 1/7] test: use test_i18ncmp when checking --stat output Jonathan Nieder
2012-03-13 6:00 ` Junio C Hamano
2012-03-13 6:05 ` Junio C Hamano
2012-03-13 6:13 ` Jonathan Nieder
2012-03-13 6:06 ` Jonathan Nieder
2012-03-13 4:58 ` [PATCH 2/7] test: use numstat instead of diffstat in funny-names test Jonathan Nieder
2012-03-13 4:59 ` [PATCH 3/7] test: modernize funny-names test style Jonathan Nieder
2012-03-13 5:00 ` [PATCH 4/7] test: test cherry-pick functionality and output separately Jonathan Nieder
2012-03-13 5:01 ` [PATCH 5/7] test: use --numstat instead of --stat in "git stash show" tests Jonathan Nieder
2012-03-13 5:02 ` [PATCH 6/7] test: use numstat instead of diffstat in binary-diff test Jonathan Nieder
2012-03-13 5:05 ` [PATCH 7/7] diffstat summary line varies by locale: miscellany Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328019840-6168-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=schwarzerf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).