Skip to content

Commit cdaee5d

Browse files
committed
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>
1 parent c961b22 commit cdaee5d

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

gitk

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,15 @@ proc start_rev_list {view} {
8787

8888
set startmsecs [clock clicks -milliseconds]
8989
set commitidx($view) 0
90-
set args $viewargs($view)
91-
if {$viewfiles($view) ne {}} {
92-
set args [concat $args "--" $viewfiles($view)]
93-
}
9490
set order "--topo-order"
9591
if {$datemode} {
9692
set order "--date-order"
9793
}
9894
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]
10197
} err]} {
102-
puts stderr "Error executing git rev-list: $err"
98+
error_popup "Error executing git rev-list: $err"
10399
exit 1
104100
}
105101
set commfd($view) $fd
@@ -7471,35 +7467,48 @@ catch {source ~/.gitk}
74717467

74727468
font create optionfont -family sans-serif -size -12
74737469

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+
74747477
set revtreeargs {}
7478+
set cmdline_files {}
7479+
set i 0
74757480
foreach arg $argv {
74767481
switch -regexp -- $arg {
74777482
"^$" { }
74787483
"^-d" { set datemode 1 }
7484+
"--" {
7485+
set cmdline_files [lrange $argv [expr {$i + 1}] end]
7486+
break
7487+
}
74797488
default {
74807489
lappend revtreeargs $arg
74817490
}
74827491
}
7492+
incr i
74837493
}
74847494

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)
74987497
if {[catch {
74997498
set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
75007499
set cmdline_files [split $f "\n"]
75017500
set n [llength $cmdline_files]
75027501
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+
}
75037512
} err]} {
75047513
# unfortunately we get both stdout and stderr in $err,
75057514
# so look for "fatal:".

0 commit comments

Comments
 (0)