gitk: Fix the display of files when filtered by path

Launching 'gitk -- .' or 'gitk -- ..\t' restricts the display to files under the given directory but the file list is left empty. This is because the path_filter function fails to match the filenames which are relative to the working tree to the filter which is filessytem relative. This solves the problem by making both names fully qualified filesystem paths before performing the comparison. Tested-by: David Aguilar <davvid@gmail.com> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net> Signed-off-by: Paul Mackerras <paulus@samba.org>

Pat Thoyts committed Dec 13, 2011 at 16:50 UTC 65bb0bda75f4070a609d266d7231b4ec53d56972
1 file changed +27 -11
gitk
+27 -11
@@ -23,6 +23,26 @@ proc reponame {} {
23 return [file tail $n]
24 }
25
26 +proc gitworktree {} {
27 + variable _gitworktree
28 + if {[info exists _gitworktree]} {
29 + return $_gitworktree
30 + }
31 + # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 + if {[catch {set _gitworktree [exec git rev-parse --show-toplevel]}]} {
33 + # try to set work tree from environment, core.worktree or use
34 + # cdup to obtain a relative path to the top of the worktree. If
35 + # run from the top, the ./ prefix ensures normalize expands pwd.
36 + if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
37 + catch {set _gitworktree [exec git config --get core.worktree]}
38 + if {$_gitworktree eq ""} {
39 + set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]]
40 + }
41 + }
42 + }
43 + return $_gitworktree
44 +}
45 +
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
@@ -7402,19 +7422,15 @@ proc startdiff {ids} {
7422 }
7423 }
7424
7425 +# If the filename (name) is under any of the passed filter paths
7426 +# then return true to include the file in the listing.
7427 proc path_filter {filter name} {
7428 + set worktree [gitworktree]
7429 foreach p $filter {
7407 - set l [string length $p]
7408 - if {[string index $p end] eq "/"} {
7409 - if {[string compare -length $l $p $name] == 0} {
7410 - return 1
7411 - }
7412 - } else {
7413 - if {[string compare -length $l $p $name] == 0 &&
7414 - ([string length $name] == $l ||
7415 - [string index $name $l] eq "/")} {
7416 - return 1
7417 - }
7430 + set fq_p [file normalize $p]
7431 + set fq_n [file normalize [file join $worktree $name]]
7432 + if {[string match [file normalize $fq_p]* $fq_n]} {
7433 + return 1
7434 }
7435 }
7436 return 0