Git fork

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 0433d533f1:

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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Nguyễn Thái Ngọc Duy and committed by
Junio C Hamano
ddf88fa6 c905cbc4

+83
+8
Documentation/diff-options.txt
··· 128 128 These parameters can also be set individually with `--stat-width=<width>`, 129 129 `--stat-name-width=<name-width>` and `--stat-count=<count>`. 130 130 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 + 131 139 --numstat:: 132 140 Similar to `--stat`, but shows number of added and 133 141 deleted lines in decimal notation and pathname without
+37
diff.c
··· 2129 2129 char *from_name; 2130 2130 char *name; 2131 2131 char *print_name; 2132 + const char *comments; 2132 2133 unsigned is_unmerged:1; 2133 2134 unsigned is_binary:1; 2134 2135 unsigned is_renamed:1; ··· 2204 2205 pprint_rename(&pname, file->from_name, file->name); 2205 2206 else 2206 2207 quote_c_style(file->name, &pname, NULL, 0); 2208 + 2209 + if (file->comments) 2210 + strbuf_addf(&pname, " (%s)", file->comments); 2207 2211 2208 2212 file->print_name = strbuf_detach(&pname, NULL); 2209 2213 } ··· 3239 3243 return; 3240 3244 } 3241 3245 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 + 3242 3272 static void builtin_diffstat(const char *name_a, const char *name_b, 3243 3273 struct diff_filespec *one, 3244 3274 struct diff_filespec *two, ··· 3258 3288 3259 3289 data = diffstat_add(diffstat, name_a, name_b); 3260 3290 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); 3261 3293 3262 3294 if (!one || !two) { 3263 3295 data->is_unmerged = 1; ··· 4528 4560 else if (starts_with(arg, "--stat")) 4529 4561 /* --stat, --stat-width, --stat-name-width, or --stat-count */ 4530 4562 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; 4531 4568 4532 4569 /* renames options */ 4533 4570 else if (starts_with(arg, "-B") ||
+1
diff.h
··· 93 93 unsigned funccontext:1; 94 94 unsigned pickaxe_ignore_case:1; 95 95 unsigned default_follow_renames:1; 96 + unsigned stat_with_summary:1; 96 97 }; 97 98 98 99 static inline void diff_flags_or(struct diff_flags *a,
+5
t/t4013-diff-various.sh
··· 361 361 diff --no-index --raw --abbrev=4 dir2 dir 362 362 :noellipses diff --no-index --raw --abbrev=4 dir2 dir 363 363 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 364 369 EOF 365 370 366 371 test_expect_success 'log -S requires an argument' '
+12
t/t4013/diff.diff-tree_--pretty_--root_--stat_--compact-summary_initial
··· 1 + $ git diff-tree --pretty --root --stat --compact-summary initial 2 + commit 444ac553ac7612cc88969031b02b3767fb8a353a 3 + Author: A U Thor <author@example.com> 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 + $
+12
t/t4013/diff.diff-tree_--pretty_-R_--root_--stat_--compact-summary_initial
··· 1 + $ git diff-tree --pretty -R --root --stat --compact-summary initial 2 + commit 444ac553ac7612cc88969031b02b3767fb8a353a 3 + Author: A U Thor <author@example.com> 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 + $
+4
t/t4013/diff.diff-tree_--stat_--compact-summary_initial_mode
··· 1 + $ git diff-tree --stat --compact-summary initial mode 2 + file0 (mode +x) | 0 3 + 1 file changed, 0 insertions(+), 0 deletions(-) 4 + $
+4
t/t4013/diff.diff-tree_-R_--stat_--compact-summary_initial_mode
··· 1 + $ git diff-tree -R --stat --compact-summary initial mode 2 + file0 (mode -x) | 0 3 + 1 file changed, 0 insertions(+), 0 deletions(-) 4 + $