Skip to content

Commit 42bf8a5

Browse files
committed
Merge branch 'master' of https://github.com/j6t/gitk
* '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"
2 parents 6ab38b7 + 776223c commit 42bf8a5

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

gitk-git/gitk

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,12 +2131,14 @@ proc ttk_toplevel {w args} {
21312131
return $w
21322132
}
21332133
2134-
proc make_transient {window origin} {
2134+
proc make_transient {window origin {geometry ""}} {
21352135
wm transient $window $origin
21362136
2137-
# Windows fails to place transient windows normally, so
2138-
# schedule a callback to center them on the parent.
2139-
if {[tk windowingsystem] eq {win32}} {
2137+
if {$geometry ne ""} {
2138+
after idle [list wm geometry $window $geometry]
2139+
} elseif {[tk windowingsystem] eq {win32}} {
2140+
# Windows fails to place transient windows normally, so
2141+
# schedule a callback to center them on the parent.
21402142
after idle [list tk::PlaceWindow $window widget $origin]
21412143
}
21422144
}
@@ -2723,17 +2725,9 @@ proc makewindow {} {
27232725
.pwbottom add .bright
27242726
.ctop add .pwbottom
27252727
2726-
# restore window width & height if known
2728+
# restore window position if known
27272729
if {[info exists geometry(main)]} {
2728-
if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2729-
if {$w > [winfo screenwidth .]} {
2730-
set w [winfo screenwidth .]
2731-
}
2732-
if {$h > [winfo screenheight .]} {
2733-
set h [winfo screenheight .]
2734-
}
2735-
wm geometry . "${w}x$h"
2736-
}
2730+
wm geometry . "$geometry(main)"
27372731
}
27382732
27392733
if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
@@ -3073,6 +3067,11 @@ proc savestuff {w} {
30733067
puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
30743068
puts $f "set geometry(botwidth) [winfo width .bleft]"
30753069
puts $f "set geometry(botheight) [winfo height .bleft]"
3070+
unset -nocomplain geometry
3071+
global geometry
3072+
if {[info exists geometry(showrefs)]} {
3073+
puts $f "set geometry(showrefs) $geometry(showrefs)"
3074+
}
30763075
30773076
array set view_save {}
30783077
array set views {}
@@ -3788,6 +3787,34 @@ proc external_diff_get_one_file {diffid filename diffdir} {
37883787
"revision $diffid"]
37893788
}
37903789
3790+
proc check_for_renames_in_diff {filepath} { # renames
3791+
global difffilestart ctext
3792+
3793+
set filename [file tail $filepath]
3794+
set renames {}
3795+
3796+
foreach loc $difffilestart {
3797+
set loclineend [string map {.0 .end} $loc]
3798+
set fromlineloc "$loc + 2 lines"
3799+
set tolineloc "$loc + 3 lines"
3800+
set renfromline [$ctext get $fromlineloc [string map {.0 .end} $fromlineloc]]
3801+
set rentoline [$ctext get $tolineloc [string map {.0 .end} $tolineloc]]
3802+
if {[string equal -length 12 "rename from " $renfromline]
3803+
&& [string equal -length 10 "rename to " $rentoline]} {
3804+
set renfrom [string range $renfromline 12 end]
3805+
set rento [string range $rentoline 10 end]
3806+
if {[string first $filename $renfrom] != -1
3807+
|| [string first $filename $rento] != -1} {
3808+
lappend renames $renfrom
3809+
lappend renames $rento
3810+
break
3811+
}
3812+
}
3813+
}
3814+
3815+
return $renames
3816+
}
3817+
37913818
proc external_diff {} {
37923819
global nullid nullid2
37933820
global flist_menu_file
@@ -3818,8 +3845,16 @@ proc external_diff {} {
38183845
if {$diffdir eq {}} return
38193846
38203847
# gather files to diff
3821-
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3822-
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3848+
set renames [check_for_renames_in_diff $flist_menu_file]
3849+
set renamefrom [lindex $renames 0]
3850+
set renameto [lindex $renames 1]
3851+
if {$renamefrom ne {} && $renameto ne {}} {
3852+
set difffromfile [external_diff_get_one_file $diffidfrom $renamefrom $diffdir]
3853+
set difftofile [external_diff_get_one_file $diffidto $renameto $diffdir]
3854+
} else {
3855+
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3856+
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3857+
}
38233858
38243859
if {$difffromfile ne {} && $difftofile ne {}} {
38253860
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
@@ -8296,7 +8331,7 @@ proc parseblobdiffline {ids line} {
82968331
if {![regexp {^diff (--cc|--git) } $line m type]} {
82978332
set line [convertfrom utf-8 $line]
82988333
$ctext insert end "$line\n" hunksep
8299-
continue
8334+
return
83008335
}
83018336
# start of a new file
83028337
set diffinhdr 1
@@ -8401,13 +8436,21 @@ proc parseblobdiffline {ids line} {
84018436
if {$i >= 0} {
84028437
setinlist difffilestart $i $curdiffstart
84038438
}
8439+
set line "rename from $fname"
84048440
} elseif {![string compare -length 10 $line "rename to "] ||
84058441
![string compare -length 8 $line "copy to "]} {
84068442
set fname [string range $line [expr 4 + [string first " to " $line] ] end]
84078443
if {[string index $fname 0] eq "\""} {
84088444
set fname [lindex $fname 0]
84098445
}
84108446
makediffhdr $fname $ids
8447+
set line "[lindex $line 0] to $fname"
8448+
} elseif {![string compare -length 10 $line "copy from "]} {
8449+
set fname [string range $line 10 end]
8450+
if {[string index $fname 0] eq "\""} {
8451+
set fname [lindex $fname 0]
8452+
}
8453+
set line "copy from $fname"
84118454
} elseif {[string compare -length 3 $line "---"] == 0} {
84128455
# do nothing
84138456
return
@@ -10160,6 +10203,7 @@ proc rmbranch {} {
1016010203
proc showrefs {} {
1016110204
global showrefstop bgcolor fgcolor selectbgcolor
1016210205
global bglist fglist reflistfilter reflist maincursor
10206+
global geometry
1016310207
1016410208
set top .showrefs
1016510209
set showrefstop $top
@@ -10170,7 +10214,11 @@ proc showrefs {} {
1017010214
}
1017110215
ttk_toplevel $top
1017210216
wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
10173-
make_transient $top .
10217+
if {[info exists geometry(showrefs)]} {
10218+
make_transient $top . $geometry(showrefs)
10219+
} else {
10220+
make_transient $top .
10221+
}
1017410222
text $top.list -background $bgcolor -foreground $fgcolor \
1017510223
-selectbackground $selectbgcolor -font mainfont \
1017610224
-xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
@@ -10206,6 +10254,9 @@ proc showrefs {} {
1020610254
bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
1020710255
set reflist {}
1020810256
refill_reflist
10257+
# avoid <Configure> being bound to child windows
10258+
bindtags $top [linsert [bindtags $top] 1 bind$top]
10259+
bind bind$top <Configure> {set geometry(showrefs) [wm geometry %W]}
1020910260
}
1021010261
1021110262
proc sel_reflist {w x y} {

0 commit comments

Comments
 (0)