@matheusbsbs / matheus-bagliano / commits / 7a39a17a87
Fork 0

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>

Paul Mackerras committed Oct 23, 2007 at 10:15 UTC 7a39a17a873b818e3a4d121b3a43baf10f68cf61
1 file changed +86 -10
gitk
+86 -10
@@ -1019,7 +1019,7 @@ proc savestuff {w} {
1019 global stuffsaved findmergefiles maxgraphpct
1020 global maxwidth showneartags showlocalchanges
1021 global viewname viewfiles viewargs viewperm nextviewnum
1022 - global cmitmode wrapcomment datetimeformat
1022 + global cmitmode wrapcomment datetimeformat limitdiffs
1023 global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
1024
1025 if {$stuffsaved} return
@@ -1038,6 +1038,7 @@ proc savestuff {w} {
1038 puts $f [list set showneartags $showneartags]
1039 puts $f [list set showlocalchanges $showlocalchanges]
1040 puts $f [list set datetimeformat $datetimeformat]
1041 + puts $f [list set limitdiffs $limitdiffs]
1042 puts $f [list set bgcolor $bgcolor]
1043 puts $f [list set fgcolor $fgcolor]
1044 puts $f [list set colors $colors]
@@ -5015,9 +5016,31 @@ proc startdiff {ids} {
5016 }
5017 }
5018
5019 +proc path_filter {filter name} {
5020 + foreach p $filter {
5021 + set l [string length $p]
5022 + if {[string compare -length $l $p $name] == 0 &&
5023 + ([string length $name] == $l || [string index $name $l] eq "/")} {
5024 + return 1
5025 + }
5026 + }
5027 + return 0
5028 +}
5029 +
5030 proc addtocflist {ids} {
5019 - global treediffs cflist
5020 - add_flist $treediffs($ids)
5031 + global treediffs cflist viewfiles curview limitdiffs
5032 +
5033 + if {$limitdiffs && $viewfiles($curview) ne {}} {
5034 + set flist {}
5035 + foreach f $treediffs($ids) {
5036 + if {[path_filter $viewfiles($curview) $f]} {
5037 + lappend flist $f
5038 + }
5039 + }
5040 + } else {
5041 + set flist $treediffs($ids)
5042 + }
5043 + add_flist $flist
5044 getblobdiffs $ids
5045 }
5046
@@ -5124,9 +5147,14 @@ proc getblobdiffs {ids} {
5147 global diffopts blobdifffd diffids env
5148 global diffinhdr treediffs
5149 global diffcontext
5150 + global limitdiffs viewfiles curview
5151
5152 set env(GIT_DIFF_OPTS) $diffopts
5129 - if {[catch {set bdf [open [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] r]} err]} {
5153 + set cmd [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"]
5154 + if {$limitdiffs && $viewfiles($curview) ne {}} {
5155 + set cmd [concat $cmd $viewfiles($curview)]
5156 + }
5157 + if {[catch {set bdf [open $cmd r]} err]} {
5158 puts "error getting diffs: $err"
5159 return
5160 }
@@ -7382,7 +7410,7 @@ proc doprefs {} {
7410 global maxwidth maxgraphpct diffopts
7411 global oldprefs prefstop showneartags showlocalchanges
7412 global bgcolor fgcolor ctext diffcolors selectbgcolor
7385 - global uifont tabstop
7413 + global uifont tabstop limitdiffs
7414
7415 set top .gitkprefs
7416 set prefstop $top
@@ -7390,7 +7418,8 @@ proc doprefs {} {
7418 raise $top
7419 return
7420 }
7393 - foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
7421 + foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges \
7422 + limitdiffs} {
7423 set oldprefs($v) [set $v]
7424 }
7425 toplevel $top
@@ -7428,6 +7457,11 @@ proc doprefs {} {
7457 label $top.tabstopl -text "tabstop" -font optionfont
7458 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
7459 grid x $top.tabstopl $top.tabstop -sticky w
7460 + frame $top.ldiff
7461 + label $top.ldiff.l -text "Limit diffs to listed paths" -font optionfont
7462 + checkbutton $top.ldiff.b -variable limitdiffs
7463 + pack $top.ldiff.b $top.ldiff.l -side left
7464 + grid x $top.ldiff -sticky w
7465
7466 label $top.cdisp -text "Colors: press to choose"
7467 $top.cdisp configure -font $uifont
@@ -7514,9 +7548,10 @@ proc setfg {c} {
7548
7549 proc prefscan {} {
7550 global maxwidth maxgraphpct diffopts
7517 - global oldprefs prefstop showneartags showlocalchanges
7551 + global oldprefs prefstop showneartags showlocalchanges limitdiffs
7552
7519 - foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
7553 + foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges \
7554 + limitdiffs} {
7555 set $v $oldprefs($v)
7556 }
7557 catch {destroy $prefstop}
@@ -7526,7 +7561,7 @@ proc prefscan {} {
7561 proc prefsok {} {
7562 global maxwidth maxgraphpct
7563 global oldprefs prefstop showneartags showlocalchanges
7529 - global charspc ctext tabstop
7564 + global charspc ctext tabstop limitdiffs
7565
7566 catch {destroy $prefstop}
7567 unset prefstop
@@ -7541,7 +7576,8 @@ proc prefsok {} {
7576 if {$maxwidth != $oldprefs(maxwidth)
7577 || $maxgraphpct != $oldprefs(maxgraphpct)} {
7578 redisplay
7544 - } elseif {$showneartags != $oldprefs(showneartags)} {
7579 + } elseif {$showneartags != $oldprefs(showneartags) ||
7580 + $limitdiffs != $oldprefs(limitdiffs)} {
7581 reselectline
7582 }
7583 }
@@ -7869,6 +7905,7 @@ set showneartags 1
7905 set maxrefs 20
7906 set maxlinelen 200
7907 set showlocalchanges 1
7908 +set limitdiffs 1
7909 set datetimeformat "%Y-%m-%d %H:%M:%S"
7910
7911 set colors {green red blue magenta darkgrey brown orange}
@@ -7892,6 +7929,7 @@ if {![file isdirectory $gitdir]} {
7929 exit 1
7930 }
7931
7932 +set mergeonly 0
7933 set revtreeargs {}
7934 set cmdline_files {}
7935 set i 0
@@ -7899,6 +7937,10 @@ foreach arg $argv {
7937 switch -- $arg {
7938 "" { }
7939 "-d" { set datemode 1 }
7940 + "--merge" {
7941 + set mergeonly 1
7942 + lappend revtreeargs $arg
7943 + }
7944 "--" {
7945 set cmdline_files [lrange $argv [expr {$i + 1}] end]
7946 break
@@ -7939,6 +7981,40 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} {
7981 }
7982 }
7983
7984 +if {$mergeonly} {
7985 + # find the list of unmerged files
7986 + set mlist {}
7987 + set nr_unmerged 0
7988 + if {[catch {
7989 + set fd [open "| git ls-files -u" r]
7990 + } err]} {
7991 + show_error {} . "Couldn't get list of unmerged files: $err"
7992 + exit 1
7993 + }
7994 + while {[gets $fd line] >= 0} {
7995 + set i [string first "\t" $line]
7996 + if {$i < 0} continue
7997 + set fname [string range $line [expr {$i+1}] end]
7998 + if {[lsearch -exact $mlist $fname] >= 0} continue
7999 + incr nr_unmerged
8000 + if {$cmdline_files eq {} || [path_filter $cmdline_files $fname]} {
8001 + lappend mlist $fname
8002 + }
8003 + }
8004 + catch {close $fd}
8005 + if {$mlist eq {}} {
8006 + if {$nr_unmerged == 0} {
8007 + show_error {} . "No files selected: --merge specified but\
8008 + no files are unmerged."
8009 + } else {
8010 + show_error {} . "No files selected: --merge specified but\
8011 + no unmerged files are within file limit."
8012 + }
8013 + exit 1
8014 + }
8015 + set cmdline_files $mlist
8016 +}
8017 +
8018 set nullid "0000000000000000000000000000000000000000"
8019 set nullid2 "0000000000000000000000000000000000000001"
8020