gitk: Improve handling of -- and ambiguous arguments
This makes gitk more consistent with git rev-list and git log in its handling of arguments that could be either a revision or a filename; now gitk displays an error message and quits, rather than treating it as a revision and getting an error in the underlying git log. Now gitk always passes "--" to git log even if no filenames are being specified. It also makes gitk display errors in invoking git log in a window rather than on stderr, and makes gitk stop looking for a -d flag when it sees a "--" argument. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Jul 12, 2007 at 22:29 UTC
cdaee5db165ba8bae8d3b524950e61666fc36a84
1 file changed
+29
-20
gitk
+29
-20
@@ -87,19 +87,15 @@ proc start_rev_list {view} {
87
88
set startmsecs [clock clicks -milliseconds]
89
set commitidx($view) 0
90
- set args $viewargs($view)
91
- if {$viewfiles($view) ne {}} {
92
- set args [concat $args "--" $viewfiles($view)]
93
- }
90
set order "--topo-order"
91
if {$datemode} {
92
set order "--date-order"
93
}
94
if {[catch {
99
- set fd [open [concat | git log -z --pretty=raw $order \
100
- --parents --boundary $args] r]
95
+ set fd [open [concat | git log -z --pretty=raw $order --parents \
96
+ --boundary $viewargs($view) "--" $viewfiles($view)] r]
97
} err]} {
102
- puts stderr "Error executing git rev-list: $err"
98
+ error_popup "Error executing git rev-list: $err"
99
exit 1
100
}
101
set commfd($view) $fd
@@ -7471,35 +7467,48 @@ catch {source ~/.gitk}
7467
7468
font create optionfont -family sans-serif -size -12
7469
7470
+# check that we can find a .git directory somewhere...
7471
+set gitdir [gitdir]
7472
+if {![file isdirectory $gitdir]} {
7473
+ show_error {} . "Cannot find the git directory \"$gitdir\"."
7474
+ exit 1
7475
+}
7476
+
7477
set revtreeargs {}
7478
+set cmdline_files {}
7479
+set i 0
7480
foreach arg $argv {
7481
switch -regexp -- $arg {
7482
"^$" { }
7483
"^-d" { set datemode 1 }
7484
+ "--" {
7485
+ set cmdline_files [lrange $argv [expr {$i + 1}] end]
7486
+ break
7487
+ }
7488
default {
7489
lappend revtreeargs $arg
7490
}
7491
}
7492
+ incr i
7493
}
7494
7485
-# check that we can find a .git directory somewhere...
7486
-set gitdir [gitdir]
7487
-if {![file isdirectory $gitdir]} {
7488
- show_error {} . "Cannot find the git directory \"$gitdir\"."
7489
- exit 1
7490
-}
7491
-
7492
-set cmdline_files {}
7493
-set i [lsearch -exact $revtreeargs "--"]
7494
-if {$i >= 0} {
7495
- set cmdline_files [lrange $revtreeargs [expr {$i + 1}] end]
7496
- set revtreeargs [lrange $revtreeargs 0 [expr {$i - 1}]]
7497
-} elseif {$revtreeargs ne {}} {
7495
+if {$i >= [llength $argv] && $revtreeargs ne {}} {
7496
+ # no -- on command line, but some arguments (other than -d)
7497
if {[catch {
7498
set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
7499
set cmdline_files [split $f "\n"]
7500
set n [llength $cmdline_files]
7501
set revtreeargs [lrange $revtreeargs 0 end-$n]
7502
+ # Unfortunately git rev-parse doesn't produce an error when
7503
+ # something is both a revision and a filename. To be consistent
7504
+ # with git log and git rev-list, check revtreeargs for filenames.
7505
+ foreach arg $revtreeargs {
7506
+ if {[file exists $arg]} {
7507
+ show_error {} . "Ambiguous argument '$arg': both revision\
7508
+ and filename"
7509
+ exit 1
7510
+ }
7511
+ }
7512
} err]} {
7513
# unfortunately we get both stdout and stderr in $err,
7514
# so look for "fatal:".