gitk: Limit diff display to listed paths by default

When the user has specified a list of paths, either on the command line
or when creating a view, gitk currently displays the diffs for all files
that a commit has modified, not just the ones that match the path list.
This is different from other git commands such as git log.  This change
makes gitk behave the same as these other git commands by default, that
is, gitk only displays the diffs for files that match the path list.

There is now a checkbox labelled "Limit diffs to listed paths" in the
Edit/Preferences pane.  If that is unchecked, gitk will display the
diffs for all files as before.

When gitk is run with the --merge flag, it will get the list of unmerged
files at startup, intersect that with the paths listed on the command line
(if any), and use that as the list of paths.

Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
Paul Mackerras 2007-10-23 10:15:11 +10:00
parent e5ef6f952a
commit 7a39a17a87

96
gitk
View File

@ -1019,7 +1019,7 @@ proc savestuff {w} {
global stuffsaved findmergefiles maxgraphpct global stuffsaved findmergefiles maxgraphpct
global maxwidth showneartags showlocalchanges global maxwidth showneartags showlocalchanges
global viewname viewfiles viewargs viewperm nextviewnum global viewname viewfiles viewargs viewperm nextviewnum
global cmitmode wrapcomment datetimeformat global cmitmode wrapcomment datetimeformat limitdiffs
global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
if {$stuffsaved} return if {$stuffsaved} return
@ -1038,6 +1038,7 @@ proc savestuff {w} {
puts $f [list set showneartags $showneartags] puts $f [list set showneartags $showneartags]
puts $f [list set showlocalchanges $showlocalchanges] puts $f [list set showlocalchanges $showlocalchanges]
puts $f [list set datetimeformat $datetimeformat] puts $f [list set datetimeformat $datetimeformat]
puts $f [list set limitdiffs $limitdiffs]
puts $f [list set bgcolor $bgcolor] puts $f [list set bgcolor $bgcolor]
puts $f [list set fgcolor $fgcolor] puts $f [list set fgcolor $fgcolor]
puts $f [list set colors $colors] puts $f [list set colors $colors]
@ -5015,9 +5016,31 @@ proc startdiff {ids} {
} }
} }
proc path_filter {filter name} {
foreach p $filter {
set l [string length $p]
if {[string compare -length $l $p $name] == 0 &&
([string length $name] == $l || [string index $name $l] eq "/")} {
return 1
}
}
return 0
}
proc addtocflist {ids} { proc addtocflist {ids} {
global treediffs cflist global treediffs cflist viewfiles curview limitdiffs
add_flist $treediffs($ids)
if {$limitdiffs && $viewfiles($curview) ne {}} {
set flist {}
foreach f $treediffs($ids) {
if {[path_filter $viewfiles($curview) $f]} {
lappend flist $f
}
}
} else {
set flist $treediffs($ids)
}
add_flist $flist
getblobdiffs $ids getblobdiffs $ids
} }
@ -5124,9 +5147,14 @@ proc getblobdiffs {ids} {
global diffopts blobdifffd diffids env global diffopts blobdifffd diffids env
global diffinhdr treediffs global diffinhdr treediffs
global diffcontext global diffcontext
global limitdiffs viewfiles curview
set env(GIT_DIFF_OPTS) $diffopts set env(GIT_DIFF_OPTS) $diffopts
if {[catch {set bdf [open [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] r]} err]} { set cmd [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"]
if {$limitdiffs && $viewfiles($curview) ne {}} {
set cmd [concat $cmd $viewfiles($curview)]
}
if {[catch {set bdf [open $cmd r]} err]} {
puts "error getting diffs: $err" puts "error getting diffs: $err"
return return
} }
@ -7382,7 +7410,7 @@ proc doprefs {} {
global maxwidth maxgraphpct diffopts global maxwidth maxgraphpct diffopts
global oldprefs prefstop showneartags showlocalchanges global oldprefs prefstop showneartags showlocalchanges
global bgcolor fgcolor ctext diffcolors selectbgcolor global bgcolor fgcolor ctext diffcolors selectbgcolor
global uifont tabstop global uifont tabstop limitdiffs
set top .gitkprefs set top .gitkprefs
set prefstop $top set prefstop $top
@ -7390,7 +7418,8 @@ proc doprefs {} {
raise $top raise $top
return return
} }
foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} { foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges \
limitdiffs} {
set oldprefs($v) [set $v] set oldprefs($v) [set $v]
} }
toplevel $top toplevel $top
@ -7428,6 +7457,11 @@ proc doprefs {} {
label $top.tabstopl -text "tabstop" -font optionfont label $top.tabstopl -text "tabstop" -font optionfont
spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
grid x $top.tabstopl $top.tabstop -sticky w grid x $top.tabstopl $top.tabstop -sticky w
frame $top.ldiff
label $top.ldiff.l -text "Limit diffs to listed paths" -font optionfont
checkbutton $top.ldiff.b -variable limitdiffs
pack $top.ldiff.b $top.ldiff.l -side left
grid x $top.ldiff -sticky w
label $top.cdisp -text "Colors: press to choose" label $top.cdisp -text "Colors: press to choose"
$top.cdisp configure -font $uifont $top.cdisp configure -font $uifont
@ -7514,9 +7548,10 @@ proc setfg {c} {
proc prefscan {} { proc prefscan {} {
global maxwidth maxgraphpct diffopts global maxwidth maxgraphpct diffopts
global oldprefs prefstop showneartags showlocalchanges global oldprefs prefstop showneartags showlocalchanges limitdiffs
foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} { foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges \
limitdiffs} {
set $v $oldprefs($v) set $v $oldprefs($v)
} }
catch {destroy $prefstop} catch {destroy $prefstop}
@ -7526,7 +7561,7 @@ proc prefscan {} {
proc prefsok {} { proc prefsok {} {
global maxwidth maxgraphpct global maxwidth maxgraphpct
global oldprefs prefstop showneartags showlocalchanges global oldprefs prefstop showneartags showlocalchanges
global charspc ctext tabstop global charspc ctext tabstop limitdiffs
catch {destroy $prefstop} catch {destroy $prefstop}
unset prefstop unset prefstop
@ -7541,7 +7576,8 @@ proc prefsok {} {
if {$maxwidth != $oldprefs(maxwidth) if {$maxwidth != $oldprefs(maxwidth)
|| $maxgraphpct != $oldprefs(maxgraphpct)} { || $maxgraphpct != $oldprefs(maxgraphpct)} {
redisplay redisplay
} elseif {$showneartags != $oldprefs(showneartags)} { } elseif {$showneartags != $oldprefs(showneartags) ||
$limitdiffs != $oldprefs(limitdiffs)} {
reselectline reselectline
} }
} }
@ -7869,6 +7905,7 @@ set showneartags 1
set maxrefs 20 set maxrefs 20
set maxlinelen 200 set maxlinelen 200
set showlocalchanges 1 set showlocalchanges 1
set limitdiffs 1
set datetimeformat "%Y-%m-%d %H:%M:%S" set datetimeformat "%Y-%m-%d %H:%M:%S"
set colors {green red blue magenta darkgrey brown orange} set colors {green red blue magenta darkgrey brown orange}
@ -7892,6 +7929,7 @@ if {![file isdirectory $gitdir]} {
exit 1 exit 1
} }
set mergeonly 0
set revtreeargs {} set revtreeargs {}
set cmdline_files {} set cmdline_files {}
set i 0 set i 0
@ -7899,6 +7937,10 @@ foreach arg $argv {
switch -- $arg { switch -- $arg {
"" { } "" { }
"-d" { set datemode 1 } "-d" { set datemode 1 }
"--merge" {
set mergeonly 1
lappend revtreeargs $arg
}
"--" { "--" {
set cmdline_files [lrange $argv [expr {$i + 1}] end] set cmdline_files [lrange $argv [expr {$i + 1}] end]
break break
@ -7939,6 +7981,40 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} {
} }
} }
if {$mergeonly} {
# find the list of unmerged files
set mlist {}
set nr_unmerged 0
if {[catch {
set fd [open "| git ls-files -u" r]
} err]} {
show_error {} . "Couldn't get list of unmerged files: $err"
exit 1
}
while {[gets $fd line] >= 0} {
set i [string first "\t" $line]
if {$i < 0} continue
set fname [string range $line [expr {$i+1}] end]
if {[lsearch -exact $mlist $fname] >= 0} continue
incr nr_unmerged
if {$cmdline_files eq {} || [path_filter $cmdline_files $fname]} {
lappend mlist $fname
}
}
catch {close $fd}
if {$mlist eq {}} {
if {$nr_unmerged == 0} {
show_error {} . "No files selected: --merge specified but\
no files are unmerged."
} else {
show_error {} . "No files selected: --merge specified but\
no unmerged files are within file limit."
}
exit 1
}
set cmdline_files $mlist
}
set nullid "0000000000000000000000000000000000000000" set nullid "0000000000000000000000000000000000000000"
set nullid2 "0000000000000000000000000000000000000001" set nullid2 "0000000000000000000000000000000000000001"