Code

git-gui: When possible show the type of an untracked file.
authorShawn O. Pearce <spearce@spearce.org>
Tue, 23 Jan 2007 08:18:37 +0000 (03:18 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 23 Jan 2007 08:18:37 +0000 (03:18 -0500)
Users may want to know what a file is before they add it to the
repository, especially if its a binary file.  So when possible
invoke 'file' on the path and try to get its output.  Since
this is strictly advice to the user we won't bother to report
any failures from our attempt to run `file`.

Since some file commands also output the path name they were
given we look for that case and strip it off the front of the
returned output before placing it into the diff viewer.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh

index f71dabe68a684c3888c53d9fa9d9993910719674..37757cfb6522a69b2e3150b8a81eab284b9f874d 100755 (executable)
@@ -640,6 +640,14 @@ proc show_diff {path w {lno {}}} {
                        return
                }
                $ui_diff conf -state normal
+               if {![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]
+                               regsub {^:?\s*} $type {} type
+                       }
+                       $ui_diff insert end "* $type\n" d_@
+               }
                if {[string first "\0" $content] != -1} {
                        $ui_diff insert end \
                                "* Binary file (not showing content)." \