git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix tree mode of the file list for files containing curly brackets

From
Alex Riesen <raa.lkml@gmail.com>
Date
Mar 14, 2008, 21:58 UTC
Message-ID
<20080314215841.GB5914@steel.home>
In-Reply-To
<20080314214904.GA5914@steel.home>

As far as I could understand the online documentation the [lindex ...] thing expects an array, which a string produced by git-ls-tree is not. So [split ...] it first, to get a real Tcl string-array.

For instance:
    $ git init
    $ date >file
    $ git add . && git commit -m1
    $ git mv file '{a-b}.a.b'
    $ git commit -m2
    $ git mv file '{a-b}.a.b{'
    $ git commit -m3
    $ git mv file '{a-b}.a .b{'
    $ git commit -m4
    $ gitk
Now switch the file list from "Patch" to "Tree":
    list element in braces followed by ".a.b" instead of space
    list element in braces followed by ".a.b" instead of space
	while executing
    "lindex $line 1"
	(procedure "gettreeline" line 9)
	invoked from within
    "gettreeline file11 4b155a05282eeccd7c8fd381b22ed442efde2850"
	("eval" body line 1)
	invoked from within
    "eval $script"
	(procedure "dorunq" line 9)
	invoked from within
    "dorunq"
	("after" script)
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Alex Riesen, Fri, Mar 14, 2008 22:49:04 +0100:
> +	    set la [split "$line" " \t"]
> +	    if {$diffids ne $nullid2 && [lindex $la 1] ne "blob"} continue
> +	    set sha1 [lindex $la 2]
> +	    set fname [lindex $la 3]

And, as I actually do know nothing about Tcl, it does not work for files with spaces. The last lindex is obviuosly wrong, it breaks names with whitespaces.

 gitk-git/gitk |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index f1f21e9..b3a57be 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -4946,14 +4946,10 @@ proc gettreeline {gtf id} {
 	if {$diffids eq $nullid} {
 	    set fname $line
 	} else {
-	    if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
-	    set i [string first "\t" $line]
-	    if {$i < 0} continue
-	    set sha1 [lindex $line 2]
-	    set fname [string range $line [expr {$i+1}] end]
-	    if {[string index $fname 0] eq "\""} {
-		set fname [lindex $fname 0]
-	    }
+	    set la [split "$line" " "]
+	    if {$diffids ne $nullid2 && [lindex $la 1] ne "blob"} continue
+	    set sha1 [lindex $la 2]
+	    set fname [lindex [split "$line" "\t"] 1]
 	    lappend treeidlist($id) $sha1
 	}
 	lappend treefilelist($id) $fname
-- 
1.5.4.4.578.g182d
Previous: Alex RiesenNext: Alex Riesen
Message 2 of 5 in “Fix tree mode of the file list for files containing curly brackets”
  1. Alex RiesenMar 14, 2008
  2. Fix tree mode of the file list for files containing curly bracketsAlex Riesen, Mar 14, 2008
  3. [RESEND] [PATCH] Fix tree mode of the file list for files containing curly bracketsAlex Riesen, Apr 27, 2008
  4. Paul MackerrasApr 27, 2008
  5. Alex RiesenApr 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.