* 'master' of https://github.com/j6t/gitk:
  gitk: add external diff file rename detection
  gitk: show unescaped file names on 'rename' and 'copy' lines
  gitk: fix a 'continue' statement outside a loop to 'return'
  gitk: persist position and size of the Tags and Heads window
  Revert "gitk: Only restore window size from ~/.gitk, not position"
This commit is contained in:
Junio C Hamano
2025-11-26 09:35:09 -08:00

View File

@@ -2131,12 +2131,14 @@ proc ttk_toplevel {w args} {
return $w return $w
} }
proc make_transient {window origin} { proc make_transient {window origin {geometry ""}} {
wm transient $window $origin wm transient $window $origin
# Windows fails to place transient windows normally, so if {$geometry ne ""} {
# schedule a callback to center them on the parent. after idle [list wm geometry $window $geometry]
if {[tk windowingsystem] eq {win32}} { } elseif {[tk windowingsystem] eq {win32}} {
# Windows fails to place transient windows normally, so
# schedule a callback to center them on the parent.
after idle [list tk::PlaceWindow $window widget $origin] after idle [list tk::PlaceWindow $window widget $origin]
} }
} }
@@ -2723,17 +2725,9 @@ proc makewindow {} {
.pwbottom add .bright .pwbottom add .bright
.ctop add .pwbottom .ctop add .pwbottom
# restore window width & height if known # restore window position if known
if {[info exists geometry(main)]} { if {[info exists geometry(main)]} {
if {[scan $geometry(main) "%dx%d" w h] >= 2} { wm geometry . "$geometry(main)"
if {$w > [winfo screenwidth .]} {
set w [winfo screenwidth .]
}
if {$h > [winfo screenheight .]} {
set h [winfo screenheight .]
}
wm geometry . "${w}x$h"
}
} }
if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} { if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
@@ -3073,6 +3067,11 @@ proc savestuff {w} {
puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\"" puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
puts $f "set geometry(botwidth) [winfo width .bleft]" puts $f "set geometry(botwidth) [winfo width .bleft]"
puts $f "set geometry(botheight) [winfo height .bleft]" puts $f "set geometry(botheight) [winfo height .bleft]"
unset -nocomplain geometry
global geometry
if {[info exists geometry(showrefs)]} {
puts $f "set geometry(showrefs) $geometry(showrefs)"
}
array set view_save {} array set view_save {}
array set views {} array set views {}
@@ -3788,6 +3787,34 @@ proc external_diff_get_one_file {diffid filename diffdir} {
"revision $diffid"] "revision $diffid"]
} }
proc check_for_renames_in_diff {filepath} { # renames
global difffilestart ctext
set filename [file tail $filepath]
set renames {}
foreach loc $difffilestart {
set loclineend [string map {.0 .end} $loc]
set fromlineloc "$loc + 2 lines"
set tolineloc "$loc + 3 lines"
set renfromline [$ctext get $fromlineloc [string map {.0 .end} $fromlineloc]]
set rentoline [$ctext get $tolineloc [string map {.0 .end} $tolineloc]]
if {[string equal -length 12 "rename from " $renfromline]
&& [string equal -length 10 "rename to " $rentoline]} {
set renfrom [string range $renfromline 12 end]
set rento [string range $rentoline 10 end]
if {[string first $filename $renfrom] != -1
|| [string first $filename $rento] != -1} {
lappend renames $renfrom
lappend renames $rento
break
}
}
}
return $renames
}
proc external_diff {} { proc external_diff {} {
global nullid nullid2 global nullid nullid2
global flist_menu_file global flist_menu_file
@@ -3818,8 +3845,16 @@ proc external_diff {} {
if {$diffdir eq {}} return if {$diffdir eq {}} return
# gather files to diff # gather files to diff
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir] set renames [check_for_renames_in_diff $flist_menu_file]
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir] set renamefrom [lindex $renames 0]
set renameto [lindex $renames 1]
if {$renamefrom ne {} && $renameto ne {}} {
set difffromfile [external_diff_get_one_file $diffidfrom $renamefrom $diffdir]
set difftofile [external_diff_get_one_file $diffidto $renameto $diffdir]
} else {
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 {}} { if {$difffromfile ne {} && $difftofile ne {}} {
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile] set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
@@ -8296,7 +8331,7 @@ proc parseblobdiffline {ids line} {
if {![regexp {^diff (--cc|--git) } $line m type]} { if {![regexp {^diff (--cc|--git) } $line m type]} {
set line [convertfrom utf-8 $line] set line [convertfrom utf-8 $line]
$ctext insert end "$line\n" hunksep $ctext insert end "$line\n" hunksep
continue return
} }
# start of a new file # start of a new file
set diffinhdr 1 set diffinhdr 1
@@ -8401,6 +8436,7 @@ proc parseblobdiffline {ids line} {
if {$i >= 0} { if {$i >= 0} {
setinlist difffilestart $i $curdiffstart setinlist difffilestart $i $curdiffstart
} }
set line "rename from $fname"
} elseif {![string compare -length 10 $line "rename to "] || } elseif {![string compare -length 10 $line "rename to "] ||
![string compare -length 8 $line "copy to "]} { ![string compare -length 8 $line "copy to "]} {
set fname [string range $line [expr 4 + [string first " to " $line] ] end] set fname [string range $line [expr 4 + [string first " to " $line] ] end]
@@ -8408,6 +8444,13 @@ proc parseblobdiffline {ids line} {
set fname [lindex $fname 0] set fname [lindex $fname 0]
} }
makediffhdr $fname $ids makediffhdr $fname $ids
set line "[lindex $line 0] to $fname"
} elseif {![string compare -length 10 $line "copy from "]} {
set fname [string range $line 10 end]
if {[string index $fname 0] eq "\""} {
set fname [lindex $fname 0]
}
set line "copy from $fname"
} elseif {[string compare -length 3 $line "---"] == 0} { } elseif {[string compare -length 3 $line "---"] == 0} {
# do nothing # do nothing
return return
@@ -10160,6 +10203,7 @@ proc rmbranch {} {
proc showrefs {} { proc showrefs {} {
global showrefstop bgcolor fgcolor selectbgcolor global showrefstop bgcolor fgcolor selectbgcolor
global bglist fglist reflistfilter reflist maincursor global bglist fglist reflistfilter reflist maincursor
global geometry
set top .showrefs set top .showrefs
set showrefstop $top set showrefstop $top
@@ -10170,7 +10214,11 @@ proc showrefs {} {
} }
ttk_toplevel $top ttk_toplevel $top
wm title $top [mc "Tags and heads: %s" [file tail [pwd]]] wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
make_transient $top . if {[info exists geometry(showrefs)]} {
make_transient $top . $geometry(showrefs)
} else {
make_transient $top .
}
text $top.list -background $bgcolor -foreground $fgcolor \ text $top.list -background $bgcolor -foreground $fgcolor \
-selectbackground $selectbgcolor -font mainfont \ -selectbackground $selectbgcolor -font mainfont \
-xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \ -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
@@ -10206,6 +10254,9 @@ proc showrefs {} {
bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break} bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
set reflist {} set reflist {}
refill_reflist refill_reflist
# avoid <Configure> being bound to child windows
bindtags $top [linsert [bindtags $top] 1 bind$top]
bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
} }
proc sel_reflist {w x y} { proc sel_reflist {w x y} {