提交 ddf88fa6 编写于 作者: N Nguyễn Thái Ngọc Duy 提交者: Junio C Hamano

diff: add --compact-summary

Certain information is currently shown with --summary, but when used
in combination with --stat it's a bit hard to read since info of the
same file is in two places (--stat and --summary).

On top of that, commits that add or remove files double the number of
display lines, which could be a lot if you add or remove a lot of
files.

--compact-summary embeds most of --summary back in --stat in the
little space between the file name part and the graph line, e.g. with
commit 0433d533:

   Documentation/merge-config.txt         |  4 +
   builtin/merge.c                        |  2 +
   ...-pull-verify-signatures.sh (new +x) | 81 ++++++++++++++
   t/t7612-merge-verify-signatures.sh     | 45 ++++++++
   4 files changed, 132 insertions(+)

It helps both condensing information and saving some text
space. What's new in diffstat is:

- A new 0644 file is shown as (new)
- A new 0755 file is shown as (new +x)
- A new symlink is shown as (new +l)
- A deleted file is shown as (gone)
- A mode change adding executable bit is shown as (mode +x)
- A mode change removing it is shown as (mode -x)

Note that --compact-summary does not contain all the information
--summary provides. Rewrite percentage is not shown but it could be
added later, like R50% or C20%.
Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c905cbc4
...@@ -128,6 +128,14 @@ have to use `--diff-algorithm=default` option. ...@@ -128,6 +128,14 @@ have to use `--diff-algorithm=default` option.
These parameters can also be set individually with `--stat-width=<width>`, These parameters can also be set individually with `--stat-width=<width>`,
`--stat-name-width=<name-width>` and `--stat-count=<count>`. `--stat-name-width=<name-width>` and `--stat-count=<count>`.
--compact-summary::
Output a condensed summary of extended header information such
as file creations or deletions ("new" or "gone", optionally "+l"
if it's a symlink) and mode changes ("+x" or "-x" for adding
or removing executable bit respectively) in diffstat. The
information is put betwen the filename part and the graph
part. Implies `--stat`.
--numstat:: --numstat::
Similar to `--stat`, but shows number of added and Similar to `--stat`, but shows number of added and
deleted lines in decimal notation and pathname without deleted lines in decimal notation and pathname without
......
...@@ -2129,6 +2129,7 @@ struct diffstat_t { ...@@ -2129,6 +2129,7 @@ struct diffstat_t {
char *from_name; char *from_name;
char *name; char *name;
char *print_name; char *print_name;
const char *comments;
unsigned is_unmerged:1; unsigned is_unmerged:1;
unsigned is_binary:1; unsigned is_binary:1;
unsigned is_renamed:1; unsigned is_renamed:1;
...@@ -2205,6 +2206,9 @@ static void fill_print_name(struct diffstat_file *file) ...@@ -2205,6 +2206,9 @@ static void fill_print_name(struct diffstat_file *file)
else else
quote_c_style(file->name, &pname, NULL, 0); quote_c_style(file->name, &pname, NULL, 0);
if (file->comments)
strbuf_addf(&pname, " (%s)", file->comments);
file->print_name = strbuf_detach(&pname, NULL); file->print_name = strbuf_detach(&pname, NULL);
} }
...@@ -3239,6 +3243,32 @@ static void builtin_diff(const char *name_a, ...@@ -3239,6 +3243,32 @@ static void builtin_diff(const char *name_a,
return; return;
} }
static char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
{
if (!is_renamed) {
if (p->status == DIFF_STATUS_ADDED) {
if (S_ISLNK(p->two->mode))
return "new +l";
else if ((p->two->mode & 0777) == 0755)
return "new +x";
else
return "new";
} else if (p->status == DIFF_STATUS_DELETED)
return "gone";
}
if (S_ISLNK(p->one->mode) && !S_ISLNK(p->two->mode))
return "mode -l";
else if (!S_ISLNK(p->one->mode) && S_ISLNK(p->two->mode))
return "mode +l";
else if ((p->one->mode & 0777) == 0644 &&
(p->two->mode & 0777) == 0755)
return "mode +x";
else if ((p->one->mode & 0777) == 0755 &&
(p->two->mode & 0777) == 0644)
return "mode -x";
return NULL;
}
static void builtin_diffstat(const char *name_a, const char *name_b, static void builtin_diffstat(const char *name_a, const char *name_b,
struct diff_filespec *one, struct diff_filespec *one,
struct diff_filespec *two, struct diff_filespec *two,
...@@ -3258,6 +3288,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b, ...@@ -3258,6 +3288,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
data = diffstat_add(diffstat, name_a, name_b); data = diffstat_add(diffstat, name_a, name_b);
data->is_interesting = p->status != DIFF_STATUS_UNKNOWN; data->is_interesting = p->status != DIFF_STATUS_UNKNOWN;
if (o->flags.stat_with_summary)
data->comments = get_compact_summary(p, data->is_renamed);
if (!one || !two) { if (!one || !two) {
data->is_unmerged = 1; data->is_unmerged = 1;
...@@ -4528,6 +4560,11 @@ int diff_opt_parse(struct diff_options *options, ...@@ -4528,6 +4560,11 @@ int diff_opt_parse(struct diff_options *options,
else if (starts_with(arg, "--stat")) else if (starts_with(arg, "--stat"))
/* --stat, --stat-width, --stat-name-width, or --stat-count */ /* --stat, --stat-width, --stat-name-width, or --stat-count */
return stat_opt(options, av); return stat_opt(options, av);
else if (!strcmp(arg, "--compact-summary")) {
options->flags.stat_with_summary = 1;
options->output_format |= DIFF_FORMAT_DIFFSTAT;
} else if (!strcmp(arg, "--no-compact-summary"))
options->flags.stat_with_summary = 0;
/* renames options */ /* renames options */
else if (starts_with(arg, "-B") || else if (starts_with(arg, "-B") ||
......
...@@ -93,6 +93,7 @@ struct diff_flags { ...@@ -93,6 +93,7 @@ struct diff_flags {
unsigned funccontext:1; unsigned funccontext:1;
unsigned pickaxe_ignore_case:1; unsigned pickaxe_ignore_case:1;
unsigned default_follow_renames:1; unsigned default_follow_renames:1;
unsigned stat_with_summary:1;
}; };
static inline void diff_flags_or(struct diff_flags *a, static inline void diff_flags_or(struct diff_flags *a,
......
...@@ -361,6 +361,11 @@ diff --no-index --raw dir2 dir ...@@ -361,6 +361,11 @@ diff --no-index --raw dir2 dir
diff --no-index --raw --abbrev=4 dir2 dir diff --no-index --raw --abbrev=4 dir2 dir
:noellipses diff --no-index --raw --abbrev=4 dir2 dir :noellipses diff --no-index --raw --abbrev=4 dir2 dir
diff --no-index --raw --no-abbrev dir2 dir diff --no-index --raw --no-abbrev dir2 dir
diff-tree --pretty --root --stat --compact-summary initial
diff-tree --pretty -R --root --stat --compact-summary initial
diff-tree --stat --compact-summary initial mode
diff-tree -R --stat --compact-summary initial mode
EOF EOF
test_expect_success 'log -S requires an argument' ' test_expect_success 'log -S requires an argument' '
......
$ git diff-tree --pretty --root --stat --compact-summary initial
commit 444ac553ac7612cc88969031b02b3767fb8a353a
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:00:00 2006 +0000
Initial
dir/sub (new) | 2 ++
file0 (new) | 3 +++
file2 (new) | 3 +++
3 files changed, 8 insertions(+)
$
$ git diff-tree --pretty -R --root --stat --compact-summary initial
commit 444ac553ac7612cc88969031b02b3767fb8a353a
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:00:00 2006 +0000
Initial
dir/sub (gone) | 2 --
file0 (gone) | 3 ---
file2 (gone) | 3 ---
3 files changed, 8 deletions(-)
$
$ git diff-tree --stat --compact-summary initial mode
file0 (mode +x) | 0
1 file changed, 0 insertions(+), 0 deletions(-)
$
$ git diff-tree -R --stat --compact-summary initial mode
file0 (mode -x) | 0
1 file changed, 0 insertions(+), 0 deletions(-)
$
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册