Skip to content

Commit 65bb0bd

Browse files
patthoytspaulusmack
authored andcommitted
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 <[email protected]> Signed-off-by: Pat Thoyts <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 44acce0 commit 65bb0bd

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

gitk

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ proc reponame {} {
2323
return [file tail $n]
2424
}
2525

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+
2646
# A simple scheduler for compute-intensive stuff.
2747
# The aim is to make sure that event handlers for GUI actions can
2848
# run at least every 50-100 ms. Unfortunately fileevent handlers are
@@ -7402,19 +7422,15 @@ proc startdiff {ids} {
74027422
}
74037423
}
74047424

7425+
# If the filename (name) is under any of the passed filter paths
7426+
# then return true to include the file in the listing.
74057427
proc path_filter {filter name} {
7428+
set worktree [gitworktree]
74067429
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
74187434
}
74197435
}
74207436
return 0

0 commit comments

Comments
 (0)