{"thread":{"id":"29991","subject":"A better git diff --word-diff (--word-diff-regex) ?","startedAt":"2012-03-19T09:44:31Z","lastAt":"2012-03-19T17:06:49Z","messageCount":7,"participants":["Piotr Krukowiecki","Matthieu Moy","Thomas Rast","Johannes Sixt","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"187244","messageId":"CAA01CsrJ12LmNYe6ujnDsZecJcGc8mFaB=1GC8-RZzvMYbYuUw@mail.gmail.com","threadId":"29991","inReplyTo":null,"subject":"A better git diff --word-diff (--word-diff-regex) ?","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2012-03-19T09:44:31Z","receivedAt":"2012-03-19T09:44:31Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"Hi,\n\nis there a way to configure --word-diff to be a more programming\nlanguage friendly? For example if I add one parameter to a function\ndeclaration, I'd like to see only the addition of the parameter as the\nchange. But currently it shows much more.\n\nFor example if\n  void foo(int x);\nis changed to\n  void foo(int x, int y);\nI'd like to see only \",int y\" as the change, not \"x, int y);\".\n\nI think I'd like to ignore all white spaces and tokenize text on word\nboundaries and see the diff between the tokens. This way if I e.g. add\na missing \";\" it'll be shown as the only change.\n\n\n$ echo 'void foo(int x);' > foo.c && git add foo.c && git commit -m \"foo\"\n[master (root-commit) 5af60cb2] foo\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 foo.c\n\n$ echo 'void foo(int x, int y);' > foo.c && git diff --word-diff\ndiff --git a/foo.c b/foo.c\nindex 42a5d4e9..289eb233 100644\n--- a/foo.c\n+++ b/foo.c\n@@ -1 +1 @@\nvoid foo(int [-x);-]{+x, int y);+}\n\n\nThanks,\n-- \nPiotr Krukowiecki\n"},{"id":"187245","messageId":"vpqvcm0exc4.fsf@bauges.imag.fr","threadId":"29991","inReplyTo":"CAA01CsrJ12LmNYe6ujnDsZecJcGc8mFaB=1GC8-RZzvMYbYuUw@mail.gmail.com","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-03-19T09:47:39Z","receivedAt":"2012-03-19T09:47:39Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n> Hi,\n>\n> is there a way to configure --word-diff to be a more programming\n> language friendly?\n\nI often use this:\n\n  git diff --color-words=.\n\nIt's rather bad on plain text, since it will try to diff within words,\nbut works well on source code.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"187246","messageId":"87ipi0vs0q.fsf@thomas.inf.ethz.ch","threadId":"29991","inReplyTo":"CAA01CsrJ12LmNYe6ujnDsZecJcGc8mFaB=1GC8-RZzvMYbYuUw@mail.gmail.com","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2012-03-19T09:50:29Z","receivedAt":"2012-03-19T09:50:29Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n> is there a way to configure --word-diff to be a more programming\n> language friendly? For example if I add one parameter to a function\n> declaration, I'd like to see only the addition of the parameter as the\n> change. But currently it shows much more.\n>\n> For example if\n>   void foo(int x);\n> is changed to\n>   void foo(int x, int y);\n> I'd like to see only \",int y\" as the change, not \"x, int y);\".\n>\n> I think I'd like to ignore all white spaces and tokenize text on word\n> boundaries and see the diff between the tokens. This way if I e.g. add\n> a missing \";\" it'll be shown as the only change.\n\nUmm, what's wrong with\n\n  echo '*.cpp diff=cpp' >>.git/info/attributes\n\nOk, the funcname patterns aren't so good, but the word regex is designed\nto \"tokenize\" as far as that is feasible.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"187247","messageId":"4F67033B.2060904@viscovery.net","threadId":"29991","inReplyTo":"CAA01CsrJ12LmNYe6ujnDsZecJcGc8mFaB=1GC8-RZzvMYbYuUw@mail.gmail.com","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2012-03-19T09:58:19Z","receivedAt":"2012-03-19T09:58:19Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 3/19/2012 10:44, schrieb Piotr Krukowiecki:\n> is there a way to configure --word-diff to be a more programming\n> language friendly? For example if I add one parameter to a function\n> declaration, I'd like to see only the addition of the parameter as the\n> change. But currently it shows much more.\n> \n> For example if\n>   void foo(int x);\n> is changed to\n>   void foo(int x, int y);\n> I'd like to see only \",int y\" as the change, not \"x, int y);\".\n> \n> I think I'd like to ignore all white spaces and tokenize text on word\n> boundaries and see the diff between the tokens. This way if I e.g. add\n> a missing \";\" it'll be shown as the only change.\n\nStart with\n\n   git config diff.wordregex '[[:alnum:]]+|[^[:space:]]'\n\nAdjust to your likings.\n\n-- Hannes\n"},{"id":"187251","messageId":"20120319151028.GC24848@sigill.intra.peff.net","threadId":"29991","inReplyTo":"CAA01CsrJ12LmNYe6ujnDsZecJcGc8mFaB=1GC8-RZzvMYbYuUw@mail.gmail.com","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-03-19T15:10:28Z","receivedAt":"2012-03-19T15:10:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 19, 2012 at 10:44:31AM +0100, Piotr Krukowiecki wrote:\n\n> is there a way to configure --word-diff to be a more programming\n> language friendly? For example if I add one parameter to a function\n> declaration, I'd like to see only the addition of the parameter as the\n> change. But currently it shows much more.\n> \n> For example if\n>   void foo(int x);\n> is changed to\n>   void foo(int x, int y);\n> I'd like to see only \",int y\" as the change, not \"x, int y);\".\n\nThis does not directly answer your question, but you may want to look at\nthe diff-highlight script in contrib/diff-highlight. I wrote it because\nI found word-diff often unreadable, but still wanted something to\nhighlight small changes on a line like this.\n\nOn your example, it produces:\n\n  -void foo(int x);\n  +void foo(int x{+, int y});\n\nexcept that the {+...} bit is highlighted by color, which makes it quite\nreadable.\n\n-Peff\n"},{"id":"187261","messageId":"CAA01CsqcDsK2-n6npQiiO2=ux0JdUU-Sq6ceHrc0A9q2hjQC3w@mail.gmail.com","threadId":"29991","inReplyTo":"vpqvcm0exc4.fsf@bauges.imag.fr","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2012-03-19T16:54:55Z","receivedAt":"2012-03-19T16:54:55Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Mon, Mar 19, 2012 at 10:47 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n>\n>> Hi,\n>>\n>> is there a way to configure --word-diff to be a more programming\n>> language friendly?\n>\n> I often use this:\n>\n>  git diff --color-words=.\n>\n> It's rather bad on plain text, since it will try to diff within words,\n> but works well on source code.\n\nHi,\n\nthanks for the idea, it's surely useful in many cases, but it can look\nconfusing on source code too. For example on git b3256eb8b in path.c\none part of the diff is\n\n-                       if (!access(used_path, F_OK)) {\n+                       if (!stat(used_path, &st) &&\n+                           (S_ISREG(st.st_mode) ||\n+                           (S_ISDIR(st.st_mode) &&\nis_git_directory(used_path)))) {\n\nand \"git diff --word-diff-regex=.\" shows\n\n                        if (![-acces-]s{+tat+}(used_path, [-F-]{+&st) &&+}\n{+                          (S+}_[-OK-]{+ISREG(st.st_mode) ||+}\n{+                          (S_ISDIR(st.st_mode) &&\nis_git_directory(used_path))+})) {\n\n\n\n-- \nPiotr Krukowiecki\n"},{"id":"187263","messageId":"CAA01Cso5z9oT_MyFmGCJ0aV7EXb11k8zK4bJ9XBBLT3Yx_zpdw@mail.gmail.com","threadId":"29991","inReplyTo":"87ipi0vs0q.fsf@thomas.inf.ethz.ch","subject":"Re: A better git diff --word-diff (--word-diff-regex) ?","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2012-03-19T17:06:49Z","receivedAt":"2012-03-19T17:06:49Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Mon, Mar 19, 2012 at 10:50 AM, Thomas Rast <trast@student.ethz.ch> wrote:\n> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n>\n>> is there a way to configure --word-diff to be a more programming\n>> language friendly? For example if I add one parameter to a function\n>> declaration, I'd like to see only the addition of the parameter as the\n>> change. But currently it shows much more.\n>\n> Umm, what's wrong with\n>\n>  echo '*.cpp diff=cpp' >>.git/info/attributes\n>\n> Ok, the funcname patterns aren't so good, but the word regex is designed\n> to \"tokenize\" as far as that is feasible.\n\nThanks, that's very good! I've missed it reading the git-diff man page.\n\n-- \nPiotr Krukowiecki\n"}]}