diff --dirstat-by-file: count changed files, not lines
This new option --dirstat-by-file is the same as --dirstat, but it counts "impacted files" instead of "impacted lines" (lines that are added or removed). Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Heikki Orsila committed
Sep 5, 2008 at 22:27 UTC
fd33777b7871eefa440f89ccf7c432895af09c74
3 files changed
+13
-1
Documentation/diff-options.txt
+3
@@ -65,6 +65,9 @@ endif::git-format-patch[]
65
can be set with "--dirstat=limit". Changes in a child directory is not
66
counted for the parent directory, unless "--cumulative" is used.
67
68
+--dirstat-by-file[=limit]::
69
+ Same as --dirstat, but counts changed files instead of lines.
70
+
71
--summary::
72
Output a condensed summary of extended header information
73
such as creations, renames and mode changes.
diff.c
+9
-1
@@ -1110,9 +1110,13 @@ static void show_dirstat(struct diff_options *options)
1110
/*
1111
* Original minus copied is the removed material,
1112
* added is the new material. They are both damages
1113
- * made to the preimage.
1113
+ * made to the preimage. In --dirstat-by-file mode, count
1114
+ * damaged files, not damaged lines. This is done by
1115
+ * counting only a single damaged line per file.
1116
*/
1117
damage = (p->one->size - copied) + added;
1118
+ if (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)
1119
+ damage = 1;
1120
1121
ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
1122
dir.files[dir.nr].name = name;
@@ -2476,6 +2480,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
2480
else if (!strcmp(arg, "--cumulative")) {
2481
options->output_format |= DIFF_FORMAT_DIRSTAT;
2482
DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
2483
+ } else if (opt_arg(arg, 0, "dirstat-by-file",
2484
+ &options->dirstat_percent)) {
2485
+ options->output_format |= DIFF_FORMAT_DIRSTAT;
2486
+ DIFF_OPT_SET(options, DIRSTAT_BY_FILE);
2487
}
2488
else if (!strcmp(arg, "--check"))
2489
options->output_format |= DIFF_FORMAT_CHECKDIFF;
diff.h
+1
@@ -64,6 +64,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
64
#define DIFF_OPT_RELATIVE_NAME (1 << 17)
65
#define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
66
#define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
67
+#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
68
#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
69
#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
70
#define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)