{"thread":{"id":"25460","subject":"[PATCH] gitk: add the equivalent of diff --color-words","startedAt":"2010-10-16T10:15:10Z","lastAt":"2010-12-11T23:48:24Z","messageCount":4,"participants":["Thomas Rast","Jonathan Nieder","Matthieu Moy","Paul Mackerras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"153622","messageId":"3c06517d478b3725054f4ca08fb8c38e681549c4.1287223650.git.trast@student.ethz.ch","threadId":"25460","inReplyTo":null,"subject":"[PATCH] gitk: add the equivalent of diff --color-words","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-10-16T10:15:10Z","receivedAt":"2010-10-16T10:15:10Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Use the newly added 'diff --word-diff=porcelain' to teach gitk a\ncolor-words mode, with two different modes analogous to the\n--word-diff=plain and --word-diff=color settings.  These are selected\nby a dropdown box.\n\nAs an extra twist, automatically enable this word-diff support when\nthe user mentions a word-diff related option on the command line.\nThese options were previously ignored because they would break diff\nparsing.\n\nBoth of these features are only enabled if we have a version of git\nthat supports --word-diff=porcelain, meaning at least 1.7.2.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\nI sent this out ages ago, but it seems to have got stuck waiting for\ngit.git to pick up the required support:\n\n  http://mid.gmane.org/20100417063557.GB6681@brick.ozlabs.ibm.com\n\nThen I also forgot.  As you can check with 'git tag --contains\n882749a', this support has indeed gone into 1.7.2, so gitk can now\nalso learn about word-diff.\n\nThe only change since the patch discussed in the above thread is that\nI resolved a conflict with current gitk.git, and that the commit\nmessage now knows the exact version that first had the porcelain\nword-diff.\n\n(I hand-edited the patch to apply to gitk.git, so if that broke\nanything it's my fault.  But it seems to apply okay to its current\nmaster.)\n\n\n gitk |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 61 insertions(+), 3 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 1b0e09a..63a90bc 100644\n--- a/gitk\n+++ b/gitk\n@@ -131,6 +131,7 @@ proc unmerged_files {files} {\n \n proc parseviewargs {n arglist} {\n     global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env\n+    global worddiff git_version\n \n     set vdatemode($n) 0\n     set vmergeonly($n) 0\n@@ -168,7 +169,7 @@ proc parseviewargs {n arglist} {\n \t\tlappend diffargs $arg\n \t    }\n \t    \"--raw\" - \"--patch-with-raw\" - \"--patch-with-stat\" -\n-\t    \"--name-only\" - \"--name-status\" - \"--color\" - \"--color-words\" -\n+\t    \"--name-only\" - \"--name-status\" - \"--color\" -\n \t    \"--log-size\" - \"--pretty=*\" - \"--decorate\" - \"--abbrev-commit\" -\n \t    \"--cc\" - \"-z\" - \"--header\" - \"--parents\" - \"--boundary\" -\n \t    \"--no-color\" - \"-g\" - \"--walk-reflogs\" - \"--no-walk\" -\n@@ -177,6 +178,18 @@ proc parseviewargs {n arglist} {\n \t\t# These cause our parsing of git log's output to fail, or else\n \t\t# they're options we want to set ourselves, so ignore them.\n \t    }\n+\t    \"--color-words*\" - \"--word-diff=color\" {\n+\t\t# These trigger a word diff in the console interface,\n+\t\t# so help the user by enabling our own support\n+\t\tif {[package vcompare $git_version \"1.7.2\"] >= 0} {\n+\t\t    set worddiff [mc \"Color words\"]\n+\t\t}\n+\t    }\n+\t    \"--word-diff*\" {\n+\t\tif {[package vcompare $git_version \"1.7.2\"] >= 0} {\n+\t\t    set worddiff [mc \"Markup words\"]\n+\t\t}\n+\t    }\n \t    \"--stat=*\" - \"--numstat\" - \"--shortstat\" - \"--summary\" -\n \t    \"--check\" - \"--exit-code\" - \"--quiet\" - \"--topo-order\" -\n \t    \"--full-history\" - \"--dense\" - \"--sparse\" -\n@@ -1970,6 +1983,8 @@ proc makewindow {} {\n     global fprogitem fprogcoord lastprogupdate progupdatepending\n     global rprogitem rprogcoord rownumsel numcommits\n     global have_tk85 use_ttk NS\n+    global git_version\n+    global worddiff\n \n     # The \"mc\" arguments here are purely so that xgettext\n     # sees the following string as needing to be translated\n@@ -2243,6 +2258,15 @@ proc makewindow {} {\n     ${NS}::checkbutton .bleft.mid.ignspace -text [mc \"Ignore space change\"] \\\n \t-command changeignorespace -variable ignorespace\n     pack .bleft.mid.ignspace -side left -padx 5\n+\n+    set worddiff [mc \"Line diff\"]\n+    if {[package vcompare $git_version \"1.7.2\"] >= 0} {\n+\tmakedroplist .bleft.mid.worddiff worddiff [mc \"Line diff\"] \\\n+\t    [mc \"Markup words\"] [mc \"Color words\"]\n+\ttrace add variable worddiff write changeworddiff\n+\tpack .bleft.mid.worddiff -side left -padx 5\n+    }\n+\n     set ctext .bleft.bottom.ctext\n     text $ctext -background $bgcolor -foreground $fgcolor \\\n \t-state disabled -font textfont \\\n@@ -7502,11 +7526,16 @@ proc changeignorespace {} {\n     reselectline\n }\n \n+proc changeworddiff {name ix op} {\n+    reselectline\n+}\n+\n proc getblobdiffs {ids} {\n     global blobdifffd diffids env\n     global diffinhdr treediffs\n     global diffcontext\n     global ignorespace\n+    global worddiff\n     global limitdiffs vfilelimit curview\n     global diffencoding targetline diffnparents\n     global git_version currdiffsubmod\n@@ -7523,6 +7552,9 @@ proc getblobdiffs {ids} {\n     if {$ignorespace} {\n \tappend cmd \" -w\"\n     }\n+    if {$worddiff ne [mc \"Line diff\"]} {\n+\tappend cmd \" --word-diff=porcelain\"\n+    }\n     if {$limitdiffs && $vfilelimit($curview) ne {}} {\n \tset cmd [concat $cmd -- $vfilelimit($curview)]\n     }\n@@ -7608,6 +7640,7 @@ proc getblobdiffline {bdf ids} {\n     global ctext_file_names ctext_file_lines\n     global diffinhdr treediffs mergemax diffnparents\n     global diffencoding jump_to_here targetline diffline currdiffsubmod\n+    global worddiff\n \n     set nr 0\n     $ctext conf -state normal\n@@ -7747,15 +7780,28 @@ proc getblobdiffline {bdf ids} {\n \t    # parse the prefix - one ' ', '-' or '+' for each parent\n \t    set prefix [string range $line 0 [expr {$diffnparents - 1}]]\n \t    set tag [expr {$diffnparents > 1? \"m\": \"d\"}]\n+\t    set dowords [expr {$worddiff ne [mc \"Line diff\"] && $diffnparents == 1}]\n+\t    set words_pre_markup \"\"\n+\t    set words_post_markup \"\"\n \t    if {[string trim $prefix \" -+\"] eq {}} {\n \t\t# prefix only has \" \", \"-\" and \"+\" in it: normal diff line\n \t\tset num [string first \"-\" $prefix]\n+\t\tif {$dowords} {\n+\t\t    set line [string range $line 1 end]\n+\t\t}\n \t\tif {$num >= 0} {\n \t\t    # removed line, first parent with line is $num\n \t\t    if {$num >= $mergemax} {\n \t\t\tset num \"max\"\n \t\t    }\n-\t\t    $ctext insert end \"$line\\n\" $tag$num\n+\t\t    if {$dowords && $worddiff eq [mc \"Markup words\"]} {\n+\t\t\t$ctext insert end \"\\[-$line-\\]\" $tag$num\n+\t\t    } else {\n+\t\t\t$ctext insert end \"$line\" $tag$num\n+\t\t    }\n+\t\t    if {!$dowords} {\n+\t\t\t$ctext insert end \"\\n\" $tag$num\n+\t\t    }\n \t\t} else {\n \t\t    set tags {}\n \t\t    if {[string first \"+\" $prefix] >= 0} {\n@@ -7770,6 +7816,8 @@ proc getblobdiffline {bdf ids} {\n \t\t\t\tlappend tags m$num\n \t\t\t    }\n \t\t\t}\n+\t\t\tset words_pre_markup \"{+\"\n+\t\t\tset words_post_markup \"+}\"\n \t\t    }\n \t\t    if {$targetline ne {}} {\n \t\t\tif {$diffline == $targetline} {\n@@ -7779,8 +7827,17 @@ proc getblobdiffline {bdf ids} {\n \t\t\t    incr diffline\n \t\t\t}\n \t\t    }\n-\t\t    $ctext insert end \"$line\\n\" $tags\n+\t\t    if {$dowords && $worddiff eq [mc \"Markup words\"]} {\n+\t\t\t$ctext insert end \"$words_pre_markup$line$words_post_markup\" $tags\n+\t\t    } else {\n+\t\t\t$ctext insert end \"$line\" $tags\n+\t\t    }\n+\t\t    if {!$dowords} {\n+\t\t\t$ctext insert end \"\\n\" $tags\n+\t\t    }\n \t\t}\n+\t    } elseif {$dowords && $prefix eq \"~\"} {\n+\t\t$ctext insert end \"\\n\" {}\n \t    } else {\n \t\t# \"\\ No newline at end of file\",\n \t\t# or something else we don't recognize\n@@ -11391,6 +11448,7 @@ if {[tk windowingsystem] eq \"win32\"} {\n set diffcolors {red \"#00a000\" blue}\n set diffcontext 3\n set ignorespace 0\n+set worddiff \"\"\n set markbgcolor \"#e0e0ff\"\n \n set circlecolors {white blue gray blue blue}\n-- \n1.7.3.1.266.g3c065\n"},{"id":"153648","messageId":"20101017015836.GC26656@burratino","threadId":"25460","inReplyTo":"3c06517d478b3725054f4ca08fb8c38e681549c4.1287223650.git.trast@student.ethz.ch","subject":"Re: [PATCH] gitk: add the equivalent of diff --color-words","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-17T01:58:36Z","receivedAt":"2010-10-17T01:58:36Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Thomas Rast wrote:\n\n> Use the newly added 'diff --word-diff=porcelain' to teach gitk a\n> color-words mode, with two different modes analogous to the\n> --word-diff=plain and --word-diff=color settings.  These are selected\n> by a dropdown box.\n>\n> As an extra twist, automatically enable this word-diff support when\n> the user mentions a word-diff related option on the command line.\n\nI like this a lot.\n\nAfter this patch, the diff pane looks like this:\n\n( ) Diff ( ) Old version ( ) New version   Lines of context: [3 +/-] \\\n\t[ ] Ignore space changes  [ Line diff      v]\n\nall on one line.  In particular, it is easy not to notice the\nnew dropdown.\n\nOne might be tempted to change the Elide added lines/Elide removed\nlines radio buttons into a dropdown box, but that would remove the\nneat-o ability to switch between \"before\" and \"after\" views with a\nsingle click.  Oh well --- screens are getting bigger, anyway.\n"},{"id":"153783","messageId":"vpqbp6q9v4x.fsf@bauges.imag.fr","threadId":"25460","inReplyTo":"20101017015836.GC26656@burratino","subject":"Re: [PATCH] gitk: add the equivalent of diff --color-words","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-10-19T13:20:30Z","receivedAt":"2010-10-19T13:20:30Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Thomas Rast wrote:\n>\n>> Use the newly added 'diff --word-diff=porcelain' to teach gitk a\n>> color-words mode, with two different modes analogous to the\n>> --word-diff=plain and --word-diff=color settings.  These are selected\n>> by a dropdown box.\n>>\n>> As an extra twist, automatically enable this word-diff support when\n>> the user mentions a word-diff related option on the command line.\n>\n> I like this a lot.\n\n+1, it's really a feature I was looking forward.\n\n> After this patch, the diff pane looks like this:\n>\n> ( ) Diff ( ) Old version ( ) New version   Lines of context: [3 +/-] \\\n> \t[ ] Ignore space changes  [ Line diff      v]\n>\n> all on one line.  In particular, it is easy not to notice the\n> new dropdown.\n\nWorse than that: if the window is not large enough, the select box\n\"line diff/markup words/color words\" is totally hidden. Is there a way\nto have the display wrap to 2 lines when the window is not large\nenough?\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"157872","messageId":"20101211234824.GE3788@brick.ozlabs.ibm.com","threadId":"25460","inReplyTo":"3c06517d478b3725054f4ca08fb8c38e681549c4.1287223650.git.trast@student.ethz.ch","subject":"Re: [PATCH] gitk: add the equivalent of diff --color-words","fromName":"Paul Mackerras","fromEmail":"paulus@samba.org","sentAt":"2010-12-11T23:48:24Z","receivedAt":"2010-12-11T23:48:24Z","isPatch":true,"sender":{"key":"paulus@samba.org","avatar":"https://avatars.githubusercontent.com/u/1606439?v=4"},"body":"On Sat, Oct 16, 2010 at 12:15:10PM +0200, Thomas Rast wrote:\n\n> Use the newly added 'diff --word-diff=porcelain' to teach gitk a\n> color-words mode, with two different modes analogous to the\n> --word-diff=plain and --word-diff=color settings.  These are selected\n> by a dropdown box.\n\nThanks, applied.\n\nPaul.\n"}]}