Skip to contentSkip to conversation

gitk: fix the display of files when filtered by path

PATCH Applied Pat Thoyts 7 participants 12 messages Jun 15, 2016 Documentation

lore
Share & tools
lore

Pat Thoyts

author
#0 lore raw

PATCH 1/1 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.

---
 gitk-git/gitk |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)
gitk-git/gitk +27 -11
index 2a92e20..b728345 100755
@@ -18,6 +18,26 @@ proc gitdir {} {
     }
 }
 
+proc gitworktree {} {
+    variable _gitworktree
+    if {[info exists _gitworktree]} {
+	return $_gitworktree
+    }
+    # v1.7.0 introduced --show-toplevel to return the canonical work-tree
+    if {[catch {set _gitworktree [exec git rev-parse --show-toplevel]}]} {
+        # try to set work tree from environment, core.worktree or use
+        # cdup to obtain a relative path to the top of the worktree. If
+        # run from the top, the ./ prefix ensures normalize expands pwd.
+        if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
+	    catch {set _gitworktree [exec git config --get core.worktree]}
+	    if {$_gitworktree eq ""} {
+		set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]]
+	    }
+        }
+    }
+    return $_gitworktree
+}
+
 # A simple scheduler for compute-intensive stuff.
 # The aim is to make sure that event handlers for GUI actions can
 # run at least every 50-100 ms.  Unfortunately fileevent handlers are
@@ -7376,19 +7396,15 @@ proc startdiff {ids} {
     }
 }
 
+# If the filename (name) is under any of the passed filter paths
+# then return true to include the file in the listing.
 proc path_filter {filter name} {
+    set worktree [gitworktree]
     foreach p $filter {
-	set l [string length $p]
-	if {[string index $p end] eq "/"} {
-	    if {[string compare -length $l $p $name] == 0} {
-		return 1
-	    }
-	} else {
-	    if {[string compare -length $l $p $name] == 0 &&
-		([string length $name] == $l ||
-		 [string index $name $l] eq "/")} {
-		return 1
-	    }
+	set fq_p [file normalize $p]
+	set fq_n [file normalize [file join $worktree $name]]
+	if {[string match [file normalize $fq_p]* $fq_n]} {
+	    return 1
 	}
     }
     return 0
Signature · 1 line
1.7.8.msysgit.0
Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Pat Thoyts

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.

Wonderful!

I've run into this problem a number of times (as have some co-workers) but I never bothered to report it since I felt guilty for never having worked up a patch.

I tested this and it worked.

FWIW,

Thank you Pat!

Signature · 1 line
            David
#2 lore raw

Hi,

Quoted 9 lines · David Aguilar
Quoted 7 lines · Pat Thoyts

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.

Quoted 3 lines
Quoted 1 line

Wonderful!

Thanks for reminding me that I did not yet apply and push. Did so now.

Thanks, Pat, for fixing this bug!
Dscho

#3 lore raw

Hi,

Quoted 12 lines · Johannes Schindelin

Hi,

Quoted 8 lines · David Aguilar
Quoted 6 lines · Pat Thoyts

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.

How is this related to my patches from April? See
http://thread.gmane.org/gmane.comp.version-control.git/170853. It's clearly not the same problem, but will the patches conflict? Will some of mine be unnecessary?

Quoted 1 line

Thanks for reminding me that I did not yet apply and push. Did so now.

What do you mean by this? Push to where?
git://git.kernel.org/pub/scm/gitk/gitk.git is still down.

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

Martin

#4 lore raw
Quoted 1 line · Martin von Zweigbergk

git://git.kernel.org/pub/scm/gitk/gitk.git is still down.

I have just created a repository on ozlabs.org for gitk, since I don't have kernel.org access at this point. The repository is:

git://ozlabs.org/~paulus/gitk.git

Quoted 4 lines

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

Your patches are in the master branch. I applied them back in July but then kernel.org went down.

Paul.

#5 lore raw
Quoted 11 lines · Paul Mackerras
Quoted 1 line · Martin von Zweigbergk

git://git.kernel.org/pub/scm/gitk/gitk.git is still down.

I have just created a repository on ozlabs.org for gitk, since I don't have kernel.org access at this point. The repository is:

git://ozlabs.org/~paulus/gitk.git
...
Your patches are in the master branch. I applied them back in July but then kernel.org went down.

Thanks.

All pulled and resulted in one liner update to the draft Release Notes for the next release.

Documentation/RelNotes/1.7.9.txt +2 -0
index cd3c256..f476667 100644
@@ -4,6 +4,8 @@ Git v1.7.9 Release Notes (draft)
 Updates since v1.7.8
 --------------------
 
+ * Accumulated gitk updates since early this year.
+
  * git-gui updated to 0.16.0.
 
  * git-p4 (in contrib/) updates.
#6 lore raw
In reply to Martin von Zweigbergk
Quoted 4 lines · Martin von Zweigbergk

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

I tend to agree.

I have this slight suspicion that Paul would appreciate if somebody who cares about gitk who is capable and willing steps forward and takes over the maintainership of gitk, as he is busy in his other projects.

#7 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Martin von Zweigbergk

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

Quoted 5 lines

I tend to agree.

I have this slight suspicion that Paul would appreciate if somebody who cares about gitk who is capable and willing steps forward and takes over the maintainership of gitk, as he is busy in his other projects.

Indeed. For now I have put up a repository on ozlabs.org:

git://ozlabs.org/~paulus/gitk.git

but if someone wants to take on the gitk maintainership, please let me know.

Paul.

author
#8 lore raw
In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Martin von Zweigbergk

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

Quoted 5 lines

I tend to agree.

I have this slight suspicion that Paul would appreciate if somebody who cares about gitk who is capable and willing steps forward and takes over the maintainership of gitk, as he is busy in his other projects.

I can do this one along with git-gui if this is the case.

Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
#9 lore raw
Quoted 7 lines · Pat Thoyts
Quoted 3 lines · Junio C Hamano

I have this slight suspicion that Paul would appreciate if somebody who cares about gitk who is capable and willing steps forward and takes over the maintainership of gitk, as he is busy in his other projects.

I can do this one along with git-gui if this is the case.

I wonder if having common maintainer for both gitk and git-gui would lead to first, splitting gitk into smaller files like git-gui was, and second sharing common Tcl/Tk bindings / wrappers between gitk and git-gui...

Signature · 1 line
Jakub Narębski
author
#10 lore raw
In reply to Martin von Zweigbergk

Martin von Zweigbergk <[email protected]> writes:

[resending as my earlier post got bounced from vger]

Quoted 22 lines

Hi,

Quoted 12 lines · Johannes Schindelin

Hi,

Quoted 8 lines · David Aguilar
Quoted 6 lines · Pat Thoyts

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.

How is this related to my patches from April? See
http://thread.gmane.org/gmane.comp.version-control.git/170853. It's clearly not the same problem, but will the patches conflict? Will some of mine be unnecessary?

Quoted 5 lines
Quoted 1 line

Thanks for reminding me that I did not yet apply and push. Did so now.

What do you mean by this? Push to where?
git://git.kernel.org/pub/scm/gitk/gitk.git is still down.

This is for msysGit.

Quoted 4 lines

Paul and Junio, the patches I sent in April are still not in git.git, are they? Can we use another repo until the kernel.org one is up? More than eight months to get a patch (or eight) merged is way too long, IMO.

I'm not sure how this might relate to your patches. I've got a version merged on top of the last version of the gitk report that I have which includes those and it seems fine. As stated I did this work against git-core as the gitk repository continues to be unavailable. However as I have a pretty current snapshot I have pushed this to github to provide some visibility of things I know are not present within git-core. See
http://github.com/patthoyts/gitk.git

Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
#11 lore raw
In reply to Pat Thoyts
Quoted 8 lines · Pat Thoyts

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.

Thanks, applied.

Paul.