Skip to content

Commit ddf88fa

Browse files
pcloudsgitster
authored andcommitted
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 0433d53: 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: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c905cbc commit ddf88fa

8 files changed

+83
-0
lines changed

Documentation/diff-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ have to use `--diff-algorithm=default` option.
128128
These parameters can also be set individually with `--stat-width=<width>`,
129129
`--stat-name-width=<name-width>` and `--stat-count=<count>`.
130130

131+
--compact-summary::
132+
Output a condensed summary of extended header information such
133+
as file creations or deletions ("new" or "gone", optionally "+l"
134+
if it's a symlink) and mode changes ("+x" or "-x" for adding
135+
or removing executable bit respectively) in diffstat. The
136+
information is put betwen the filename part and the graph
137+
part. Implies `--stat`.
138+
131139
--numstat::
132140
Similar to `--stat`, but shows number of added and
133141
deleted lines in decimal notation and pathname without

diff.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,7 @@ struct diffstat_t {
21292129
char *from_name;
21302130
char *name;
21312131
char *print_name;
2132+
const char *comments;
21322133
unsigned is_unmerged:1;
21332134
unsigned is_binary:1;
21342135
unsigned is_renamed:1;
@@ -2205,6 +2206,9 @@ static void fill_print_name(struct diffstat_file *file)
22052206
else
22062207
quote_c_style(file->name, &pname, NULL, 0);
22072208

2209+
if (file->comments)
2210+
strbuf_addf(&pname, " (%s)", file->comments);
2211+
22082212
file->print_name = strbuf_detach(&pname, NULL);
22092213
}
22102214

@@ -3239,6 +3243,32 @@ static void builtin_diff(const char *name_a,
32393243
return;
32403244
}
32413245

3246+
static char *get_compact_summary(const struct diff_filepair *p, int is_renamed)
3247+
{
3248+
if (!is_renamed) {
3249+
if (p->status == DIFF_STATUS_ADDED) {
3250+
if (S_ISLNK(p->two->mode))
3251+
return "new +l";
3252+
else if ((p->two->mode & 0777) == 0755)
3253+
return "new +x";
3254+
else
3255+
return "new";
3256+
} else if (p->status == DIFF_STATUS_DELETED)
3257+
return "gone";
3258+
}
3259+
if (S_ISLNK(p->one->mode) && !S_ISLNK(p->two->mode))
3260+
return "mode -l";
3261+
else if (!S_ISLNK(p->one->mode) && S_ISLNK(p->two->mode))
3262+
return "mode +l";
3263+
else if ((p->one->mode & 0777) == 0644 &&
3264+
(p->two->mode & 0777) == 0755)
3265+
return "mode +x";
3266+
else if ((p->one->mode & 0777) == 0755 &&
3267+
(p->two->mode & 0777) == 0644)
3268+
return "mode -x";
3269+
return NULL;
3270+
}
3271+
32423272
static void builtin_diffstat(const char *name_a, const char *name_b,
32433273
struct diff_filespec *one,
32443274
struct diff_filespec *two,
@@ -3258,6 +3288,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
32583288

32593289
data = diffstat_add(diffstat, name_a, name_b);
32603290
data->is_interesting = p->status != DIFF_STATUS_UNKNOWN;
3291+
if (o->flags.stat_with_summary)
3292+
data->comments = get_compact_summary(p, data->is_renamed);
32613293

32623294
if (!one || !two) {
32633295
data->is_unmerged = 1;
@@ -4528,6 +4560,11 @@ int diff_opt_parse(struct diff_options *options,
45284560
else if (starts_with(arg, "--stat"))
45294561
/* --stat, --stat-width, --stat-name-width, or --stat-count */
45304562
return stat_opt(options, av);
4563+
else if (!strcmp(arg, "--compact-summary")) {
4564+
options->flags.stat_with_summary = 1;
4565+
options->output_format |= DIFF_FORMAT_DIFFSTAT;
4566+
} else if (!strcmp(arg, "--no-compact-summary"))
4567+
options->flags.stat_with_summary = 0;
45314568

45324569
/* renames options */
45334570
else if (starts_with(arg, "-B") ||

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct diff_flags {
9393
unsigned funccontext:1;
9494
unsigned pickaxe_ignore_case:1;
9595
unsigned default_follow_renames:1;
96+
unsigned stat_with_summary:1;
9697
};
9798

9899
static inline void diff_flags_or(struct diff_flags *a,

t/t4013-diff-various.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ diff --no-index --raw dir2 dir
361361
diff --no-index --raw --abbrev=4 dir2 dir
362362
:noellipses diff --no-index --raw --abbrev=4 dir2 dir
363363
diff --no-index --raw --no-abbrev dir2 dir
364+
365+
diff-tree --pretty --root --stat --compact-summary initial
366+
diff-tree --pretty -R --root --stat --compact-summary initial
367+
diff-tree --stat --compact-summary initial mode
368+
diff-tree -R --stat --compact-summary initial mode
364369
EOF
365370

366371
test_expect_success 'log -S requires an argument' '
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$ git diff-tree --pretty --root --stat --compact-summary initial
2+
commit 444ac553ac7612cc88969031b02b3767fb8a353a
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:00:00 2006 +0000
5+
6+
Initial
7+
8+
dir/sub (new) | 2 ++
9+
file0 (new) | 3 +++
10+
file2 (new) | 3 +++
11+
3 files changed, 8 insertions(+)
12+
$
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$ git diff-tree --pretty -R --root --stat --compact-summary initial
2+
commit 444ac553ac7612cc88969031b02b3767fb8a353a
3+
Author: A U Thor <[email protected]>
4+
Date: Mon Jun 26 00:00:00 2006 +0000
5+
6+
Initial
7+
8+
dir/sub (gone) | 2 --
9+
file0 (gone) | 3 ---
10+
file2 (gone) | 3 ---
11+
3 files changed, 8 deletions(-)
12+
$
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$ git diff-tree --stat --compact-summary initial mode
2+
file0 (mode +x) | 0
3+
1 file changed, 0 insertions(+), 0 deletions(-)
4+
$
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$ git diff-tree -R --stat --compact-summary initial mode
2+
file0 (mode -x) | 0
3+
1 file changed, 0 insertions(+), 0 deletions(-)
4+
$

0 commit comments

Comments
 (0)