git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Help/Advice needed on diff bug in xutils.c
@ 2009-08-04 23:33 Thell Fowler
  2009-08-05 20:45 ` Johannes Schindelin
                   ` (3 more replies)
  0 siblings, 4 replies; 63+ messages in thread
From: Thell Fowler @ 2009-08-04 23:33 UTC (permalink / raw)
  To: git

Hi all!  Please give me a sanity check before I go crazy...

There is a bug in git diff (ignoring whitespace) that does not take into
account a trailing space at the end of a line at the end of a file when
no new line follows.

Here is the example of the bug:
mkdir test_ws_eof
cd test_ws_eof
git init
echo -n "Test" > test.txt
git add .
git commit -m'test'
git symbolic-ref HEAD refs/heads/with_space
rm .git/index
git clean -f
echo -n "Test ">test.txt
git add .
git commit -m'test'
# Ignoring all whitespace there shouldn't be a diff.
git diff -w master -- test.txt
# Ignoring space at eol there shouldn't be a diff
git diff --ignore-space-at-eol master -- test.txt
# Ignoring with -b might have a case for a diff showing.
git diff -b master -- test.txt


In the xutils.c xdl_hash_record_with_whitespace function the trailing
space prior to eof was being calculated into the hash, I fixed that
with the change below, but there is still a difference being noted in
xdl_recmatch because of the size difference.

Before I go changing something that shouldn't be changed could someone
provide some input please?

Thanks for reading,
Thell

diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 04ad468..623da92 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -243,17 +243,17 @@ static unsigned long
xdl_hash_record_with_whitespace(char
const **data,
                if (isspace(*ptr)) {
                        const char *ptr2 = ptr;
                        while (ptr + 1 < top && isspace(ptr[1])
-                                       && ptr[1] != '\n')
+                                       && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) )
                                ptr++;
                        if (flags & XDF_IGNORE_WHITESPACE)
                                ; /* already handled */
                        else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
-                                       && ptr[1] != '\n') {
+                                       && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) ) {
                                ha += (ha << 5);
                                ha ^= (unsigned long) ' ';
                        }
                        else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
-                                       && ptr[1] != '\n') {
+                                       && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) ) {
                                while (ptr2 != ptr + 1) {

^ permalink raw reply related	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2009-08-27 10:49 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-04 23:33 Help/Advice needed on diff bug in xutils.c Thell Fowler
2009-08-05 20:45 ` Johannes Schindelin
2009-08-10 18:54   ` Thell Fowler
2009-08-12  0:47   ` [PATCH/RFC] Add diff tests for trailing-space and now newline Thell Fowler
2009-08-19 23:05 ` [PATCH 0/6 RFC] Series to correct xutils incomplete line handling Thell Fowler
2009-08-21 17:39   ` Thell Fowler
2009-08-21 22:16     ` Alex Riesen
2009-08-22  4:23       ` Thell Fowler
     [not found] ` <cover.1250719760.git.git@tbfowler.name>
2009-08-19 23:06   ` [PATCH 1/6] Add supplemental test for trailing-whitespace on incomplete lines Thell Fowler
2009-08-19 23:06   ` [PATCH 2/6] Make xdl_hash_record_with_whitespace ignore eof Thell Fowler
2009-08-19 23:07   ` [PATCH 3/6] Make diff -w handle trailing-spaces on incomplete lines Thell Fowler
2009-08-20 23:09     ` Thell Fowler
2009-08-19 23:07   ` [PATCH 4/6] Make diff -b " Thell Fowler
2009-08-19 23:08   ` [PATCH 5/6] Make diff --ignore-space-at-eol handle " Thell Fowler
2009-08-19 23:09   ` [PATCH 6/6] Add diff tests for trailing-space on " Thell Fowler
2009-08-23  3:47 ` [PATCH-v2/RFC 0/6] improvements for trailing-space processing " Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 1/6] Add supplemental test for trailing-whitespace " Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 2/6] xutils: fix hash with whitespace on incomplete line Thell Fowler
2009-08-23  7:51     ` Junio C Hamano
2009-08-23 17:02       ` Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 3/6] xutils: fix ignore-all-space " Thell Fowler
2009-08-23  7:57     ` Junio C Hamano
2009-08-23  8:18       ` Nanako Shiraishi
2009-08-23  8:56         ` Junio C Hamano
2009-08-23 21:07           ` Nanako Shiraishi
2009-08-23 21:14             ` Junio C Hamano
2009-08-23 22:13             ` Thell Fowler
2009-08-23 22:30               ` Junio C Hamano
2009-08-24  4:16                 ` [PATCH] Teach mailinfo to ignore everything before -- >8 -- mark Nicolas Sebrecht
2009-08-24  4:51                   ` Junio C Hamano
2009-08-24  5:36                     ` Junio C Hamano
2009-08-24  6:21                       ` [PATCH] " Nicolas Sebrecht
2009-08-24  6:58                         ` Junio C Hamano
2009-08-24  7:31                           ` Nicolas Sebrecht
2009-08-24 14:02                             ` Don Zickus
2009-08-24 21:48                               ` Junio C Hamano
2009-08-24  5:16                   ` [PATCH] " Nanako Shiraishi
2009-08-24  7:17                     ` [PATCH] " Nicolas Sebrecht
2009-08-24  7:24                       ` Nicolas Sebrecht
2009-08-24 22:17                       ` Junio C Hamano
2009-08-25 16:18                         ` Nicolas Sebrecht
2009-08-26  1:51                           ` Junio C Hamano
     [not found]                             ` <20090826110332.6117@nanako3.lavabit.com>
2009-08-26  2:20                               ` Junio C Hamano
2009-08-26  3:03                             ` Junio C Hamano
2009-08-26  5:02                               ` Nicolas Sebrecht
2009-08-26  8:57                                 ` Jakub Narebski
2009-08-26  9:00                                   ` Johannes Schindelin
2009-08-27  5:46                                     ` Junio C Hamano
2009-08-27 10:49                                       ` Johannes Schindelin
2009-08-26  9:03                                   ` Junio C Hamano
2009-08-26  3:54                             ` Nicolas Sebrecht
2009-08-24  8:09                     ` [PATCH] " Nanako Shiraishi
2009-08-23 17:01       ` [PATCH-v2/RFC 3/6] xutils: fix ignore-all-space on incomplete line Thell Fowler
2009-08-23 19:40         ` Junio C Hamano
2009-08-23 20:33           ` Thell Fowler
2009-08-23 21:11             ` Junio C Hamano
2009-08-24  3:26               ` Thell Fowler
2009-08-24  6:02                 ` Junio C Hamano
2009-08-24 14:13                   ` Thell Fowler
2009-08-25  5:58                     ` Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 4/6] xutils: fix ignore-space-change " Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 5/6] xutils: fix ignore-space-at-eol " Thell Fowler
2009-08-23  3:49   ` [PATCH-v2/RFC 6/6] t4015: add tests for trailing-space " Thell Fowler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).