diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-08-03 13:33:31 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-08-14 01:55:00 -0700 |
commit | fb13227e089f22dc31a3b1624559153821056848 (patch) | |
tree | a183d18dca83a2214c6d8cf69f0369f461a83fcb /builtin-diff.c | |
parent | 180787c48f21c40a047ae3ee5432821d7e033e44 (diff) | |
download | git-fb13227e089f22dc31a3b1624559153821056848.tar.gz |
git-diff: squelch "empty" diffs
After starting to edit a working tree file but later when your edit ends
up identical to the original (this can also happen when you ran a
wholesale regexp replace with something like "perl -i" that does not
actually modify many of the paths), "git diff" between the index and the
working tree outputs many "empty" diffs that show "diff --git" headers
and nothing else, because these paths are stat-dirty. While it was a
way to warn the user that the earlier action of the user made the index
ineffective as an optimization mechanism, it was felt too loud for the
purpose of warning even to experienced users, and also resulted in
confusing people new to git.
This replaces the "empty" diffs with a single warning message at the
end. Having many such paths hurts performance, and you can run
"git-update-index --refresh" to update the lstat(2) information recorded
in the index in such a case. "git-status" does so as a side effect, and
that is more familiar to the end-user, so we recommend it to them.
The change affects only "git diff" that outputs patch text, because that
is where the annoyance of too many "empty" diff is most strongly felt,
and because the warning message can be safely ignored by downstream
tools without getting mistaken as part of the patch. For the low-level
"git diff-files" and "git diff-index", the traditional behaviour is
retained.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-diff.c')
-rw-r--r-- | builtin-diff.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin-diff.c b/builtin-diff.c index 8dc17b0dd7..6ed7b6842e 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -222,6 +222,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) prefix = setup_git_directory_gently(&nongit); git_config(git_diff_ui_config); init_revisions(&rev, prefix); + rev.diffopt.skip_stat_unmatch = 1; if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix)) argc = 0; @@ -344,5 +345,12 @@ int cmd_diff(int argc, const char **argv, const char *prefix) ent, ents); if (rev.diffopt.exit_with_status) result = rev.diffopt.has_changes; + + if ((rev.diffopt.output_format & DIFF_FORMAT_PATCH) + && (1 < rev.diffopt.skip_stat_unmatch)) + printf("Warning: %d path%s touched but unmodified. " + "Consider running git-status.\n", + rev.diffopt.skip_stat_unmatch - 1, + rev.diffopt.skip_stat_unmatch == 2 ? "" : "s"); return result; } |