Skip to content

Commit cbfea48

Browse files
patthoytsdscho
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. Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net> Tested-by: David Aguilar <davvid@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f57116e commit cbfea48

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

gitk-git/gitk

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ proc gitdir {} {
1818
}
1919
}
2020

21+
proc gitworktree {} {
22+
variable _gitworktree
23+
if {[info exists _gitworktree]} {
24+
return $_gitworktree
25+
}
26+
# v1.7.0 introduced --show-toplevel to return the canonical work-tree
27+
if {[catch {set _gitworktree [exec git rev-parse --show-toplevel]}]} {
28+
# try to set work tree from environment, core.worktree or use
29+
# cdup to obtain a relative path to the top of the worktree. If
30+
# run from the top, the ./ prefix ensures normalize expands pwd.
31+
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
32+
catch {set _gitworktree [exec git config --get core.worktree]}
33+
if {$_gitworktree eq ""} {
34+
set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]]
35+
}
36+
}
37+
}
38+
return $_gitworktree
39+
}
40+
2141
# A simple scheduler for compute-intensive stuff.
2242
# The aim is to make sure that event handlers for GUI actions can
2343
# run at least every 50-100 ms. Unfortunately fileevent handlers are
@@ -7376,19 +7396,15 @@ proc startdiff {ids} {
73767396
}
73777397
}
73787398

7399+
# If the filename (name) is under any of the passed filter paths
7400+
# then return true to include the file in the listing.
73797401
proc path_filter {filter name} {
7402+
set worktree [gitworktree]
73807403
foreach p $filter {
7381-
set l [string length $p]
7382-
if {[string index $p end] eq "/"} {
7383-
if {[string compare -length $l $p $name] == 0} {
7384-
return 1
7385-
}
7386-
} else {
7387-
if {[string compare -length $l $p $name] == 0 &&
7388-
([string length $name] == $l ||
7389-
[string index $name $l] eq "/")} {
7390-
return 1
7391-
}
7404+
set fq_p [file normalize $p]
7405+
set fq_n [file normalize [file join $worktree $name]]
7406+
if {[string match [file normalize $fq_p]* $fq_n]} {
7407+
return 1
73927408
}
73937409
}
73947410
return 0

0 commit comments

Comments
 (0)