zsh-workers
 help / color / mirror / code / Atom feed
* [(I)-foo] subscripting in _git
@ 2011-07-21 10:32 Mikael Magnusson
  2011-07-21 11:21 ` Nikolai Weibull
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2011-07-21 10:32 UTC (permalink / raw)
  To: zsh workers, Nikolai Weibull

I noticed while looking at _git-add that _git does a lot of this type of thing:
if (( words[(I)-n|--dry-run] )); then
that particular example is fine, but further down is this
if [[ -n ${line[(I)-f|--force]} ]]; then
which seems to have two problems, first it uses line instead of words,
so it never matches. Second it uses [[ -n ]] which will always be true
as (I) returns a 0 when it didn't match. There appears to be other
occurences of this pattern in the file, and before I go changing all
of them I wanted to ask if I missed something obvious? It also looks
like _arguments changes $words, as I had to do this to make it work.

@@ -38,6 +38,8 @@
 _git-add () {
   local curcontext=$curcontext state line
   declare -A opt_args
+  local -a owords
+  owords=($words)
@@ -63,7 +65,7 @@ _git-add () {
     (file)
       # TODO: Use __git_ignore_line_inside_arguments.
       declare -a ignored_files_alternatives
-      if [[ -n ${line[(I)-f|--force]} ]]; then
+      if (( ${owords[(I)-f|--force]} )); then
         ignored_files_alternatives=(


-- 
Mikael Magnusson


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

* Re: [(I)-foo] subscripting in _git
  2011-07-21 10:32 [(I)-foo] subscripting in _git Mikael Magnusson
@ 2011-07-21 11:21 ` Nikolai Weibull
  2011-07-21 11:29   ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Nikolai Weibull @ 2011-07-21 11:21 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh workers

On Thu, Jul 21, 2011 at 12:32, Mikael Magnusson <mikachu@gmail.com> wrote:
> I noticed while looking at _git-add that _git does a lot of this type of thing:
> if (( words[(I)-n|--dry-run] )); then
> that particular example is fine, but further down is this
> if [[ -n ${line[(I)-f|--force]} ]]; then
> which seems to have two problems, first it uses line instead of words,
> so it never matches.

If you check out the latest revision, however, this has been fixed.  I
fixed it an hour or so ago.  The correct pattern when checking for an
option processed by _arguments is if [[ -n ${opt_args[(I)-o|--option]}
]]; then …; fi.

There are, based on my checks, no other instances of the incorrect pattern.


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

* Re: [(I)-foo] subscripting in _git
  2011-07-21 11:21 ` Nikolai Weibull
@ 2011-07-21 11:29   ` Mikael Magnusson
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2011-07-21 11:29 UTC (permalink / raw)
  To: Nikolai Weibull; +Cc: zsh workers

On 21 July 2011 13:21, Nikolai Weibull <now@bitwi.se> wrote:
> On Thu, Jul 21, 2011 at 12:32, Mikael Magnusson <mikachu@gmail.com> wrote:
>> I noticed while looking at _git-add that _git does a lot of this type of thing:
>> if (( words[(I)-n|--dry-run] )); then
>> that particular example is fine, but further down is this
>> if [[ -n ${line[(I)-f|--force]} ]]; then
>> which seems to have two problems, first it uses line instead of words,
>> so it never matches.
>
> If you check out the latest revision, however, this has been fixed.  I
> fixed it an hour or so ago.  The correct pattern when checking for an
> option processed by _arguments is if [[ -n ${opt_args[(I)-o|--option]}
> ]]; then …; fi.
>
> There are, based on my checks, no other instances of the incorrect pattern.

You left out this part of my mail:
> Second it uses [[ -n ]] which will always be true as (I) returns a
> 0 when it didn't match.

The obvious part that I was missing is that opt_args is an associative
array, which changes the meaning of (I). :)

-- 
Mikael Magnusson


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

end of thread, other threads:[~2011-07-21 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 10:32 [(I)-foo] subscripting in _git Mikael Magnusson
2011-07-21 11:21 ` Nikolai Weibull
2011-07-21 11:29   ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).