{"thread":{"id":"38606","subject":"Something wrong with diff --color-words=regexp?","startedAt":"2015-02-19T23:52:13Z","lastAt":"2015-02-20T07:49:09Z","messageCount":2,"participants":["Mike Hommey","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"256373","messageId":"20150219235213.GA1291@glandium.org","threadId":"38606","inReplyTo":null,"subject":"Something wrong with diff --color-words=regexp?","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2015-02-19T23:52:13Z","receivedAt":"2015-02-19T23:52:13Z","isPatch":false,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Hi,\n\nI was trying to use --color-words with a regex to check a diff, and it appears\nit displays things out of order. Am I misunderstanding what my regexp should be\ndoing or is there a bug?\n\n$ git diff -U3 HEAD^ dom/base/nsDOMFileReader.cpp \ndiff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp\nindex 6267e0e..fa22590 100644\n--- a/dom/base/nsDOMFileReader.cpp\n+++ b/dom/base/nsDOMFileReader.cpp\n@@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)\n       return NS_ERROR_OUT_OF_MEMORY;\n     }\n     if (mDataFormat != FILE_AS_ARRAYBUFFER) {\n-      mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount);\n+      mFileData = (char *) realloc(mFileData, mDataLen + aCount);\n       NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);\n     }\n \n$ git diff -U3 --color-words='[^ ()]' HEAD^ dom/base/nsDOMFileReader.cpp \ndiff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp\nindex 6267e0e..fa22590 100644\n--- a/dom/base/nsDOMFileReader.cpp\n+++ b/dom/base/nsDOMFileReader.cpp\n@@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)\n      return NS_ERROR_OUT_OF_MEMORY;\n    }\n    if (mDataFormat != FILE_AS_ARRAYBUFFER) {\n      mFileData = (char *moz_) realloc(mFileData, mDataLen + aCount);\n      NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);\n    }\n\n\n(This is with 2.3.0)\n\nCheers,\n\nMike\n"},{"id":"256388","messageId":"54E6E6F5.2020202@kdbg.org","threadId":"38606","inReplyTo":"20150219235213.GA1291@glandium.org","subject":"Re: Something wrong with diff --color-words=regexp?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2015-02-20T07:49:09Z","receivedAt":"2015-02-20T07:49:09Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 20.02.2015 um 00:52 schrieb Mike Hommey:\n> Hi,\n>\n> I was trying to use --color-words with a regex to check a diff, and it appears\n> it displays things out of order. Am I misunderstanding what my regexp should be\n> doing or is there a bug?\n>\n> $ git diff -U3 HEAD^ dom/base/nsDOMFileReader.cpp\n> diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp\n> index 6267e0e..fa22590 100644\n> --- a/dom/base/nsDOMFileReader.cpp\n> +++ b/dom/base/nsDOMFileReader.cpp\n> @@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)\n>         return NS_ERROR_OUT_OF_MEMORY;\n>       }\n>       if (mDataFormat != FILE_AS_ARRAYBUFFER) {\n> -      mFileData = (char *) moz_realloc(mFileData, mDataLen + aCount);\n> +      mFileData = (char *) realloc(mFileData, mDataLen + aCount);\n>         NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);\n>       }\n>\n> $ git diff -U3 --color-words='[^ ()]' HEAD^ dom/base/nsDOMFileReader.cpp\n> diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp\n> index 6267e0e..fa22590 100644\n> --- a/dom/base/nsDOMFileReader.cpp\n> +++ b/dom/base/nsDOMFileReader.cpp\n> @@ -363,7 +363,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)\n>        return NS_ERROR_OUT_OF_MEMORY;\n>      }\n>      if (mDataFormat != FILE_AS_ARRAYBUFFER) {\n>        mFileData = (char *moz_) realloc(mFileData, mDataLen + aCount);\n>        NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY);\n>      }\n\nYour regexp says that every character (with a few exceptions) by itself \nis a word. Your diff says that it deleted the words 'm', 'o', 'z', and \n'_'. So, that is not wrong.\n\nFurthermore, your regexp says that space, '(' and ')' are whitespace. \nWhitespace is *ignored* for computation of the word difference. \nNevertheless, --color-word mode helpfully keeps the whitespace of the \npost-image to produce readable output. In doing so, it has to choose \nwhether to keep the whitespace before or after a word. It chooses to \nkeep it before a word. Hence, you see the whitespace sequence ') ' \nattached in front of 'r' (of 'realloc') instead of after '*'. So, the \nprocedure is a matter of choice, which sometimes does not match \nexpectations.\n\nPerhaps you meant to say\n\n     --color-words='[^ ()]+'\n\nto split the diff text into longer words.\n\n-- Hannes\n"}]}