git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Eelis van der Weegen <eelis@eelis.net>,
	Junio C Hamano <gitster@pobox.com>,
	Paul Mackerras <paulus@samba.org>, Miles Bader <miles@gnu.org>
Subject: [PATCH 2/2] gitk: add the equivalent of diff --color-words
Date: Sun, 4 Apr 2010 15:46:39 +0200	[thread overview]
Message-ID: <d144dbcdc950d54837009b740ad1fa791b5e479a.1270388195.git.trast@student.ethz.ch> (raw)
In-Reply-To: <cover.1270388195.git.trast@student.ethz.ch>

Use the newly added 'diff --word-diff=porcelain' to teach gitk a
color-words mode, triggered by a checkbox.

As an extra twist, automatically enable this word-diff support when
the user mentions a word-diff related option on the command line.
These options were previously ignored because they would break diff
parsing.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 gitk |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/gitk b/gitk
index 1f36a3e..05ed053 100755
--- a/gitk
+++ b/gitk
@@ -131,6 +131,7 @@ proc unmerged_files {files} {
 
 proc parseviewargs {n arglist} {
     global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
+    global worddiff
 
     set vdatemode($n) 0
     set vmergeonly($n) 0
@@ -168,7 +169,7 @@ proc parseviewargs {n arglist} {
 		lappend diffargs $arg
 	    }
 	    "--raw" - "--patch-with-raw" - "--patch-with-stat" -
-	    "--name-only" - "--name-status" - "--color" - "--color-words" -
+	    "--name-only" - "--name-status" - "--color" -
 	    "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
 	    "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
 	    "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
@@ -177,6 +178,11 @@ proc parseviewargs {n arglist} {
 		# These cause our parsing of git log's output to fail, or else
 		# they're options we want to set ourselves, so ignore them.
 	    }
+	    "--color-words*" - "--word-diff*" {
+		# These trigger a word diff in the console interface,
+		# so help the user by enabling our own support
+		set worddiff 1
+	    }
 	    "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
 	    "--check" - "--exit-code" - "--quiet" - "--topo-order" -
 	    "--full-history" - "--dense" - "--sparse" -
@@ -2240,6 +2246,9 @@ proc makewindow {} {
     ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
 	-command changeignorespace -variable ignorespace
     pack .bleft.mid.ignspace -side left -padx 5
+    ${NS}::checkbutton .bleft.mid.worddiff -text [mc "Word diff"] \
+	-command changeworddiff -variable worddiff
+    pack .bleft.mid.worddiff -side left -padx 5
     set ctext .bleft.bottom.ctext
     text $ctext -background $bgcolor -foreground $fgcolor \
 	-state disabled -font textfont \
@@ -7494,11 +7503,16 @@ proc changeignorespace {} {
     reselectline
 }
 
+proc changeworddiff {} {
+    reselectline
+}
+
 proc getblobdiffs {ids} {
     global blobdifffd diffids env
     global diffinhdr treediffs
     global diffcontext
     global ignorespace
+    global worddiff
     global limitdiffs vfilelimit curview
     global diffencoding targetline diffnparents
     global git_version
@@ -7515,6 +7529,9 @@ proc getblobdiffs {ids} {
     if {$ignorespace} {
 	append cmd " -w"
     }
+    if {$worddiff} {
+	append cmd " --word-diff=porcelain"
+    }
     if {$limitdiffs && $vfilelimit($curview) ne {}} {
 	set cmd [concat $cmd -- $vfilelimit($curview)]
     }
@@ -7599,6 +7616,7 @@ proc getblobdiffline {bdf ids} {
     global ctext_file_names ctext_file_lines
     global diffinhdr treediffs mergemax diffnparents
     global diffencoding jump_to_here targetline diffline
+    global worddiff
 
     set nr 0
     $ctext conf -state normal
@@ -7727,15 +7745,22 @@ proc getblobdiffline {bdf ids} {
 	    # parse the prefix - one ' ', '-' or '+' for each parent
 	    set prefix [string range $line 0 [expr {$diffnparents - 1}]]
 	    set tag [expr {$diffnparents > 1? "m": "d"}]
+	    set dowords [expr {$worddiff && $diffnparents == 1}]
 	    if {[string trim $prefix " -+"] eq {}} {
 		# prefix only has " ", "-" and "+" in it: normal diff line
 		set num [string first "-" $prefix]
+		if {$dowords} {
+		    set line [string range $line 1 end]
+		}
 		if {$num >= 0} {
 		    # removed line, first parent with line is $num
 		    if {$num >= $mergemax} {
 			set num "max"
 		    }
-		    $ctext insert end "$line\n" $tag$num
+		    $ctext insert end "$line" $tag$num
+		    if {!$dowords} {
+			$ctext insert end "\n" $tag$num
+		    }
 		} else {
 		    set tags {}
 		    if {[string first "+" $prefix] >= 0} {
@@ -7759,8 +7784,13 @@ proc getblobdiffline {bdf ids} {
 			    incr diffline
 			}
 		    }
-		    $ctext insert end "$line\n" $tags
+		    $ctext insert end "$line" $tags
+		    if {!$dowords} {
+			$ctext insert end "\n" $tags
+		    }
 		}
+	    } elseif {$dowords && $prefix eq "~"} {
+		$ctext insert end "\n" {}
 	    } else {
 		# "\ No newline at end of file",
 		# or something else we don't recognize
@@ -11379,6 +11409,7 @@ if {[tk windowingsystem] eq "win32"} {
 set diffcolors {red "#00a000" blue}
 set diffcontext 3
 set ignorespace 0
+set worddiff 0
 set markbgcolor "#e0e0ff"
 
 set circlecolors {white blue gray blue blue}
-- 
1.7.0.3.521.ga1e9e

  parent reply	other threads:[~2010-04-04 13:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1269996525.git.trast@student.ethz>
2010-04-04 13:46 ` [PATCH 0/2] gitk --color-words Thomas Rast
2010-04-04 13:46   ` [PATCH 1/2] diff: add --word-diff option that generalizes --color-words Thomas Rast
2010-04-05  2:06     ` Junio C Hamano
2010-04-05 10:20       ` Thomas Rast
2010-04-05 18:46         ` Junio C Hamano
2010-04-05 18:53           ` Miles Bader
2010-04-12 13:07             ` [PATCH v3 0/2] gitk --color-words Thomas Rast
2010-04-12 13:07               ` [PATCH v3 1/3] diff: add --word-diff option that generalizes --color-words Thomas Rast
2010-04-12 16:31                 ` Junio C Hamano
2010-04-13  9:27                   ` Thomas Rast
2010-04-14 15:59                   ` [PATCH v4 0/3] git-diff --word-diff/gitk --color-words Thomas Rast
2010-04-14 15:59                     ` [PATCH v4 1/3] diff: add --word-diff option that generalizes --color-words Thomas Rast
2010-04-14 21:23                       ` Junio C Hamano
2010-04-14 15:59                     ` [PATCH v4 2/3] gitk: do not parse " >" context as submodule change Thomas Rast
2010-04-15 19:57                       ` Jens Lehmann
2010-04-17  6:33                       ` Paul Mackerras
2010-04-17 12:20                         ` Thomas Rast
2010-04-19  1:08                           ` Paul Mackerras
2010-04-19 16:27                             ` [PATCH v4' 1/2] " Thomas Rast
2010-04-19 16:27                               ` [PATCH v4' 2/2] gitk: add the equivalent of diff --color-words Thomas Rast
2010-04-19 17:22                               ` [PATCH v4' 1/2] gitk: do not parse " >" context as submodule change Jens Lehmann
2010-04-20 17:05                                 ` Jens Lehmann
2010-04-14 15:59                     ` [PATCH v4 3/3] gitk: add the equivalent of diff --color-words Thomas Rast
2010-04-17  6:35                       ` Paul Mackerras
2010-04-17  6:55                         ` Junio C Hamano
2010-04-12 13:07               ` [PATCH v3 2/3] gitk: do not parse " >" context as submodule change Thomas Rast
2010-04-12 13:25                 ` [PATCH v3.1] " Thomas Rast
2010-04-12 13:07               ` [PATCH v3 3/3] gitk: add the equivalent of diff --color-words Thomas Rast
2010-04-06  9:20           ` [PATCH 1/2] diff: add --word-diff option that generalizes --color-words Thomas Rast
2010-04-04 13:46   ` Thomas Rast [this message]
2010-03-31  0:52 [RFC PATCH 0/2] gitk --color-words Thomas Rast
2010-03-31  0:52 ` [PATCH 2/2] gitk: add the equivalent of diff --color-words Thomas Rast
2010-03-31 12:04   ` Thomas Rast

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d144dbcdc950d54837009b740ad1fa791b5e479a.1270388195.git.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=eelis@eelis.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=miles@gnu.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).