git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Something wrong with diff --color-words=regexp?
@ 2015-02-19 23:52 Mike Hommey
  2015-02-20  7:49 ` Johannes Sixt
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Hommey @ 2015-02-19 23:52 UTC (permalink / raw)
  To: git

Hi,

I was trying to use --color-words with a regex to check a diff, and it appears
it displays things out of order. Am I misunderstanding what my regexp should be
doing or is there a bug?

$ git diff -U3 HEAD^ dom/base/nsDOMFileReader.cpp 
diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp
index 6267e0e..fa22590 100644
--- a/dom/base/nsDOMFileReader.cpp
+++ b/dom/base/nsDOMFileReader.cpp
@@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
       return NS_ERROR_OUT_OF_MEMORY;
     }
     if (mDataFormat != FILE_AS_ARRAYBUFFER) {
-      mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount);
+      mFileData = (char *) realloc(mFileData, mDataLen + aCount);
       NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);
     }
 
$ git diff -U3 --color-words='[^ ()]' HEAD^ dom/base/nsDOMFileReader.cpp 
diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp
index 6267e0e..fa22590 100644
--- a/dom/base/nsDOMFileReader.cpp
+++ b/dom/base/nsDOMFileReader.cpp
@@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
      return NS_ERROR_OUT_OF_MEMORY;
    }
    if (mDataFormat != FILE_AS_ARRAYBUFFER) {
      mFileData = (char *moz_) realloc(mFileData, mDataLen + aCount);
      NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);
    }


(This is with 2.3.0)

Cheers,

Mike

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

* Re: Something wrong with diff --color-words=regexp?
  2015-02-19 23:52 Something wrong with diff --color-words=regexp? Mike Hommey
@ 2015-02-20  7:49 ` Johannes Sixt
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Sixt @ 2015-02-20  7:49 UTC (permalink / raw)
  To: Mike Hommey, git

Am 20.02.2015 um 00:52 schrieb Mike Hommey:
> Hi,
>
> I was trying to use --color-words with a regex to check a diff, and it appears
> it displays things out of order. Am I misunderstanding what my regexp should be
> doing or is there a bug?
>
> $ git diff -U3 HEAD^ dom/base/nsDOMFileReader.cpp
> diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp
> index 6267e0e..fa22590 100644
> --- a/dom/base/nsDOMFileReader.cpp
> +++ b/dom/base/nsDOMFileReader.cpp
> @@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
>         return NS_ERROR_OUT_OF_MEMORY;
>       }
>       if (mDataFormat != FILE_AS_ARRAYBUFFER) {
> -      mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount);
> +      mFileData = (char *) realloc(mFileData, mDataLen + aCount);
>         NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);
>       }
>
> $ git diff -U3 --color-words='[^ ()]' HEAD^ dom/base/nsDOMFileReader.cpp
> diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp
> index 6267e0e..fa22590 100644
> --- a/dom/base/nsDOMFileReader.cpp
> +++ b/dom/base/nsDOMFileReader.cpp
> @@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
>        return NS_ERROR_OUT_OF_MEMORY;
>      }
>      if (mDataFormat != FILE_AS_ARRAYBUFFER) {
>        mFileData = (char *moz_) realloc(mFileData, mDataLen + aCount);
>        NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);
>      }

Your regexp says that every character (with a few exceptions) by itself 
is a word. Your diff says that it deleted the words 'm', 'o', 'z', and 
'_'. So, that is not wrong.

Furthermore, your regexp says that space, '(' and ')' are whitespace. 
Whitespace is *ignored* for computation of the word difference. 
Nevertheless, --color-word mode helpfully keeps the whitespace of the 
post-image to produce readable output. In doing so, it has to choose 
whether to keep the whitespace before or after a word. It chooses to 
keep it before a word. Hence, you see the whitespace sequence ') ' 
attached in front of 'r' (of 'realloc') instead of after '*'. So, the 
procedure is a matter of choice, which sometimes does not match 
expectations.

Perhaps you meant to say

     --color-words='[^ ()]+'

to split the diff text into longer words.

-- Hannes

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

end of thread, other threads:[~2015-02-20  7:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19 23:52 Something wrong with diff --color-words=regexp? Mike Hommey
2015-02-20  7:49 ` Johannes Sixt

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).