aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/diff-options.txt4
-rw-r--r--diff.c19
-rwxr-xr-xt/t4013-diff-various.sh2
-rw-r--r--t/t4013/diff.diff_--dirstat_initial_rearrange1
4 files changed, 21 insertions, 5 deletions
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 23772d615..7e4bd425e 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -74,8 +74,8 @@ endif::git-format-patch[]
counted for the parent directory, unless `--cumulative` is used.
+
Note that the `--dirstat` option computes the changes while ignoring
-pure code movements within a file. In other words, rearranging lines
-in a file is not counted as a change.
+the amount of pure code movements within a file. In other words,
+rearranging lines in a file is not counted as much as other changes.
--dirstat-by-file[=<limit>]::
Same as `--dirstat`, but counts changed files instead of lines.
diff --git a/diff.c b/diff.c
index 4f5270b8d..1f44cb423 100644
--- a/diff.c
+++ b/diff.c
@@ -1548,6 +1548,16 @@ static void show_dirstat(struct diff_options *options)
else
content_changed = 1;
+ if (!content_changed) {
+ /*
+ * The SHA1 has not changed, so pre-/post-content is
+ * identical. We can therefore skip looking at the
+ * file contents altogether.
+ */
+ damage = 0;
+ goto found_damage;
+ }
+
if (DIFF_OPT_TST(options, DIRSTAT_BY_FILE)) {
/*
* In --dirstat-by-file mode, we don't really need to
@@ -1556,7 +1566,7 @@ static void show_dirstat(struct diff_options *options)
* add this file to the list of results
* (with each file contributing equal damage).
*/
- damage = content_changed ? 1 : 0;
+ damage = 1;
goto found_damage;
}
@@ -1583,8 +1593,15 @@ static void show_dirstat(struct diff_options *options)
* Original minus copied is the removed material,
* added is the new material. They are both damages
* made to the preimage.
+ * If the resulting damage is zero, we know that
+ * diffcore_count_changes() considers the two entries to
+ * be identical, but since content_changed is true, we
+ * know that there must have been _some_ kind of change,
+ * so we force all entries to have damage > 0.
*/
damage = (p->one->size - copied) + added;
+ if (!damage)
+ damage = 1;
found_damage:
ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 6428a905a..93a6f2087 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -300,9 +300,7 @@ diff --no-index --name-status -- dir2 dir
diff --no-index dir dir3
diff master master^ side
diff --dirstat master~1 master~2
-# --dirstat doesn't notice changes that simply rearrange existing lines
diff --dirstat initial rearrange
-# ...but --dirstat-by-file does notice changes that only rearrange lines
diff --dirstat-by-file initial rearrange
EOF
diff --git a/t/t4013/diff.diff_--dirstat_initial_rearrange b/t/t4013/diff.diff_--dirstat_initial_rearrange
index fb2e17dd2..5fb02c13b 100644
--- a/t/t4013/diff.diff_--dirstat_initial_rearrange
+++ b/t/t4013/diff.diff_--dirstat_initial_rearrange
@@ -1,2 +1,3 @@
$ git diff --dirstat initial rearrange
+ 100.0% dir/
$