All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] gitk: add --cwd=path commandline parameter to change path
@ 2015-11-03 15:00 Juha-Pekka Heikkila
  2015-11-03 15:00 ` [PATCH 1/1] " Juha-Pekka Heikkila
  0 siblings, 1 reply; 8+ messages in thread
From: Juha-Pekka Heikkila @ 2015-11-03 15:00 UTC (permalink / raw)
  To: git; +Cc: Juha-Pekka Heikkila

I found I needed this option thus made it for myself, maybe others find it 
useful too. I'm not skilled with tcl so if there is something totally wrong 
with my change this is why.

/Juha-Pekka

Juha-Pekka Heikkila (1):
  gitk: add --cwd=path commandline parameter to change path

 Documentation/gitk.txt |  5 +++++
 gitk-git/gitk          | 15 +++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/1] gitk: add --cwd=path commandline parameter to change path
  2015-11-03 15:00 [PATCH 0/1] gitk: add --cwd=path commandline parameter to change path Juha-Pekka Heikkila
@ 2015-11-03 15:00 ` Juha-Pekka Heikkila
  2015-11-03 18:27   ` Eric Sunshine
  0 siblings, 1 reply; 8+ messages in thread
From: Juha-Pekka Heikkila @ 2015-11-03 15:00 UTC (permalink / raw)
  To: git; +Cc: Juha-Pekka Heikkila

This patch adds --cwd (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.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
---
 Documentation/gitk.txt |  5 +++++
 gitk-git/gitk          | 15 +++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt
index 6ade002..1f42198 100644
--- a/Documentation/gitk.txt
+++ b/Documentation/gitk.txt
@@ -146,6 +146,11 @@ gitk-specific options
 	Select the specified commit after loading the graph.
 	Default behavior is equivalent to specifying '--select-commit=HEAD'.
 
+--cwd=<path>::
+
+	Change working direcoty to <path>. If the git tree exist elsewhere
+	gitk first cd to given path before start to operate.
+
 Examples
 --------
 gitk v2.6.12.. include/scsi drivers/scsi::
diff --git a/gitk-git/gitk b/gitk-git/gitk
index fcc606e..5fdf459 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -12279,12 +12279,6 @@ 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 {}
 
@@ -12305,6 +12299,9 @@ foreach arg $argv {
 	"--argscmd=*" {
 	    set revtreeargscmd [string range $arg 10 end]
 	}
+	"--cwd=*" {
+	    cd [string range $arg 6 end]
+	}
 	default {
 	    lappend revtreeargs $arg
 	}
@@ -12312,6 +12309,12 @@ foreach arg $argv {
     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"} {
     set selecthead {}
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] gitk: add --cwd=path commandline parameter to change path
  2015-11-03 15:00 ` [PATCH 1/1] " Juha-Pekka Heikkila
@ 2015-11-03 18:27   ` Eric Sunshine
  2015-11-05  9:19     ` [PATCH v2] gitk: add -C <path> " Juha-Pekka Heikkila
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Sunshine @ 2015-11-03 18:27 UTC (permalink / raw)
  To: Juha-Pekka Heikkila; +Cc: Git List

On Tue, Nov 3, 2015 at 10:00 AM, Juha-Pekka Heikkila
<juhapekka.heikkila@gmail.com> wrote:
> This patch adds --cwd (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.

git itself supports this sort of functionality via -C, as does GNU
tar, which suggests such an option in gitk should be named -C, as
well.

> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
> ---
> diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt
> @@ -146,6 +146,11 @@ gitk-specific options
>         Select the specified commit after loading the graph.
>         Default behavior is equivalent to specifying '--select-commit=HEAD'.
>
> +--cwd=<path>::
> +
> +       Change working direcoty to <path>. If the git tree exist elsewhere

s/direcoty/directory/

> +       gitk first cd to given path before start to operate.

Taking git's -C documentation as a template, perhaps this could be
written instead as:

    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>`.

This description correctly reflects your implementation which allows
--cwd to be specified multiple times.

>  Examples
>  --------
>  gitk v2.6.12.. include/scsi drivers/scsi::
> diff --git a/gitk-git/gitk b/gitk-git/gitk
> index fcc606e..5fdf459 100755
> --- a/gitk-git/gitk
> +++ b/gitk-git/gitk
> @@ -12279,12 +12279,6 @@ 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 {}
>
> @@ -12305,6 +12299,9 @@ foreach arg $argv {
>         "--argscmd=*" {
>             set revtreeargscmd [string range $arg 10 end]
>         }
> +       "--cwd=*" {
> +           cd [string range $arg 6 end]
> +       }
>         default {
>             lappend revtreeargs $arg
>         }
> @@ -12312,6 +12309,12 @@ foreach arg $argv {
>      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"} {
>      set selecthead {}
>  }
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] gitk: add -C <path> commandline parameter to change path
  2015-11-03 18:27   ` Eric Sunshine
@ 2015-11-05  9:19     ` Juha-Pekka Heikkila
  2015-11-06  9:48       ` Eric Sunshine
  0 siblings, 1 reply; 8+ messages in thread
From: Juha-Pekka Heikkila @ 2015-11-05  9:19 UTC (permalink / raw)
  To: git; +Cc: Juha-Pekka Heikkila

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 <juhapekka.heikkila@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] gitk: add -C <path> commandline parameter to change path
  2015-11-05  9:19     ` [PATCH v2] gitk: add -C <path> " Juha-Pekka Heikkila
@ 2015-11-06  9:48       ` Eric Sunshine
  2015-11-06 10:49         ` Juha-Pekka Heikkila
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Sunshine @ 2015-11-06  9:48 UTC (permalink / raw)
  To: Juha-Pekka Heikkila; +Cc: Git List, Paul Mackerras

On Thu, Nov 5, 2015 at 4:19 AM, Juha-Pekka Heikkila
<juhapekka.heikkila@gmail.com> wrote:
> 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.

Thanks, -C makes more sense than --cwd, and is more consistent with
other commands.

You'll want to also address the patch to Paul Mackerras (I've cc:'d
him) since he's the gitk maintainer, and Junio pulls gitk from him.

> 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.

This sort of explanation of of changes between versions is definitely
welcome, but should be placed below the "---" line just under your
sign-off so that it does not become part of the permanent commit
message.

> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
> ---

You'd place your commentary about changes between patch versions here.
More below...

>  Documentation/gitk.txt |  7 +++++++
>  gitk-git/gitk          | 26 +++++++++++++++++---------
>  2 files changed, 24 insertions(+), 9 deletions(-)
>
> diff --git 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}]]

What happens if no arguments follow -C (that is, the entire
command-line is "gitk -C")? Will this simply run "cd" with no argument
or with an empty argument or error out or what? Should there be a
check for this condition?

> +                       continue

Why does this 'continue' need to be here? Am I missing something obvious?

> +               } 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] gitk: add -C <path> commandline parameter to change path
  2015-11-06  9:48       ` Eric Sunshine
@ 2015-11-06 10:49         ` Juha-Pekka Heikkila
  2015-11-09 11:45           ` [PATCH v3] " Juha-Pekka Heikkila
  0 siblings, 1 reply; 8+ messages in thread
From: Juha-Pekka Heikkila @ 2015-11-06 10:49 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Paul Mackerras

On 06.11.2015 11:48, Eric Sunshine wrote:
> On Thu, Nov 5, 2015 at 4:19 AM, Juha-Pekka Heikkila
> <juhapekka.heikkila@gmail.com> wrote:
>> 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.
>
> Thanks, -C makes more sense than --cwd, and is more consistent with
> other commands.
>
> You'll want to also address the patch to Paul Mackerras (I've cc:'d
> him) since he's the gitk maintainer, and Junio pulls gitk from him.
>
>> 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.
>
> This sort of explanation of of changes between versions is definitely
> welcome, but should be placed below the "---" line just under your
> sign-off so that it does not become part of the permanent commit
> message.

Ok, I'll make bit later another version. I didn't realize to check where 
to put this comment as some projects want these in the commit message.

>
>> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
>> ---
>
> You'd place your commentary about changes between patch versions here.
> More below...
>
>>   Documentation/gitk.txt |  7 +++++++
>>   gitk-git/gitk          | 26 +++++++++++++++++---------
>>   2 files changed, 24 insertions(+), 9 deletions(-)
>>
>> diff --git 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}]]
>
> What happens if no arguments follow -C (that is, the entire
> command-line is "gitk -C")? Will this simply run "cd" with no argument
> or with an empty argument or error out or what? Should there be a
> check for this condition?
>
>> +                       continue
>
> Why does this 'continue' need to be here? Am I missing something obvious?
>

I'll add the missing try/catch for these cd commands, I slowly start to 
understand how tcl work. Earlier catch was not for some reason needed 
here when the loop was ran with 'foreach', error was reported once 
reached UI but now it seem to advertise "error in startup script.." 
'continue' was part of this skipping but doesn't do its trick anymore.

Anyway, I'll make v3 and resend. :)

>> +               } 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] gitk: add -C <path> commandline parameter to change path
  2015-11-06 10:49         ` Juha-Pekka Heikkila
@ 2015-11-09 11:45           ` Juha-Pekka Heikkila
  2015-12-19  3:13             ` Paul Mackerras
  0 siblings, 1 reply; 8+ messages in thread
From: Juha-Pekka Heikkila @ 2015-11-09 11:45 UTC (permalink / raw)
  To: git; +Cc: Juha-Pekka Heikkila, sunshine, paulus

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.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>

---
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.

v3: catch error from cd and other small refinement.

 Documentation/gitk.txt |  7 +++++++
 gitk-git/gitk          | 30 +++++++++++++++++++++---------
 2 files changed, 28 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..a7076f8 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,29 @@ foreach arg $argv {
 	"--argscmd=*" {
 	    set revtreeargscmd [string range $arg 10 end]
 	}
+	"-C*" {
+		if {[string length $arg] < 3} {
+			incr i
+			set cwd_path [lindex $argv [expr {$i}]]
+		} else {
+			set cwd_path [string range $arg 2 end]
+		}
+
+		if {[catch {cd $cwd_path}]} {
+			show_error {} . [mc "Cannot change directory to '%s'" $cwd_path]
+			exit 1
+		}
+	}
 	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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] gitk: add -C <path> commandline parameter to change path
  2015-11-09 11:45           ` [PATCH v3] " Juha-Pekka Heikkila
@ 2015-12-19  3:13             ` Paul Mackerras
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Mackerras @ 2015-12-19  3:13 UTC (permalink / raw)
  To: Juha-Pekka Heikkila; +Cc: git, sunshine

On Mon, Nov 09, 2015 at 01:45:22PM +0200, Juha-Pekka Heikkila wrote:
> 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.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>

Thanks.

While I like the idea, there are a couple of minor problems with the
patch.  First, the Documentation directory is in Junio's tree, not
mine, so the change to gitk and the change to Documentation need to be
separated.  Secondly, please use 4-space indentation rather than
8-space for consistency with the rest of the file.  See also the
comments below.

> +	"-C*" {
> +		if {[string length $arg] < 3} {
> +			incr i
> +			set cwd_path [lindex $argv [expr {$i}]]

No need to say [expr {$i}] here; [lindex $argv $i] works just fine.

Also, if i is now >= [llength $argv], we'll get an empty string in
cwd_path.  Is that what you meant?  Shouldn't we display an
appropriate error message instead of trying to cd to ""?

Paul.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-12-19  3:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03 15:00 [PATCH 0/1] gitk: add --cwd=path commandline parameter to change path Juha-Pekka Heikkila
2015-11-03 15:00 ` [PATCH 1/1] " Juha-Pekka Heikkila
2015-11-03 18:27   ` Eric Sunshine
2015-11-05  9:19     ` [PATCH v2] gitk: add -C <path> " Juha-Pekka Heikkila
2015-11-06  9:48       ` Eric Sunshine
2015-11-06 10:49         ` Juha-Pekka Heikkila
2015-11-09 11:45           ` [PATCH v3] " Juha-Pekka Heikkila
2015-12-19  3:13             ` Paul Mackerras

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.