From 3e45ee1ef268c73539903f89c737af89034d391f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 8 May 2007 22:36:01 -0400 Subject: [PATCH] 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 --- git-gui.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 8f33f81c5..e90cdde96 100755 --- a/git-gui.sh +++ b/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]} +set subcommand_args {} +proc usage {} { + puts stderr "usage: $::argv0 $::subcommand $::subcommand_args" + exit 1 +} + # -- Not a normal commit type invocation? Do that instead! # switch -- $subcommand { browser { - if {[llength $argv] != 1} { - puts stderr "usage: $argv0 browser commit" - exit 1 + set subcommand_args {rev?} + switch [llength $argv] { + 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 return } blame { - if {[llength $argv] != 2} { - puts stderr "usage: $argv0 blame commit path" - exit 1 + set subcommand_args {rev? path?} + set path {} + 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 + } + } + unset is_path + + if {$current_branch eq {} && $path ne {}} { + set current_branch [git symbolic-ref HEAD] + regsub ^refs/((heads|tags|remotes)/)? \ + $current_branch {} current_branch } - set current_branch [lindex $argv 0] - blame::new $current_branch $_prefix[lindex $argv 1] + if {$current_branch eq {} || $path eq {}} usage + blame::new $current_branch $path return } citool - -- 2.30.2