[PATCH] Do not show empty diff in diff-cache uncached.
- From
Junio C Hamano <junkio@cox.net>
- Date
- May 28, 2005, 10:11 UTC
- Message-ID
- <7vis13wth4.fsf_-_@assigned-by-dhcp.cox.net>
- In-Reply-To
- <7v3bs82rwh.fsf@assigned-by-dhcp.cox.net>
Pre- "diff --git" built-in diff did not add any extended header on its own, so it did not show anything for unmodified but stat-dirty file from diff-cache command without --cached flag.
Recent diff-cache produces "diff --git" header internally before calling the "diff" command, which results in an empty diff for such a file, cluttering the output. This patch fixes this.
Signed-off-by: Junio C Hamano <junkio@cox.net> ---
diff.c | 26 ++++++++++++++++++++++++++ diffcore-rename.c | 17 ----------------- diffcore.h | 2 ++ 3 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/diff.c b/diff.c --- a/diff.c +++ b/diff.c @@ -684,6 +684,23 @@ int diff_unmodified_pair(struct diff_fil return 0; } +int is_exact_match(struct diff_filespec *src, struct diff_filespec *dst) +{ + if (src->sha1_valid && dst->sha1_valid && + !memcmp(src->sha1, dst->sha1, 20)) + return 1; + if (diff_populate_filespec(src, 1) || diff_populate_filespec(dst, 1)) + return 0; + if (src->size != dst->size) + return 0; + if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0)) + return 0; + if (src->size == dst->size && + !memcmp(src->data, dst->data, src->size)) + return 1; + return 0; +} + static void diff_flush_patch(struct diff_filepair *p) { const char *name, *other; @@ -692,6 +709,15 @@ static void diff_flush_patch(struct diff if (diff_unmodified_pair(p)) return; + /* When diff-raw would have said "look at the filesystem", we + * need to see if the two are the same and if so not to emit + * anything at all. Avoid is_exact_match() comparison when it + * does not matter. + */ + if ((DIFF_FILE_VALID(p->two) && !p->two->sha1_valid) && + is_exact_match(p->one, p->two)) + return; + name = p->one->path; other = (strcmp(name, p->two->path) ? p->two->path : NULL); if ((DIFF_FILE_VALID(p->one) && S_ISDIR(p->one->mode)) || diff --git a/diffcore-rename.c b/diffcore-rename.c --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -94,23 +94,6 @@ static struct diff_rename_src *register_ return &(rename_src[first]); } -static int is_exact_match(struct diff_filespec *src, struct diff_filespec *dst) -{ - if (src->sha1_valid && dst->sha1_valid && - !memcmp(src->sha1, dst->sha1, 20)) - return 1; - if (diff_populate_filespec(src, 1) || diff_populate_filespec(dst, 1)) - return 0; - if (src->size != dst->size) - return 0; - if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0)) - return 0; - if (src->size == dst->size && - !memcmp(src->data, dst->data, src->size)) - return 1; - return 0; -} - struct diff_score { int src; /* index in rename_src */ int dst; /* index in rename_dst */ diff --git a/diffcore.h b/diffcore.h --- a/diffcore.h +++ b/diffcore.h @@ -29,6 +29,8 @@ struct diff_filespec { unsigned should_munmap : 1; /* data should be munmap()'ed */ }; +extern int is_exact_match(struct diff_filespec *, struct diff_filespec *); + extern struct diff_filespec *alloc_filespec(const char *); extern void fill_filespec(struct diff_filespec *, const unsigned char *, unsigned short); ------------------------------------------------