mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-18 10:23:06 -05:00
git-gui: Smarter command line parsing for browser, blame
The browser subcommand now optionally accepts a single revision argument; if no revision argument is supplied then we use the current branch as the tree to browse. This is very common, so its a nice option. Our blame subcommand now tries to perform the same assumptions as the command line git-blame; both the revision and the file are optional. We assume the argument is a filename if the file exists in the working directory, otherwise we assume the argument is a revision name. A -- can be supplied between the two to force parsing, or before the filename to force it to be a filename. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
56
git-gui.sh
56
git-gui.sh
@@ -1578,25 +1578,63 @@ bind all <$M1B-Key-Q> do_quit
|
|||||||
bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
|
bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
|
||||||
bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
|
bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
|
||||||
|
|
||||||
|
set subcommand_args {}
|
||||||
|
proc usage {} {
|
||||||
|
puts stderr "usage: $::argv0 $::subcommand $::subcommand_args"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# -- Not a normal commit type invocation? Do that instead!
|
# -- Not a normal commit type invocation? Do that instead!
|
||||||
#
|
#
|
||||||
switch -- $subcommand {
|
switch -- $subcommand {
|
||||||
browser {
|
browser {
|
||||||
if {[llength $argv] != 1} {
|
set subcommand_args {rev?}
|
||||||
puts stderr "usage: $argv0 browser commit"
|
switch [llength $argv] {
|
||||||
exit 1
|
0 {
|
||||||
|
set current_branch [git symbolic-ref HEAD]
|
||||||
|
regsub ^refs/((heads|tags|remotes)/)? \
|
||||||
|
$current_branch {} current_branch
|
||||||
|
}
|
||||||
|
1 {
|
||||||
|
set current_branch [lindex $argv 0]
|
||||||
|
}
|
||||||
|
default usage
|
||||||
}
|
}
|
||||||
set current_branch [lindex $argv 0]
|
|
||||||
browser::new $current_branch
|
browser::new $current_branch
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
blame {
|
blame {
|
||||||
if {[llength $argv] != 2} {
|
set subcommand_args {rev? path?}
|
||||||
puts stderr "usage: $argv0 blame commit path"
|
set path {}
|
||||||
exit 1
|
set is_path 0
|
||||||
|
foreach a $argv {
|
||||||
|
if {$is_path || [file exists $_prefix$a]} {
|
||||||
|
if {$path ne {}} usage
|
||||||
|
set path $a
|
||||||
|
break
|
||||||
|
} elseif {$a eq {--}} {
|
||||||
|
if {$path ne {}} {
|
||||||
|
if {$current_branch ne {}} usage
|
||||||
|
set current_branch $path
|
||||||
|
set path {}
|
||||||
|
}
|
||||||
|
set is_path 1
|
||||||
|
} elseif {$current_branch eq {}} {
|
||||||
|
if {$current_branch ne {}} usage
|
||||||
|
set current_branch $a
|
||||||
|
} else {
|
||||||
|
usage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set current_branch [lindex $argv 0]
|
unset is_path
|
||||||
blame::new $current_branch $_prefix[lindex $argv 1]
|
|
||||||
|
if {$current_branch eq {} && $path ne {}} {
|
||||||
|
set current_branch [git symbolic-ref HEAD]
|
||||||
|
regsub ^refs/((heads|tags|remotes)/)? \
|
||||||
|
$current_branch {} current_branch
|
||||||
|
}
|
||||||
|
if {$current_branch eq {} || $path eq {}} usage
|
||||||
|
blame::new $current_branch $path
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
citool -
|
citool -
|
||||||
|
|||||||
Reference in New Issue
Block a user