{"thread":{"id":"23528","subject":"[PATCH v4' 2/2] gitk: add the equivalent of diff --color-words","startedAt":"2010-04-19T16:27:26Z","lastAt":"2010-04-20T17:05:32Z","messageCount":4,"participants":["Thomas Rast","Jens Lehmann"],"isPatch":true,"patchVersion":4,"patchTotal":2},"messages":[{"id":"139914","messageId":"671110fcac73c5fc8a935b82d88f8553c510c50c.1271694102.git.trast@student.ethz.ch","threadId":"23528","inReplyTo":"20100419010819.GA4386@brick.ozlabs.ibm.com","subject":"[PATCH v4' 1/2] gitk: do not parse \" >\" context as submodule change","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-04-19T16:27:26Z","receivedAt":"2010-04-19T16:27:26Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Since 5c838d2 (gitk: Use the --submodule option for displaying diffs\nwhen available, 2009-10-28) gitk erroneously matches \"  >\" and \"  <\"\nat the beginning of a line in the submodule code even if we're in the\ndiff text section and the lines should be treated as context.\n\nFix by (ab)using the $diffinhdr variable also in the 'Submodule...'\ncase, and move the \"  >\"/\"  <\" specific code inside the $diffinhdr\ntest.  The existing code will set $diffinhdr to 0 when it hits a\n\"+++\", so that it is always 0 when we can hit a context line.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n\n> Thanks, but now that I have applied Jens Lehmann's patch that also\n> touches this area, your patch doesn't apply.  Could you rebase it and\n> send it again?\n\nSure.\n\n\n gitk |   18 ++++++++++--------\n 1 files changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 1b0e09a..6513ef8 100755\n--- a/gitk\n+++ b/gitk\n@@ -7706,14 +7706,8 @@ proc getblobdiffline {bdf ids} {\n \t    } else {\n \t\t$ctext insert end \"$line\\n\" filesep\n \t    }\n-\t} elseif {![string compare -length 3 \"  >\" $line]} {\n-\t    set $currdiffsubmod \"\"\n-\t    set line [encoding convertfrom $diffencoding $line]\n-\t    $ctext insert end \"$line\\n\" dresult\n-\t} elseif {![string compare -length 3 \"  <\" $line]} {\n-\t    set $currdiffsubmod \"\"\n-\t    set line [encoding convertfrom $diffencoding $line]\n-\t    $ctext insert end \"$line\\n\" d0\n+\t    # pretend we're in a file header to correctly parse \"  [><]\"\n+\t    set diffinhdr 1\n \t} elseif {$diffinhdr} {\n \t    if {![string compare -length 12 \"rename from \" $line]} {\n \t\tset fname [string range $line [expr 6 + [string first \" from \" $line] ] end]\n@@ -7732,6 +7726,14 @@ proc getblobdiffline {bdf ids} {\n \t\t    set fname [lindex $fname 0]\n \t\t}\n \t\tmakediffhdr $fname $ids\n+\t    } elseif {![string compare -length 3 \"  >\" $line]} {\n+\t\tset line [encoding convertfrom $diffencoding $line]\n+\t\t$ctext insert end \"$line\\n\" dresult\n+\t\tcontinue\n+\t    } elseif {![string compare -length 3 \"  <\" $line]} {\n+\t\tset line [encoding convertfrom $diffencoding $line]\n+\t\t$ctext insert end \"$line\\n\" d0\n+\t\tcontinue\n \t    } elseif {[string compare -length 3 $line \"---\"] == 0} {\n \t\t# do nothing\n \t\tcontinue\n-- \n1.7.1.rc1.284.g4b2e3\n"},{"id":"139913","messageId":"34692bfb072d02aaa0dea01515fa89d4a1f175b8.1271694102.git.trast@student.ethz.ch","threadId":"23528","inReplyTo":"671110fcac73c5fc8a935b82d88f8553c510c50c.1271694102.git.trast@student.ethz.ch","subject":"[PATCH v4' 2/2] gitk: add the equivalent of diff --color-words","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-04-19T16:27:27Z","receivedAt":"2010-04-19T16:27:27Z","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, tentatively set to 1.7.2.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n gitk |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 files changed, 61 insertions(+), 3 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 6513ef8..46d1b0e 100755\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@@ -7749,15 +7782,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@@ -7772,6 +7818,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@@ -7781,8 +7829,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@@ -11393,6 +11450,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.1.rc1.284.g4b2e3\n"},{"id":"139918","messageId":"4BCC9164.3080301@web.de","threadId":"23528","inReplyTo":"671110fcac73c5fc8a935b82d88f8553c510c50c.1271694102.git.trast@student.ethz.ch","subject":"Re: [PATCH v4' 1/2] gitk: do not parse \" >\" context as submodule change","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-04-19T17:22:44Z","receivedAt":"2010-04-19T17:22:44Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 19.04.2010 18:27, schrieb Thomas Rast:\n>> Thanks, but now that I have applied Jens Lehmann's patch that also\n>> touches this area, your patch doesn't apply.  Could you rebase it and\n>> send it again?\n> \n> Sure.\n\nThere might be a problem with this rebase. Unfortunately I am very\nshort on time, so I can't test this today.\n\nI think setting the $currdiffsubmod variable to the empty string\nhas to show up in the two sections formatting the lines with\n\"  >\" & \"  <\".\n\n\n>  gitk |   18 ++++++++++--------\n>  1 files changed, 10 insertions(+), 8 deletions(-)\n> \n> diff --git a/gitk b/gitk\n> index 1b0e09a..6513ef8 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -7706,14 +7706,8 @@ proc getblobdiffline {bdf ids} {\n>  \t    } else {\n>  \t\t$ctext insert end \"$line\\n\" filesep\n>  \t    }\n> -\t} elseif {![string compare -length 3 \"  >\" $line]} {\n> -\t    set $currdiffsubmod \"\"\n> -\t    set line [encoding convertfrom $diffencoding $line]\n> -\t    $ctext insert end \"$line\\n\" dresult\n> -\t} elseif {![string compare -length 3 \"  <\" $line]} {\n> -\t    set $currdiffsubmod \"\"\n> -\t    set line [encoding convertfrom $diffencoding $line]\n> -\t    $ctext insert end \"$line\\n\" d0\n> +\t    # pretend we're in a file header to correctly parse \"  [><]\"\n> +\t    set diffinhdr 1\n>  \t} elseif {$diffinhdr} {\n>  \t    if {![string compare -length 12 \"rename from \" $line]} {\n>  \t\tset fname [string range $line [expr 6 + [string first \" from \" $line] ] end]\n> @@ -7732,6 +7726,14 @@ proc getblobdiffline {bdf ids} {\n>  \t\t    set fname [lindex $fname 0]\n>  \t\t}\n>  \t\tmakediffhdr $fname $ids\n> +\t    } elseif {![string compare -length 3 \"  >\" $line]} {\n\nI suspect we need a 'set $currdiffsubmod \"\"' here\n\n> +\t\tset line [encoding convertfrom $diffencoding $line]\n> +\t\t$ctext insert end \"$line\\n\" dresult\n> +\t\tcontinue\n> +\t    } elseif {![string compare -length 3 \"  <\" $line]} {\n\nand here.\n\n> +\t\tset line [encoding convertfrom $diffencoding $line]\n> +\t\t$ctext insert end \"$line\\n\" d0\n> +\t\tcontinue\n>  \t    } elseif {[string compare -length 3 $line \"---\"] == 0} {\n>  \t\t# do nothing\n>  \t\tcontinue\n\nIf you can wait until tomorrow I can check that.\n"},{"id":"139989","messageId":"4BCDDEDC.7040507@web.de","threadId":"23528","inReplyTo":"4BCC9164.3080301@web.de","subject":"Re: [PATCH v4' 1/2] gitk: do not parse \" >\" context as submodule change","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-04-20T17:05:32Z","receivedAt":"2010-04-20T17:05:32Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 19.04.2010 19:22, schrieb Jens Lehmann:\n> Am 19.04.2010 18:27, schrieb Thomas Rast:\n>>> Thanks, but now that I have applied Jens Lehmann's patch that also\n>>> touches this area, your patch doesn't apply.  Could you rebase it and\n>>> send it again?\n>>\n>> Sure.\n> \n> There might be a problem with this rebase. Unfortunately I am very\n> short on time, so I can't test this today.\n\nI successfully tested this patch, this was a false alarm from my side.\nSorry for the noise.\n\nTested-by: Jens.Lehmann@web.de\n"}]}