gitk: Move "pickaxe" find function to highlight facility
This removes the "Files" and "Pickaxe" parts of the "Find" function, so Find is now just about searching the commit data. We now highlight the commits that match the Find string (without having to press Find), and have a drop-down menu for selecting whether the git-diff-tree based highlighting is done on paths or on adding/removing a given string. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
May 26, 2006 at 10:43 UTC
60f7a7dc4904ba4baab44b70e2675a01e6172f54
1 file changed
+59
-309
gitk
+59
-309
@@ -383,7 +383,7 @@ proc makewindow {} {
383
global entries sha1entry sha1string sha1but
384
global maincursor textcursor curtextcursor
385
global rowctxmenu mergemax
386
- global highlight_files highlight_names
386
+ global highlight_files gdttype
387
global searchstring sstring
388
389
menu .bar
@@ -498,26 +498,33 @@ proc makewindow {} {
498
set fstring .ctop.top.bar.findstring
499
lappend entries $fstring
500
entry $fstring -width 30 -font $textfont -textvariable findstring
501
+ trace add variable findstring write find_change
502
pack $fstring -side left -expand 1 -fill x
503
set findtype Exact
504
set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
505
findtype Exact IgnCase Regexp]
506
+ trace add variable findtype write find_change
507
.ctop.top.bar.findtype configure -font $uifont
508
.ctop.top.bar.findtype.menu configure -font $uifont
509
set findloc "All fields"
510
tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
509
- Comments Author Committer Files Pickaxe
511
+ Comments Author Committer
512
+ trace add variable findloc write find_change
513
.ctop.top.bar.findloc configure -font $uifont
514
.ctop.top.bar.findloc.menu configure -font $uifont
512
-
515
pack .ctop.top.bar.findloc -side right
516
pack .ctop.top.bar.findtype -side right
515
- # for making sure type==Exact whenever loc==Pickaxe
516
- trace add variable findloc write findlocchange
517
518
- label .ctop.top.lbar.flabel -text "Highlight: Commits touching paths:" \
518
+ label .ctop.top.lbar.flabel -text "Highlight: Commits " \
519
-font $uifont
520
pack .ctop.top.lbar.flabel -side left -fill y
521
+ set gdttype "touching paths:"
522
+ set gm [tk_optionMenu .ctop.top.lbar.gdttype gdttype "touching paths:" \
523
+ "adding/removing string:"]
524
+ trace add variable gdttype write hfiles_change
525
+ $gm conf -font $uifont
526
+ .ctop.top.lbar.gdttype conf -font $uifont
527
+ pack .ctop.top.lbar.gdttype -side left -fill y
528
entry .ctop.top.lbar.fent -width 25 -font $textfont \
529
-textvariable highlight_files
530
trace add variable highlight_files write hfiles_change
@@ -531,14 +538,6 @@ proc makewindow {} {
538
$viewhlmenu conf -font $uifont
539
.ctop.top.lbar.vhl conf -font $uifont
540
pack .ctop.top.lbar.vhl -side left -fill y
534
- label .ctop.top.lbar.alabel -text " OR author/committer:" \
535
- -font $uifont
536
- pack .ctop.top.lbar.alabel -side left -fill y
537
- entry .ctop.top.lbar.aent -width 20 -font $textfont \
538
- -textvariable highlight_names
539
- trace add variable highlight_names write hnames_change
540
- lappend entries .ctop.top.lbar.aent
541
- pack .ctop.top.lbar.aent -side right -fill x -expand 1
541
542
panedwindow .ctop.cdet -orient horizontal
543
.ctop add .ctop.cdet
@@ -1807,12 +1806,17 @@ proc makepatterns {l} {
1806
}
1807
1808
proc do_file_hl {serial} {
1810
- global highlight_files filehighlight highlight_paths
1809
+ global highlight_files filehighlight highlight_paths gdttype
1810
1812
- if {[catch {set paths [shellsplit $highlight_files]}]} return
1813
- set highlight_paths [makepatterns $paths]
1814
- highlight_filelist
1815
- set cmd [concat | git-diff-tree -r -s --stdin -- $paths]
1811
+ if {$gdttype eq "touching paths:"} {
1812
+ if {[catch {set paths [shellsplit $highlight_files]}]} return
1813
+ set highlight_paths [makepatterns $paths]
1814
+ highlight_filelist
1815
+ set gdtargs [concat -- $paths]
1816
+ } else {
1817
+ set gdtargs [list "-S$highlight_files"]
1818
+ }
1819
+ set cmd [concat | git-diff-tree -r -s --stdin $gdtargs]
1820
set filehighlight [open $cmd r+]
1821
fconfigure $filehighlight -blocking 0
1822
fileevent $filehighlight readable readfhighlight
@@ -1859,8 +1863,9 @@ proc readfhighlight {} {
1863
set fhighlights($row) 1
1864
}
1865
1862
-proc hnames_change {name ix op} {
1863
- global highlight_names nhighlights nhl_names mainfont
1866
+proc find_change {name ix op} {
1867
+ global nhighlights mainfont
1868
+ global findstring findpattern findtype
1869
1870
# delete previous highlights, if any
1871
set rows [array names nhighlights]
@@ -1873,30 +1878,41 @@ proc hnames_change {name ix op} {
1878
unset nhighlights
1879
unbolden $rows
1880
}
1876
- if {[catch {set nhl_names [shellsplit $highlight_names]}]} {
1877
- set nhl_names {}
1878
- return
1881
+ if {$findtype ne "Regexp"} {
1882
+ set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
1883
+ $findstring]
1884
+ set findpattern "*$e*"
1885
}
1886
drawvisible
1887
}
1888
1883
-proc asknamehighlight {row id} {
1884
- global nhl_names nhighlights commitinfo iddrawn mainfont
1889
+proc askfindhighlight {row id} {
1890
+ global nhighlights commitinfo iddrawn mainfont
1891
+ global findstring findtype findloc findpattern
1892
1893
if {![info exists commitinfo($id)]} {
1894
getcommit $id
1895
}
1896
+ set info $commitinfo($id)
1897
set isbold 0
1890
- set author [lindex $commitinfo($id) 1]
1891
- set committer [lindex $commitinfo($id) 3]
1892
- foreach name $nhl_names {
1893
- set pattern "*$name*"
1894
- if {[string match -nocase $pattern $author]} {
1895
- set isbold 2
1896
- break
1898
+ set fldtypes {Headline Author Date Committer CDate Comments}
1899
+ foreach f $info ty $fldtypes {
1900
+ if {$findloc ne "All fields" && $findloc ne $ty} {
1901
+ continue
1902
}
1898
- if {!$isbold && [string match -nocase $pattern $committer]} {
1899
- set isbold 1
1903
+ if {$findtype eq "Regexp"} {
1904
+ set doesmatch [regexp $findstring $f]
1905
+ } elseif {$findtype eq "IgnCase"} {
1906
+ set doesmatch [string match -nocase $findpattern $f]
1907
+ } else {
1908
+ set doesmatch [string match $findpattern $f]
1909
+ }
1910
+ if {$doesmatch} {
1911
+ if {$ty eq "Author"} {
1912
+ set isbold 2
1913
+ } else {
1914
+ set isbold 1
1915
+ }
1916
}
1917
}
1918
if {[info exists iddrawn($id)]} {
@@ -2681,7 +2697,7 @@ proc drawcmitrow {row} {
2697
global displayorder rowidlist
2698
global idrangedrawn iddrawn
2699
global commitinfo parentlist numcommits
2684
- global filehighlight fhighlights nhl_names nhighlights
2700
+ global filehighlight fhighlights findstring nhighlights
2701
global hlview vhighlights
2702
2703
if {$row >= $numcommits} return
@@ -2709,8 +2725,8 @@ proc drawcmitrow {row} {
2725
if {[info exists filehighlight] && ![info exists fhighlights($row)]} {
2726
askfilehighlight $row $id
2727
}
2712
- if {$nhl_names ne {} && ![info exists nhighlights($row)]} {
2713
- asknamehighlight $row $id
2728
+ if {$findstring ne {} && ![info exists nhighlights($row)]} {
2729
+ askfindhighlight $row $id
2730
}
2731
if {[info exists iddrawn($id)]} return
2732
set col [lsearch -exact [lindex $rowidlist $row] $id]
@@ -3073,10 +3089,6 @@ proc dofind {} {
3089
unmarkmatches
3090
focus .
3091
set matchinglines {}
3076
- if {$findloc == "Pickaxe"} {
3077
- findpatches
3078
- return
3079
- }
3092
if {$findtype == "IgnCase"} {
3093
set foundstring [string tolower $findstring]
3094
} else {
@@ -3086,17 +3098,13 @@ proc dofind {} {
3098
if {$foundstrlen == 0} return
3099
regsub -all {[*?\[\\]} $foundstring {\\&} matchstring
3100
set matchstring "*$matchstring*"
3089
- if {$findloc == "Files"} {
3090
- findfiles
3091
- return
3092
- }
3101
if {![info exists selectedline]} {
3102
set oldsel -1
3103
} else {
3104
set oldsel $selectedline
3105
}
3106
set didsel 0
3099
- set fldtypes {Headline Author Date Committer CDate Comment}
3107
+ set fldtypes {Headline Author Date Committer CDate Comments}
3108
set l -1
3109
foreach id $displayorder {
3110
set d $commitdata($id)
@@ -3199,18 +3207,6 @@ proc findprev {} {
3207
}
3208
}
3209
3202
-proc findlocchange {name ix op} {
3203
- global findloc findtype findtypemenu
3204
- if {$findloc == "Pickaxe"} {
3205
- set findtype Exact
3206
- set state disabled
3207
- } else {
3208
- set state normal
3209
- }
3210
- $findtypemenu entryconf 1 -state $state
3211
- $findtypemenu entryconf 2 -state $state
3212
-}
3213
-
3210
proc stopfindproc {{done 0}} {
3211
global findprocpid findprocfile findids
3212
global ctext findoldcursor phase maincursor textcursor
@@ -3228,247 +3224,6 @@ proc stopfindproc {{done 0}} {
3224
notbusy find
3225
}
3226
3231
-proc findpatches {} {
3232
- global findstring selectedline numcommits
3233
- global findprocpid findprocfile
3234
- global finddidsel ctext displayorder findinprogress
3235
- global findinsertpos
3236
-
3237
- if {$numcommits == 0} return
3238
-
3239
- # make a list of all the ids to search, starting at the one
3240
- # after the selected line (if any)
3241
- if {[info exists selectedline]} {
3242
- set l $selectedline
3243
- } else {
3244
- set l -1
3245
- }
3246
- set inputids {}
3247
- for {set i 0} {$i < $numcommits} {incr i} {
3248
- if {[incr l] >= $numcommits} {
3249
- set l 0
3250
- }
3251
- append inputids [lindex $displayorder $l] "\n"
3252
- }
3253
-
3254
- if {[catch {
3255
- set f [open [list | git-diff-tree --stdin -s -r -S$findstring \
3256
- << $inputids] r]
3257
- } err]} {
3258
- error_popup "Error starting search process: $err"
3259
- return
3260
- }
3261
-
3262
- set findinsertpos end
3263
- set findprocfile $f
3264
- set findprocpid [pid $f]
3265
- fconfigure $f -blocking 0
3266
- fileevent $f readable readfindproc
3267
- set finddidsel 0
3268
- nowbusy find
3269
- set findinprogress 1
3270
-}
3271
-
3272
-proc readfindproc {} {
3273
- global findprocfile finddidsel
3274
- global commitrow matchinglines findinsertpos curview
3275
-
3276
- set n [gets $findprocfile line]
3277
- if {$n < 0} {
3278
- if {[eof $findprocfile]} {
3279
- stopfindproc 1
3280
- if {!$finddidsel} {
3281
- bell
3282
- }
3283
- }
3284
- return
3285
- }
3286
- if {![regexp {^[0-9a-f]{40}} $line id]} {
3287
- error_popup "Can't parse git-diff-tree output: $line"
3288
- stopfindproc
3289
- return
3290
- }
3291
- if {![info exists commitrow($curview,$id)]} {
3292
- puts stderr "spurious id: $id"
3293
- return
3294
- }
3295
- set l $commitrow($curview,$id)
3296
- insertmatch $l $id
3297
-}
3298
-
3299
-proc insertmatch {l id} {
3300
- global matchinglines findinsertpos finddidsel
3301
-
3302
- if {$findinsertpos == "end"} {
3303
- if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
3304
- set matchinglines [linsert $matchinglines 0 $l]
3305
- set findinsertpos 1
3306
- } else {
3307
- lappend matchinglines $l
3308
- }
3309
- } else {
3310
- set matchinglines [linsert $matchinglines $findinsertpos $l]
3311
- incr findinsertpos
3312
- }
3313
- markheadline $l $id
3314
- if {!$finddidsel} {
3315
- findselectline $l
3316
- set finddidsel 1
3317
- }
3318
-}
3319
-
3320
-proc findfiles {} {
3321
- global selectedline numcommits displayorder ctext
3322
- global ffileline finddidsel parentlist
3323
- global findinprogress findstartline findinsertpos
3324
- global treediffs fdiffid fdiffsneeded fdiffpos
3325
- global findmergefiles
3326
-
3327
- if {$numcommits == 0} return
3328
-
3329
- if {[info exists selectedline]} {
3330
- set l [expr {$selectedline + 1}]
3331
- } else {
3332
- set l 0
3333
- }
3334
- set ffileline $l
3335
- set findstartline $l
3336
- set diffsneeded {}
3337
- set fdiffsneeded {}
3338
- while 1 {
3339
- set id [lindex $displayorder $l]
3340
- if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
3341
- if {![info exists treediffs($id)]} {
3342
- append diffsneeded "$id\n"
3343
- lappend fdiffsneeded $id
3344
- }
3345
- }
3346
- if {[incr l] >= $numcommits} {
3347
- set l 0
3348
- }
3349
- if {$l == $findstartline} break
3350
- }
3351
-
3352
- # start off a git-diff-tree process if needed
3353
- if {$diffsneeded ne {}} {
3354
- if {[catch {
3355
- set df [open [list | git-diff-tree -r --stdin << $diffsneeded] r]
3356
- } err ]} {
3357
- error_popup "Error starting search process: $err"
3358
- return
3359
- }
3360
- catch {unset fdiffid}
3361
- set fdiffpos 0
3362
- fconfigure $df -blocking 0
3363
- fileevent $df readable [list readfilediffs $df]
3364
- }
3365
-
3366
- set finddidsel 0
3367
- set findinsertpos end
3368
- set id [lindex $displayorder $l]
3369
- nowbusy find
3370
- set findinprogress 1
3371
- findcont
3372
- update
3373
-}
3374
-
3375
-proc readfilediffs {df} {
3376
- global findid fdiffid fdiffs
3377
-
3378
- set n [gets $df line]
3379
- if {$n < 0} {
3380
- if {[eof $df]} {
3381
- donefilediff
3382
- if {[catch {close $df} err]} {
3383
- stopfindproc
3384
- bell
3385
- error_popup "Error in git-diff-tree: $err"
3386
- } elseif {[info exists findid]} {
3387
- set id $findid
3388
- stopfindproc
3389
- bell
3390
- error_popup "Couldn't find diffs for $id"
3391
- }
3392
- }
3393
- return
3394
- }
3395
- if {[regexp {^([0-9a-f]{40})$} $line match id]} {
3396
- # start of a new string of diffs
3397
- donefilediff
3398
- set fdiffid $id
3399
- set fdiffs {}
3400
- } elseif {[string match ":*" $line]} {
3401
- lappend fdiffs [lindex $line 5]
3402
- }
3403
-}
3404
-
3405
-proc donefilediff {} {
3406
- global fdiffid fdiffs treediffs findid
3407
- global fdiffsneeded fdiffpos
3408
-
3409
- if {[info exists fdiffid]} {
3410
- while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffid
3411
- && $fdiffpos < [llength $fdiffsneeded]} {
3412
- # git-diff-tree doesn't output anything for a commit
3413
- # which doesn't change anything
3414
- set nullid [lindex $fdiffsneeded $fdiffpos]
3415
- set treediffs($nullid) {}
3416
- if {[info exists findid] && $nullid eq $findid} {
3417
- unset findid
3418
- findcont
3419
- }
3420
- incr fdiffpos
3421
- }
3422
- incr fdiffpos
3423
-
3424
- if {![info exists treediffs($fdiffid)]} {
3425
- set treediffs($fdiffid) $fdiffs
3426
- }
3427
- if {[info exists findid] && $fdiffid eq $findid} {
3428
- unset findid
3429
- findcont
3430
- }
3431
- }
3432
-}
3433
-
3434
-proc findcont {} {
3435
- global findid treediffs parentlist
3436
- global ffileline findstartline finddidsel
3437
- global displayorder numcommits matchinglines findinprogress
3438
- global findmergefiles
3439
-
3440
- set l $ffileline
3441
- while {1} {
3442
- set id [lindex $displayorder $l]
3443
- if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
3444
- if {![info exists treediffs($id)]} {
3445
- set findid $id
3446
- set ffileline $l
3447
- return
3448
- }
3449
- set doesmatch 0
3450
- foreach f $treediffs($id) {
3451
- set x [findmatches $f]
3452
- if {$x != {}} {
3453
- set doesmatch 1
3454
- break
3455
- }
3456
- }
3457
- if {$doesmatch} {
3458
- insertmatch $l $id
3459
- }
3460
- }
3461
- if {[incr l] >= $numcommits} {
3462
- set l 0
3463
- }
3464
- if {$l == $findstartline} break
3465
- }
3466
- stopfindproc
3467
- if {!$finddidsel} {
3468
- bell
3469
- }
3470
-}
3471
-
3227
# mark a commit as matching by putting a yellow background
3228
# behind the headline
3229
proc markheadline {l id} {
@@ -4965,7 +4720,7 @@ proc doquit {} {
4720
}
4721
4722
proc doprefs {} {
4968
- global maxwidth maxgraphpct diffopts findmergefiles
4723
+ global maxwidth maxgraphpct diffopts
4724
global oldprefs prefstop
4725
4726
set top .gitkprefs
@@ -4974,7 +4729,7 @@ proc doprefs {} {
4729
raise $top
4730
return
4731
}
4977
- foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
4732
+ foreach v {maxwidth maxgraphpct diffopts} {
4733
set oldprefs($v) [set $v]
4734
}
4735
toplevel $top
@@ -4990,10 +4745,6 @@ proc doprefs {} {
4745
-font optionfont
4746
spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
4747
grid x $top.maxpctl $top.maxpct -sticky w
4993
- checkbutton $top.findm -variable findmergefiles
4994
- label $top.findml -text "Include merges for \"Find\" in \"Files\"" \
4995
- -font optionfont
4996
- grid $top.findm $top.findml - -sticky w
4748
label $top.ddisp -text "Diff display options"
4749
grid $top.ddisp - -sticky w -pady 10
4750
label $top.diffoptl -text "Options for diff program" \
@@ -5010,10 +4761,10 @@ proc doprefs {} {
4761
}
4762
4763
proc prefscan {} {
5013
- global maxwidth maxgraphpct diffopts findmergefiles
4764
+ global maxwidth maxgraphpct diffopts
4765
global oldprefs prefstop
4766
5016
- foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
4767
+ foreach v {maxwidth maxgraphpct diffopts} {
4768
set $v $oldprefs($v)
4769
}
4770
catch {destroy $prefstop}
@@ -5389,7 +5140,6 @@ if {$i >= 0} {
5140
set history {}
5141
set historyindex 0
5142
set fh_serial 0
5392
-set highlight_names {}
5143
set nhl_names {}
5144
set highlight_paths {}
5145
set searchdirn -forwards