git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] gitk: Use git-difftool for external diffs

From
David Aguilar <davvid@gmail.com>
Date
Mar 28, 2010, 00:01 UTC
Message-ID
<1269734510-11503-1-git-send-email-davvid@gmail.com>
In-Reply-To
<1269726316-30443-1-git-send-email-davvid@gmail.com>

This teaches gitk about git-difftool. A benefit of this change is that gitk's external diff feature now works with read-only repositories.

Signed-off-by: David Aguilar <davvid@gmail.com>
---

Differences since the first patch: This one doesn't pass "--gui" to difftool.

"--gui" was mistakenly included in the first patch and consequently uncovered a bug in difftool.

 gitk |   58 +++++++++-------------------------------------------------
 1 files changed, 9 insertions(+), 49 deletions(-)
diff --git a/gitk b/gitk
index 1f36a3e..46c103e 100755
--- a/gitk
+++ b/gitk
@@ -3317,39 +3317,6 @@ proc gitknewtmpdir {} {
     return $diffdir
 }
 
-proc save_file_from_commit {filename output what} {
-    global nullfile
-
-    if {[catch {exec git show $filename -- > $output} err]} {
-	if {[string match "fatal: bad revision *" $err]} {
-	    return $nullfile
-	}
-	error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
-	return {}
-    }
-    return $output
-}
-
-proc external_diff_get_one_file {diffid filename diffdir} {
-    global nullid nullid2 nullfile
-    global gitdir
-
-    if {$diffid == $nullid} {
-        set difffile [file join [file dirname $gitdir] $filename]
-	if {[file exists $difffile]} {
-	    return $difffile
-	}
-	return $nullfile
-    }
-    if {$diffid == $nullid2} {
-        set difffile [file join $diffdir "\[index\] [file tail $filename]"]
-        return [save_file_from_commit :$filename $difffile index]
-    }
-    set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
-    return [save_file_from_commit $diffid:$filename $difffile \
-	       "revision $diffid"]
-}
-
 proc external_diff {} {
     global nullid nullid2
     global flist_menu_file
@@ -3375,23 +3342,16 @@ proc external_diff {} {
         set diffidto [lindex $diffids 1]
     }
 
-    # make sure that several diffs wont collide
-    set diffdir [gitknewtmpdir]
-    if {$diffdir eq {}} return
-
-    # gather files to diff
-    set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
-    set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
-
-    if {$difffromfile ne {} && $difftofile ne {}} {
-        set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
-        if {[catch {set fl [open |$cmd r]} err]} {
-            file delete -force $diffdir
-            error_popup "$extdifftool: [mc "command failed:"] $err"
-        } else {
-            fconfigure $fl -blocking 0
-            filerun $fl [list delete_at_eof $fl $diffdir]
+    if {$flist_menu_file ne {}} {
+        set cmd [list "git" "difftool" "--no-prompt" "--extcmd" $extdifftool]
+        if {$diffidfrom ne $nullid && $diffidfrom ne $nullid2} {
+            lappend cmd $diffidfrom
+        }
+        if {$diffidto ne $nullid && $diffidto ne $nullid2} {
+            lappend cmd $diffidto
         }
+        lappend cmd "--" $flist_menu_file
+        eval exec $cmd &
     }
 }
 
-- 
1.7.0.3.292.gbeff
Previous: David AguilarNext: David Aguilar
Message 2 of 14 in “gitk: Use git-difftool for external diffs”
  1. gitk: Use git-difftool for external diffsDavid Aguilar, Mar 27, 2010
  2. gitk: Use git-difftool for external diffsDavid Aguilar, Mar 28, 2010
  3. gitk: Use git-difftool for external diffsDavid Aguilar, Mar 28, 2010
  4. Markus HeidelbergMar 28, 2010
  5. David AguilarMar 31, 2010
  6. gitk: Use git-difftool for external diffsDavid Aguilar, Mar 31, 2010
  7. Markus HeidelbergApr 2, 2010
  8. David AguilarApr 8, 2010
  9. gitk: Use git-difftool for external diffs when git >= 1.7.0David Aguilar, Apr 8, 2010
  10. Paul MackerrasApr 17, 2010
  11. David AguilarApr 17, 2010
  12. Jay SoffianApr 18, 2010
  13. gitk: Use git-difftool for external diffs when availableDavid Aguilar, Apr 20, 2010
  14. David AguilarJun 8, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.