Skip to contentSkip to conversation

Show selected subdirectory paths in gitk

PATCH New Peter Baumann 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Show selected subdirectory paths in gitk

Previously, running 'gitk -- file' in a subdirectory of the worktree didn't show the file in the file selection widget. This is especially annoying if multiple files and/or a subdirectory was given as parameter to gitk, because no visual reprasentation on the changed files was given besides the commit diff itself.

By prefixing all file filters with the result of the newly added function get_subdir_prefix which returns the subdirectory relative to the GIT_DIR, we make sure we always use the correct file name.

---

The problem this patch fixes could be reproduced in the git repo by

cd Documentation
gitk git-add.txt

Running the above commands and you should not see any file listed in the file selection widget in gitk. After applying the patch, the file is listed there (for any non merge commit).

 gitk-git/gitk |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
 mode change 100644 => 100755 gitk-git/gitk
gitk-git/gitk +10 -1
old mode 100644
new mode 100755
index 1a7887b..2355d82
@@ -7104,8 +7104,17 @@ proc startdiff {ids} {
     }
 }
 
+# Return the current subdirectory relative to the repository root
+proc get_subdir_prefix {} {
+    return [exec git rev-parse --show-prefix]
+}
+
 proc path_filter {filter name} {
-    foreach p $filter {
+    set prefix [get_subdir_prefix]
+    foreach f $filter {
+	# get full pathname starting from the workdir root
+	set p "$prefix$f"
+
 	set l [string length $p]
 	if {[string index $p end] eq "/"} {
 	    if {[string compare -length $l $p $name] == 0} {
Signature · 1 line
1.6.3.1.70.ga80aa.dirty