[PATCH] apply.c: tolerate diff from a dirty but unchanged path
- From
Junio C Hamano <junkio@cox.net>
- Date
- Jun 11, 2005, 23:27 UTC
- Message-ID
- <7vpsusqxsy.fsf_-_@assigned-by-dhcp.cox.net>
- In-Reply-To
- <Pine.LNX.4.58.0505291151250.10545@ppc970.osdl.org>
I just noticed a problem with empty "diff --git" header a dirty but otherwise unmodified path spits out. The problem is related to an old topic:
Re: [PATCH] Do not show empty diff in diff-cache uncached.
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes: LT> On Sat, 28 May 2005, Junio C Hamano wrote:
>> 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. LT> I actually _expect_ that "git-diff-files" will show
LT> files that don't match the index, even if they happen to
LT> have the exact content that the index points to. It's
LT> how I know whether the index is up-to-date or not.I now agree with the reasoning and think showing an empty "diff --git" header is a good thing. I had something like this, while fixing a rename/copy bug:
...
#endif static void diff_resolve_rename_copy(void)
diff --git a/diffcore-break.c b/diffcore-break.c
diff --git a/diffcore-rename.c b/diffcore-rename.c
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -249,8 +249,12 @@ void diffcore_rename(int detect_rename,
...I touched diffcore-break.c and decided I should not change it so I reverted, which is why the empty "diff --git" for that file shows that the cache is dirty. The problem is that currently, "git-apply --stat" seems to barf reading such a patch.
Here is a proposed fix.
------------ apply.c: tolerate diff from a dirty but otherwise unchanged cache.
For such an entry, "diff --git" line without anything else is output, but the next "diff --git" header is not really treated as an unrecognized diff.
Signed-off-by: Junio C Hamano <junkio@cox.net> ---
diff --git a/apply.c b/apply.c --- a/apply.c +++ b/apply.c @@ -343,7 +343,7 @@ static int gitdiff_dissimilarity(const c */ static int gitdiff_unrecognized(const char *line, struct patch *patch) { - return -1; + return -2; } static char *git_header_name(char *line) @@ -453,8 +453,12 @@ static int parse_git_header(char *line, int oplen = strlen(p->str); if (len < oplen || memcmp(p->str, line, oplen)) continue; - if (p->fn(line + oplen, patch) < 0) + switch (p->fn(line + oplen, patch)) { + case -1: return offset; + case -2: + return -1; + } break; } }