From 2d19f8e921a1cdc562783814747819b0d5a12641 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:04:45 +0200 Subject: git-gui: show unstaged symlinks in diff viewer git-gui has a minor problem with regards to symlinks that point to directories. git init mkdir realdir ln -s realdir linkdir git gui Now clicking on file names in the "unstaged changes" window, there's a problem coming from the "linkdir" symlink: git-gui complains with error reading "file4": illegal operation on a directory ...even though git-gui can add that same symlink to the index just fine. This patch fix this by adding a check. [sp: Minor fix to use {link} instead of "link" in condition and to only open the path if it is not a symlink.] Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce diff --git a/lib/diff.tcl b/lib/diff.tcl index e09e125..9eeff2e 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -85,11 +85,16 @@ proc show_diff {path w {lno {}}} { if {$m eq {_O}} { set max_sz [expr {128 * 1024}] if {[catch { - set fd [open $path r] - fconfigure $fd -eofchar {} - set content [read $fd $max_sz] - close $fd - set sz [file size $path] + if {[file type $path] == {link}} { + set content [file readlink $path] + set sz [string length $content] + } else { + set fd [open $path r] + fconfigure $fd -eofchar {} + set content [read $fd $max_sz] + close $fd + set sz [file size $path] + } } err ]} { set diff_active 0 unlock_index -- cgit v0.10.2-6-g49f6 From 4ed1a190d09c7d6a248038edb11addda77af7550 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:09:07 +0200 Subject: git-gui: handle "deleted symlink" diff marker Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce diff --git a/lib/diff.tcl b/lib/diff.tcl index 9eeff2e..a1d5e52 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -203,6 +203,7 @@ proc read_diff {fd} { if {[string match {mode *} $line] || [string match {new file *} $line] || [string match {deleted file *} $line] + || [string match {deleted symlink} $line] || [string match {Binary files * and * differ} $line] || $line eq {\ No newline at end of file} || [regexp {^\* Unmerged path } $line]} { -- cgit v0.10.2-6-g49f6 From 3b9dfde3d636aeb961318d41b3ab59f72414d010 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:13:10 -0400 Subject: git-gui: Assume untracked directories are Git submodules If `git ls-files --others` returned us the name of a directory then it is because Git has decided that this directory itself contains a valid Git repository and its files shouldn't be listed as untracked for this repository. In such a case we should label the object as a Git repository and not just as a directory. Signed-off-by: Shawn O. Pearce diff --git a/lib/diff.tcl b/lib/diff.tcl index a1d5e52..694834a 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -84,17 +84,30 @@ proc show_diff {path w {lno {}}} { # if {$m eq {_O}} { set max_sz [expr {128 * 1024}] + set type unknown if {[catch { - if {[file type $path] == {link}} { + set type [file type $path] + switch -- $type { + directory { + set type submodule + set content {} + set sz 0 + } + link { set content [file readlink $path] set sz [string length $content] - } else { + } + file { set fd [open $path r] fconfigure $fd -eofchar {} set content [read $fd $max_sz] close $fd set sz [file size $path] } + default { + error "'$type' not supported" + } + } } err ]} { set diff_active 0 unlock_index @@ -103,7 +116,9 @@ proc show_diff {path w {lno {}}} { return } $ui_diff conf -state normal - if {![catch {set type [exec file $path]}]} { + if {$type eq {submodule}} { + $ui_diff insert end "* Git Repository (subproject)\n" d_@ + } elseif {![catch {set type [exec file $path]}]} { set n [string length $path] if {[string equal -length $n $path $type]} { set type [string range $type $n end] -- cgit v0.10.2-6-g49f6 From 8938410189315979255c1dfcc3c0b7a4bf9953e5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:38:05 -0400 Subject: git-gui: Trim trailing slashes from untracked submodule names Oddly enough `git ls-files --others` supplies us the name of an untracked submodule by including the trailing slash but that same git version will not accept the name with a trailing slash through `git update-index --stdin`. Stripping off that final slash character before loading it into our file lists allows git-gui to stage changes to submodules just like any other file. This change should give git-gui users some basic submodule support, but it is strictly at the plumbing level as we do not actually know about calling the git-submodule porcelain that is a recent addition to git 1.5.3. Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 6d67609..26eb5ac 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1010,7 +1010,11 @@ proc read_ls_others {fd after} { set pck [split $buf_rlo "\0"] set buf_rlo [lindex $pck end] foreach p [lrange $pck 0 end-1] { - merge_state [encoding convertfrom $p] ?O + set p [encoding convertfrom $p] + if {[string index $p end] eq {/}} { + set p [string range $p 0 end-1] + } + merge_state $p ?O } rescan_done $fd buf_rlo $after } -- cgit v0.10.2-6-g49f6