aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-04 14:59:07 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-04 14:59:07 -0700
commitf5bf1b5f6b43f5ed9263f4cecd0faf58c5a7322f (patch)
tree974ffecbcfaa90e90a2d72ee98bcc11cf694723f /diff.c
parent419272d87b7a611ea55736c284df9615d22ec6af (diff)
parent2ca86714703f81f9dd5dfb31f8d97a8a0089634d (diff)
downloadgit-f5bf1b5f6b43f5ed9263f4cecd0faf58c5a7322f.tar.gz
git-f5bf1b5f6b43f5ed9263f4cecd0faf58c5a7322f.tar.xz
Merge branch 'jh/dirstat' into maint
* jh/dirstat: --dirstat: In case of renames, use target filename instead of source filename Teach --dirstat not to completely ignore rearranged lines within a file --dirstat-by-file: Make it faster and more correct --dirstat: Describe non-obvious differences relative to --stat or regular diff
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/diff.c b/diff.c
index 9fa841010..5376d01e1 100644
--- a/diff.c
+++ b/diff.c
@@ -1538,8 +1538,36 @@ static void show_dirstat(struct diff_options *options)
struct diff_filepair *p = q->queue[i];
const char *name;
unsigned long copied, added, damage;
+ int content_changed;
- name = p->one->path ? p->one->path : p->two->path;
+ name = p->two->path ? p->two->path : p->one->path;
+
+ if (p->one->sha1_valid && p->two->sha1_valid)
+ content_changed = hashcmp(p->one->sha1, p->two->sha1);
+ 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
+ * look at the actual file contents at all.
+ * The fact that the SHA1 changed is enough for us to
+ * add this file to the list of results
+ * (with each file contributing equal damage).
+ */
+ damage = 1;
+ goto found_damage;
+ }
if (DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
diff_populate_filespec(p->one, 0);
@@ -1563,14 +1591,18 @@ 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. In --dirstat-by-file mode, count
- * damaged files, not damaged lines. This is done by
- * counting only a single damaged line per file.
+ * 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 (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)
+ if (!damage)
damage = 1;
+found_damage:
ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
dir.files[dir.nr].name = name;
dir.files[dir.nr].changed = damage;