Merge branch 'nd/diff-stat-with-summary'
"git diff" and friends learned "--compact-summary" that shows the information usually given with the "--summary" option on the same line as the diffstat output of the "--stat" option (which saves vertical space and keeps info on a single path at the same place). * nd/diff-stat-with-summary: diff: add --compact-summary diff.c: refactor pprint_rename() to use strbuf
This commit is contained in:
commit
868f7d2338
@ -128,6 +128,14 @@ have to use `--diff-algorithm=default` option.
|
||||
These parameters can also be set individually with `--stat-width=<width>`,
|
||||
`--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::
|
||||
Similar to `--stat`, but shows number of added and
|
||||
deleted lines in decimal notation and pathname without
|
||||
|
96
diff.c
96
diff.c
@ -2045,11 +2045,10 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
|
||||
}
|
||||
}
|
||||
|
||||
static char *pprint_rename(const char *a, const char *b)
|
||||
static void pprint_rename(struct strbuf *name, const char *a, const char *b)
|
||||
{
|
||||
const char *old_name = a;
|
||||
const char *new_name = b;
|
||||
struct strbuf name = STRBUF_INIT;
|
||||
int pfx_length, sfx_length;
|
||||
int pfx_adjust_for_slash;
|
||||
int len_a = strlen(a);
|
||||
@ -2059,10 +2058,10 @@ static char *pprint_rename(const char *a, const char *b)
|
||||
int qlen_b = quote_c_style(b, NULL, NULL, 0);
|
||||
|
||||
if (qlen_a || qlen_b) {
|
||||
quote_c_style(a, &name, NULL, 0);
|
||||
strbuf_addstr(&name, " => ");
|
||||
quote_c_style(b, &name, NULL, 0);
|
||||
return strbuf_detach(&name, NULL);
|
||||
quote_c_style(a, name, NULL, 0);
|
||||
strbuf_addstr(name, " => ");
|
||||
quote_c_style(b, name, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Find common prefix */
|
||||
@ -2109,19 +2108,18 @@ static char *pprint_rename(const char *a, const char *b)
|
||||
if (b_midlen < 0)
|
||||
b_midlen = 0;
|
||||
|
||||
strbuf_grow(&name, pfx_length + a_midlen + b_midlen + sfx_length + 7);
|
||||
strbuf_grow(name, pfx_length + a_midlen + b_midlen + sfx_length + 7);
|
||||
if (pfx_length + sfx_length) {
|
||||
strbuf_add(&name, a, pfx_length);
|
||||
strbuf_addch(&name, '{');
|
||||
strbuf_add(name, a, pfx_length);
|
||||
strbuf_addch(name, '{');
|
||||
}
|
||||
strbuf_add(&name, a + pfx_length, a_midlen);
|
||||
strbuf_addstr(&name, " => ");
|
||||
strbuf_add(&name, b + pfx_length, b_midlen);
|
||||
strbuf_add(name, a + pfx_length, a_midlen);
|
||||
strbuf_addstr(name, " => ");
|
||||
strbuf_add(name, b + pfx_length, b_midlen);
|
||||
if (pfx_length + sfx_length) {
|
||||
strbuf_addch(&name, '}');
|
||||
strbuf_add(&name, a + len_a - sfx_length, sfx_length);
|
||||
strbuf_addch(name, '}');
|
||||
strbuf_add(name, a + len_a - sfx_length, sfx_length);
|
||||
}
|
||||
return strbuf_detach(&name, NULL);
|
||||
}
|
||||
|
||||
struct diffstat_t {
|
||||
@ -2131,6 +2129,7 @@ struct diffstat_t {
|
||||
char *from_name;
|
||||
char *name;
|
||||
char *print_name;
|
||||
const char *comments;
|
||||
unsigned is_unmerged:1;
|
||||
unsigned is_binary:1;
|
||||
unsigned is_renamed:1;
|
||||
@ -2197,23 +2196,20 @@ static void show_graph(struct strbuf *out, char ch, int cnt,
|
||||
|
||||
static void fill_print_name(struct diffstat_file *file)
|
||||
{
|
||||
char *pname;
|
||||
struct strbuf pname = STRBUF_INIT;
|
||||
|
||||
if (file->print_name)
|
||||
return;
|
||||
|
||||
if (!file->is_renamed) {
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
if (quote_c_style(file->name, &buf, NULL, 0)) {
|
||||
pname = strbuf_detach(&buf, NULL);
|
||||
} else {
|
||||
pname = file->name;
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
} else {
|
||||
pname = pprint_rename(file->from_name, file->name);
|
||||
}
|
||||
file->print_name = pname;
|
||||
if (file->is_renamed)
|
||||
pprint_rename(&pname, file->from_name, file->name);
|
||||
else
|
||||
quote_c_style(file->name, &pname, NULL, 0);
|
||||
|
||||
if (file->comments)
|
||||
strbuf_addf(&pname, " (%s)", file->comments);
|
||||
|
||||
file->print_name = strbuf_detach(&pname, NULL);
|
||||
}
|
||||
|
||||
static void print_stat_summary_inserts_deletes(struct diff_options *options,
|
||||
@ -2797,8 +2793,7 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
|
||||
int i;
|
||||
for (i = 0; i < diffstat->nr; i++) {
|
||||
struct diffstat_file *f = diffstat->files[i];
|
||||
if (f->name != f->print_name)
|
||||
free(f->print_name);
|
||||
free(f->print_name);
|
||||
free(f->name);
|
||||
free(f->from_name);
|
||||
free(f);
|
||||
@ -3248,6 +3243,32 @@ static void builtin_diff(const char *name_a,
|
||||
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,
|
||||
struct diff_filespec *one,
|
||||
struct diff_filespec *two,
|
||||
@ -3267,6 +3288,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
|
||||
|
||||
data = diffstat_add(diffstat, name_a, name_b);
|
||||
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) {
|
||||
data->is_unmerged = 1;
|
||||
@ -4553,6 +4576,11 @@ int diff_opt_parse(struct diff_options *options,
|
||||
else if (starts_with(arg, "--stat"))
|
||||
/* --stat, --stat-width, --stat-name-width, or --stat-count */
|
||||
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 */
|
||||
else if (starts_with(arg, "-B") ||
|
||||
@ -5241,10 +5269,12 @@ static void show_rename_copy(struct diff_options *opt, const char *renamecopy,
|
||||
struct diff_filepair *p)
|
||||
{
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
char *names = pprint_rename(p->one->path, p->two->path);
|
||||
struct strbuf names = STRBUF_INIT;
|
||||
|
||||
pprint_rename(&names, p->one->path, p->two->path);
|
||||
strbuf_addf(&sb, " %s %s (%d%%)\n",
|
||||
renamecopy, names, similarity_index(p));
|
||||
free(names);
|
||||
renamecopy, names.buf, similarity_index(p));
|
||||
strbuf_release(&names);
|
||||
emit_diff_symbol(opt, DIFF_SYMBOL_SUMMARY,
|
||||
sb.buf, sb.len, 0);
|
||||
show_mode_change(opt, p, 0);
|
||||
|
1
diff.h
1
diff.h
@ -93,6 +93,7 @@ struct diff_flags {
|
||||
unsigned dirstat_by_line:1;
|
||||
unsigned funccontext:1;
|
||||
unsigned default_follow_renames:1;
|
||||
unsigned stat_with_summary:1;
|
||||
};
|
||||
|
||||
static inline void diff_flags_or(struct diff_flags *a,
|
||||
|
@ -361,6 +361,11 @@ diff --no-index --raw dir2 dir
|
||||
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-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
|
||||
|
||||
test_expect_success 'log -S requires an argument' '
|
||||
|
@ -0,0 +1,12 @@
|
||||
$ 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(+)
|
||||
$
|
@ -0,0 +1,12 @@
|
||||
$ 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(-)
|
||||
$
|
@ -0,0 +1,4 @@
|
||||
$ git diff-tree --stat --compact-summary initial mode
|
||||
file0 (mode +x) | 0
|
||||
1 file changed, 0 insertions(+), 0 deletions(-)
|
||||
$
|
@ -0,0 +1,4 @@
|
||||
$ git diff-tree -R --stat --compact-summary initial mode
|
||||
file0 (mode -x) | 0
|
||||
1 file changed, 0 insertions(+), 0 deletions(-)
|
||||
$
|
Loading…
Reference in New Issue
Block a user