[PATCH v2] gitk: add -C <path> commandline parameter to change path
From: Juha-Pekka Heikkila <hidden>
Date: 2016-06-15 23:07:11
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
This patch adds -C (change working directory) parameter to
gitk. With this parameter, instead of need to cd to directory
with .git folder, one can point the correct folder from
commandline.
v2: Adjusted the parameter as per Eric's suggestion. I think
it now work in similar manner as in many GNU tools as well
as git itself.
Signed-off-by: Juha-Pekka Heikkila <redacted>
---
Documentation/gitk.txt | 7 +++++++
gitk-git/gitk | 26 +++++++++++++++++---------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt
index 6ade002..d194d9b 100644
--- a/Documentation/gitk.txt
+++ b/Documentation/gitk.txt@@ -146,6 +146,13 @@ gitk-specific options Select the specified commit after loading the graph. Default behavior is equivalent to specifying '--select-commit=HEAD'. +-C <path>:: + + Run as if gitk was started in '<path>' instead of the current + working directory. When multiple `-C` options are given, each + subsequent non-absolute `-C <path>` is interpreted relative to + the preceding `-C <path>`. + Examples -------- gitk v2.6.12.. include/scsi drivers/scsi::
diff --git a/gitk-git/gitk b/gitk-git/gitk
index fcc606e..606474a 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk@@ -12279,20 +12279,14 @@ setui $uicolor setoptions -# check that we can find a .git directory somewhere... -if {[catch {set gitdir [exec git rev-parse --git-dir]}]} { - show_error {} . [mc "Cannot find a git repository here."] - exit 1 -} - set selecthead {} set selectheadid {} set revtreeargs {} set cmdline_files {} -set i 0 set revtreeargscmd {} -foreach arg $argv { +for {set i 0} {$i < [llength $argv]} {incr i} { + set arg [lindex $argv [expr {$i}]] switch -glob -- $arg { "" { } "--" {
@@ -12305,11 +12299,25 @@ foreach arg $argv { "--argscmd=*" { set revtreeargscmd [string range $arg 10 end] } + "-C*" { + if {[string length $arg] < 3} { + incr i + cd [lindex $argv [expr {$i}]] + continue + } else { + cd [string range $arg 2 end] + } + } default { lappend revtreeargs $arg } } - incr i +} + +# check that we can find a .git directory somewhere... +if {[catch {set gitdir [exec git rev-parse --git-dir]}]} { + show_error {} . [mc "Cannot find a git repository here."] + exit 1 } if {$selecthead eq "HEAD"} {
--
1.9.1