gitk: Use git-rev-parse only to identify file/dir names on cmd line
[gitweb.git] / gitk
diff --git a/gitk b/gitk
index 85f426ab2244006aea2e391dc8d24c58a3d9e080..6cefc8721846fd2a2a97a816d240d8a4cb8336c1 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -16,56 +16,26 @@ proc gitdir {} {
     }
 }
 
-proc parse_args {rargs} {
-    global parsed_args cmdline_files
-
-    set parsed_args {}
-    set cmdline_files {}
-    if {[catch {
-       set args [concat --default HEAD $rargs]
-       set args [split [eval exec git-rev-parse $args] "\n"]
-       set i 0
-       foreach arg $args {
-           if {![regexp {^[0-9a-f]{40}$} $arg]} {
-               if {$arg eq "--"} {
-                   incr i
-               }
-               set cmdline_files [lrange $args $i end]
-               break
-           }
-           lappend parsed_args $arg
-           incr i
-       }
-    }]} {
-       # if git-rev-parse failed for some reason...
-       set i [lsearch -exact $rargs "--"]
-       if {$i >= 0} {
-           set cmdline_files [lrange $rargs [expr {$i+1}] end]
-           set rargs [lrange $rargs 0 [expr {$i-1}]]
-       }
-       if {$rargs == {}} {
-           set parsed_args HEAD
-       } else {
-           set parsed_args $rargs
-       }
-    }
-}
-
-proc start_rev_list {rlargs} {
+proc start_rev_list {} {
     global startmsecs nextupdate ncmupdate
     global commfd leftover tclencoding datemode
+    global revtreeargs curview viewfiles
 
     set startmsecs [clock clicks -milliseconds]
     set nextupdate [expr {$startmsecs + 100}]
     set ncmupdate 1
     initlayout
+    set args $revtreeargs
+    if {$viewfiles($curview) ne {}} {
+       set args [concat $args "--" $viewfiles($curview)]
+    }
     set order "--topo-order"
     if {$datemode} {
        set order "--date-order"
     }
     if {[catch {
        set commfd [open [concat | git-rev-list --header $order \
-                             --parents --boundary $rlargs] r]
+                             --parents --boundary --default HEAD $args] r]
     } err]} {
        puts stderr "Error executing git-rev-list: $err"
        exit 1
@@ -92,11 +62,11 @@ proc stop_rev_list {} {
     unset commfd
 }
 
-proc getcommits {rargs} {
+proc getcommits {} {
     global phase canv mainfont
 
     set phase getcommits
-    start_rev_list $rargs
+    start_rev_list
     $canv delete all
     $canv create text 3 3 -anchor nw -text "Reading commits..." \
        -font $mainfont -tags textitems
@@ -239,7 +209,6 @@ proc updatecommits {} {
     set n $curview
     set curview -1
     catch {unset viewdata($n)}
-    parse_args $revtreeargs
     readrefs
     showview $n
 }
@@ -926,7 +895,6 @@ proc showview {n} {
     global numcommits rowrangelist commitlisted idrowranges
     global selectedline currentid canv canvy0
     global matchinglines treediffs
-    global parsed_args
     global pending_select phase
     global commitidx rowlaidout rowoptim linesegends leftover
     global commfd nextupdate
@@ -959,7 +927,8 @@ proc showview {n} {
                     $commitidx $rowlaidout $rowoptim $numcommits \
                     $linesegends $leftover $commfd]
            fileevent $commfd readable {}
-       } elseif {![info exists viewdata($curview)]} {
+       } elseif {![info exists viewdata($curview)]
+                 || [lindex $viewdata($curview) 0] ne {}} {
            set viewdata($curview) \
                [list {} $displayorder $parentlist $childlist $rowidlist \
                     $rowoffsets $rowrangelist $commitlisted]
@@ -973,12 +942,8 @@ proc showview {n} {
     .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}]
 
     if {![info exists viewdata($n)]} {
-       set args $parsed_args
-       if {$viewfiles($n) ne {}} {
-           set args [concat $args "--" $viewfiles($n)]
-       }
        set pending_select $selid
-       getcommits $args 
+       getcommits
        return
     }
 
@@ -1035,6 +1000,14 @@ proc showview {n} {
     allcanvs yview moveto $yf
     drawvisible
     selectline $row 0
+    if {$phase eq {}} {
+       global maincursor textcursor
+       . config -cursor $maincursor
+       settextcursor $textcursor
+    } else {
+       . config -cursor watch
+       settextcursor watch
+    }
 }
 
 proc shortids {ids} {
@@ -2301,7 +2274,7 @@ proc stopfindproc {{done 0}} {
     }
     if {[info exists findinprogress]} {
        unset findinprogress
-       if {$phase != "incrdraw"} {
+       if {$phase eq {}} {
            . config -cursor $maincursor
            settextcursor $textcursor
        }
@@ -2840,17 +2813,18 @@ proc unselectline {} {
 }
 
 proc addtohistory {cmd} {
-    global history historyindex
+    global history historyindex curview
 
+    set elt [list $curview $cmd]
     if {$historyindex > 0
-       && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
+       && [lindex $history [expr {$historyindex - 1}]] == $elt} {
        return
     }
 
     if {$historyindex < [llength $history]} {
-       set history [lreplace $history $historyindex end $cmd]
+       set history [lreplace $history $historyindex end $elt]
     } else {
-       lappend history $cmd
+       lappend history $elt
     }
     incr historyindex
     if {$historyindex > 1} {
@@ -2861,13 +2835,23 @@ proc addtohistory {cmd} {
     .ctop.top.bar.rightbut conf -state disabled
 }
 
+proc godo {elt} {
+    global curview
+
+    set view [lindex $elt 0]
+    set cmd [lindex $elt 1]
+    if {$curview != $view} {
+       showview $view
+    }
+    eval $cmd
+}
+
 proc goback {} {
     global history historyindex
 
     if {$historyindex > 1} {
        incr historyindex -1
-       set cmd [lindex $history [expr {$historyindex - 1}]]
-       eval $cmd
+       godo [lindex $history [expr {$historyindex - 1}]]
        .ctop.top.bar.rightbut conf -state normal
     }
     if {$historyindex <= 1} {
@@ -2881,7 +2865,7 @@ proc goforw {} {
     if {$historyindex < [llength $history]} {
        set cmd [lindex $history $historyindex]
        incr historyindex
-       eval $cmd
+       godo $cmd
        .ctop.top.bar.leftbut conf -state normal
     }
     if {$historyindex >= [llength $history]} {
@@ -4232,8 +4216,18 @@ set patchnum 0
 setcoords
 makewindow
 readrefs
-parse_args $revtreeargs
-set args $parsed_args
+
+set cmdline_files {}
+catch {
+    set fileargs [eval exec git-rev-parse --no-revs --no-flags $revtreeargs]
+    set cmdline_files [split $fileargs "\n"]
+    set n [llength $cmdline_files]
+    set revtreeargs [lrange $revtreeargs 0 end-$n]
+}
+if {[lindex $revtreeargs end] eq "--"} {
+    set revtreeargs [lrange $revtreeargs 0 end-1]
+}
+
 if {$cmdline_files ne {}} {
     # create a view for the files/dirs specified on the command line
     set curview 1
@@ -4242,6 +4236,5 @@ if {$cmdline_files ne {}} {
     set viewfiles(1) $cmdline_files
     .bar.view add command -label $viewname(1) -command {showview 1}
     .bar.view entryconf 2 -state normal
-    set args [concat $args "--" $cmdline_files]
 }
-getcommits $args
+getcommits