{"thread":{"id":"11806","subject":"[PATCH] gitk : External diff viewer.","startedAt":"2008-01-31T16:00:02Z","lastAt":"2008-01-31T17:50:38Z","messageCount":2,"participants":["Thomas Arcila","Steffen Prohaska"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"66988","messageId":"1201795202.11689.9.camel@bod-tarcila2.ad.mc.com","threadId":"11806","inReplyTo":null,"subject":"[PATCH] gitk : External diff viewer.","fromName":"Thomas Arcila","fromEmail":"tarcila@mc.com","sentAt":"2008-01-31T16:00:02Z","receivedAt":"2008-01-31T16:00:02Z","isPatch":true,"sender":{"key":"tarcila@mc.com","avatar":null},"body":"Right click on patched file list view gives \"External diff\" popup menu entry,\nlaunching selected external diff tool.\nThe diff tool is configurable through Edit/Preference/External diff tool.\n\nSigned-off-by: Thomas Arcila <tarcila@mc.com>\n---\n\nHi,\n\nHere is a patch to gitk that allows to run an external diff viewer.\nIt can be configured in Edit/Preferences/External diff tool.\n\nTo see the diff between two files:\n- select revisions to diff\n- right click on a file in the patched files list view\n- choose \"External diff\"\n\nAny feedback is welcome.\nThomas\n\n gitk |  132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 128 insertions(+), 4 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 5560e4d..6d727f4 100755\n--- a/gitk\n+++ b/gitk\n@@ -1054,6 +1054,16 @@ proc makewindow {} {\n \t-command {flist_hl 0}\n     $flist_menu add command -label [mc \"Highlight this only\"] \\\n \t-command {flist_hl 1}\n+    $flist_menu add command -label [mc \"External diff\"] \\\n+        -command {external_diff}\n+\n+    global flist_menu_tree\n+    set flist_menu_tree .flistctxmenutree\n+    menu $flist_menu_tree -tearoff 0\n+    $flist_menu_tree add command -label [mc \"Highlight this too\"] \\\n+\t-command {flist_hl 0}\n+    $flist_menu_tree add command -label [mc \"Highlight this only\"] \\\n+\t-command {flist_hl 1}\n }\n \n # Windows sends all mouse wheel events to the current focused window, not\n@@ -1157,7 +1167,7 @@ proc savestuff {w} {\n     global maxwidth showneartags showlocalchanges\n     global viewname viewfiles viewargs viewperm nextviewnum\n     global cmitmode wrapcomment datetimeformat limitdiffs\n-    global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor\n+    global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor extdifftool\n \n     if {$stuffsaved} return\n     if {![winfo viewable .]} return\n@@ -1182,6 +1192,7 @@ proc savestuff {w} {\n \tputs $f [list set diffcolors $diffcolors]\n \tputs $f [list set diffcontext $diffcontext]\n \tputs $f [list set selectbgcolor $selectbgcolor]\n+\tputs $f [list set extdifftool $extdifftool]\n \n \tputs $f \"set geometry(main) [wm geometry .]\"\n \tputs $f \"set geometry(topwidth) [winfo width .tf]\"\n@@ -1719,7 +1730,7 @@ proc sel_flist {w x y} {\n }\n \n proc pop_flist_menu {w X Y x y} {\n-    global ctext cflist cmitmode flist_menu flist_menu_file\n+    global ctext cflist cmitmode flist_menu flist_menu_tree flist_menu_file\n     global treediffs diffids\n \n     stopfinding\n@@ -1732,7 +1743,11 @@ proc pop_flist_menu {w X Y x y} {\n \tset e [lindex $treediffs($diffids) [expr {$l-2}]]\n     }\n     set flist_menu_file $e\n-    tk_popup $flist_menu $X $Y\n+    if {$cmitmode eq \"tree\"} {\n+      tk_popup $flist_menu_tree $X $Y\n+    } else {\n+      tk_popup $flist_menu $X $Y\n+    }\n }\n \n proc flist_hl {only} {\n@@ -1747,6 +1762,99 @@ proc flist_hl {only} {\n     set gdttype [mc \"touching paths:\"]\n }\n \n+proc external_diff {} {\n+  global gitktmpdir nullid nullid2\n+  global flist_menu_file\n+  global diffids\n+  global diffnum\n+  global gitdir extdifftool\n+\n+  set diffidto [lindex $diffids 0]\n+\n+  if {[llength $diffids] == 1} {\n+    # no reference commit given\n+    set diffidto [lindex $diffids 0]\n+    if {$diffidto eq $nullid} {\n+      # diffing working copy with index\n+      set diffidfrom $nullid2\n+    } elseif {$diffidto eq $nullid2} {\n+      # diffing index with HEAD\n+      set diffidfrom \"HEAD\"\n+    } else {\n+      # use parent commit\n+      global allparents\n+      set diffidfrom $allparents($diffidto)\n+    }\n+  } else {\n+    set diffidfrom [lindex $diffids 0]\n+    set diffidto [lindex $diffids 1]\n+  }\n+\n+  if {! [info exists diffnum]} {\n+    set diffnum 0\n+  } else {\n+    set diffnum [expr $diffnum + 1]\n+  }\n+\n+\n+  set diffdir [file join $gitktmpdir \"$diffnum\"]\n+  set diffok \"true\"\n+\n+  file mkdir $diffdir\n+  if {$diffidto eq $nullid} {\n+    set difftofile [file join $gitdir \"..\" $flist_menu_file]\n+  } elseif {$diffidto eq $nullid2} {\n+    set difftofile [file join $diffdir \"\\[index\\] [file tail $flist_menu_file]\"]\n+    if {[catch {exec git show :$flist_menu_file > $difftofile} err]} {\n+      error_popup \"\\\"$flist_menu_file\\\" [mc \"cannot be found in index. \\\n+                  File has probably been created, deleted or renamed, \\\n+                  in a different commit.\"]\"\n+      set diffok \"false\"\n+    }\n+  } else {\n+    set difftofile [file join $diffdir \"\\[$diffidto\\] [file tail $flist_menu_file]\"]\n+    if {[catch {exec git show $diffidto:$flist_menu_file > $difftofile} err]} {\n+      error_popup \"\\\"$flist_menu_file\\\" [mc \"cannot be found in revision\"] \\\n+                  $diffidto. [mc \"File has probably been created, \\\n+                  deleted or renamed, in a different commit.\"]\"\n+      set diffok \"false\"\n+    }\n+  }\n+\n+  if {$diffidfrom == $nullid} {\n+    set difffromfile [file join $gitdir \"..\" $flist_menu_file]\n+  } elseif {$diffidfrom == $nullid2} {\n+    set difffromfile [file join $diffdir \"\\[index\\] [file tail $flist_menu_file]\"]\n+    if {[catch {exec git show :$flist_menu_file > $difffromfile} err]} {\n+      error_popup \"\\\"$flist_menu_file\\\" [mc \"cannot be found in index. \\\n+                  File has probably been created, deleted or renamed, \\\n+                  in a different commit.\"]\"\n+      set diffok \"false\"\n+    }\n+   } else {\n+    set difffromfile [file join $diffdir \"\\[$diffidfrom\\] [file tail $flist_menu_file]\"]\n+    if {[catch {exec git show $diffidfrom:$flist_menu_file > $difffromfile} err]} {\n+      error_popup \"\\\"$flist_menu_file\\\" [mc \"cannot be found in revision\"] \\\n+                  $diffidfrom. [mc \"File has probably been created, \\\n+                  deleted or renamed, in a different commit.\"]\"\n+      set diffok \"false\"\n+    }\n+  }\n+\n+  if {$diffok} {\n+    # here we don't use shellquote because \\ and everything must be escaped and not enclosed between ''\n+    set quotedextdifftool \\\"[string map {\\\" \\\\\\\" \\\\ \\\\\\\\ \\  \\\\\\ } $extdifftool]\\\"\n+    set cmd [concat | $quotedextdifftool [shellarglist [list $difffromfile $difftofile]]]\n+    if {[catch {set fl [open $cmd]} err]} {\n+      file delete -force [ file join $gitktmpdir $diffnum ]\n+      error_popup [mc \"$extdifftool command failed: $err\"]\n+    } else {\n+      fconfigure $fl -blocking 0\n+      filerun $fl [list file delete -force [file join $gitktmpdir $diffnum]]\n+    }\n+  }\n+}\n+\n # Functions for adding and removing shell-type quoting\n \n proc shellquote {str} {\n@@ -7802,9 +7910,13 @@ proc showtag {tag isnew} {\n \n proc doquit {} {\n     global stopped\n+    global gitktmpdir\n+\n     set stopped 100\n     savestuff .\n     destroy .\n+\n+    catch {file delete -force $gitktmpdir}\n }\n \n proc mkfontdisp {font top which} {\n@@ -7933,7 +8045,7 @@ proc doprefs {} {\n     global maxwidth maxgraphpct\n     global oldprefs prefstop showneartags showlocalchanges\n     global bgcolor fgcolor ctext diffcolors selectbgcolor\n-    global tabstop limitdiffs\n+    global tabstop limitdiffs extdifftool\n \n     set top .gitkprefs\n     set prefstop $top\n@@ -7980,6 +8092,13 @@ proc doprefs {} {\n     pack $top.ldiff.b $top.ldiff.l -side left\n     grid x $top.ldiff -sticky w\n \n+    entry $top.extdifft -textvariable extdifftool\n+    button $top.extdiffb -text [mc \"External diff tool\" ] -font optionfont \\\n+  -command {set extdifftool [tk_getOpenFile -title \"External diff tool\" \\\n+  -multiple \"false\"]}\n+    grid x $top.extdiffb $top.extdifft -sticky w\n+\n+\n     label $top.cdisp -text [mc \"Colors: press to choose\"]\n     grid $top.cdisp - -sticky w -pady 10\n     label $top.bg -padx 40 -relief sunk -background $bgcolor\n@@ -8454,6 +8573,8 @@ set showlocalchanges 1\n set limitdiffs 1\n set datetimeformat \"%Y-%m-%d %H:%M:%S\"\n \n+set extdifftool \"meld\"\n+\n set colors {green red blue magenta darkgrey brown orange}\n set bgcolor white\n set fgcolor black\n@@ -8507,6 +8628,9 @@ if {![file isdirectory $gitdir]} {\n     exit 1\n }\n \n+set gitktmpdir [file normalize [file join $gitdir \"..\" [format \".gitk-tmp.%s\" [pid]]]]\n+file mkdir $gitktmpdir\n+\n set mergeonly 0\n set revtreeargs {}\n set cmdline_files {}\n-- \n1.5.3.8\n"},{"id":"66990","messageId":"F0FADF3C-E33F-4BA9-B014-312F91CFA7F2@zib.de","threadId":"11806","inReplyTo":"1201795202.11689.9.camel-+NgBfe53rIlR1FB8S1TzorOUoyqYp7Dr@public.gmane.org","subject":"Re: [PATCH] gitk : External diff viewer.","fromName":"Steffen Prohaska","fromEmail":"prohaska-wjoc1khpmeg@public.gmane.org","sentAt":"2008-01-31T17:50:38Z","receivedAt":"2008-01-31T17:50:38Z","isPatch":true,"sender":{"key":"prohaska-wjoc1khpmeg@public.gmane.org","avatar":null},"body":"\n\nOn Jan 31, 2008, at 5:00 PM, Thomas Arcila wrote:\n\n> Right click on patched file list view gives \"External diff\" popup  \n> menu entry,\n> launching selected external diff tool.\n> The diff tool is configurable through Edit/Preference/External diff  \n> tool.\n>\n> Signed-off-by: Thomas Arcila <tarcila-s5SjKpinsOs@public.gmane.org>\n> ---\n>\n> Hi,\n>\n> Here is a patch to gitk that allows to run an external diff viewer.\n> It can be configured in Edit/Preferences/External diff tool.\n>\n> To see the diff between two files:\n> - select revisions to diff\n> - right click on a file in the patched files list view\n> - choose \"External diff\"\n>\n> Any feedback is welcome.\n\nVarious combinations of showing diffs between index, work tree, and  \ncommits\nwork for me.  I haven't yet found any problems.\n\n\tSteffen\n"}]}