git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: remote set-* <name> and <branch>

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Feb 22, 2012, 00:03 UTC
Message-ID
<20120222000310.GA13237@goldbirke>
In-Reply-To
<7v8vjvg71s.fsf@alter.siamese.dyndns.org>
On Tue, Feb 21, 2012 at 02:23:11PM -0800, Junio C Hamano wrote:
Show 20 quoted lines
> >>>  {
> >>>       local cur_="$cur" cmd="${words[1]}"
> >>>       local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
> >>> +     if [ "$cmd" = "remote" ]; then
> >>> +             c=$((++c))
> >>> +     fi
> >>
> >> I don't know about others, but auto-incrementing a variable and assigning
> >> the result to the same variable, while not wrong at all, hurts my brain.
> >>
> >>        c=$(($c + 1))
> >>
> >> is far more readable and does not suggest there is any funky magic
> >> involved.  Also it is a good habit to get into not to omit $ from
> >> variables inside arithmetic substitution, even though bash allows it and
> >> this script is meant to be consumed only by shells that understand this
> >> bash-ism.
> >>
> >> I do not know offhand if zsh groks it, but the point is that you do not
> >> have to worry about it if you write "$(($c+1))" instead of "$((c+1))".

This c=$((++c)) style increment is used in several completion functions, even in the main entry function _git() itself. If zsh didn't grok it, then completion wouldn't work at all on zsh, because the while loop in _git() would be an endless loop.

Show 22 quoted lines
> > CodingGuidlines suggests to follow local convention, which was
> > "c=$((++c))". This file also uses "++n", "i++" and "((i++))". I will
> > send a v2 patch that normalizes these, open to discussion of course.
> 
> OK, it was my mistake to suggest $c++ in this file; it liberally uses
> dollar-less variables, and I agree that it is a good idea to stick to that
> local convention.
> 
> But I think you went too far in your follow-up patch to make the increment
> and decrement uniform.
> 
> "i++" is so much easier on the eye unless you must use "++i" in order to
> use the value of the incremented "i" in an expression, and the changes to
> turn existing instances of free-standing "i++" to "++i" done only for the
> side effect of incrementing the variables look totally backwards.
> 
> Although I do not deeply care.  Just leaving the new one as you originally
> wrote, i.e.
> 
> 	c=$((++c))
> 
> would have been easier to review for the area experts, I would think.
The issue of this weird increment came up before
  http://thread.gmane.org/gmane.comp.version-control.git/87650/focus=87806

and the conclusion back then was that we kept the existing style. But otherwise I agree, it hurts my brain, too.

Best, Gábor

Previous: Junio C Hamano
Message 14 of 14 in “completion: remote set-* <name> and <branch>”
  1. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 18, 2012
  2. Junio C HamanoFeb 20, 2012
  3. Philip JägenstedtFeb 21, 2012
  4. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 21, 2012
  5. SZEDER GáborFeb 22, 2012
  6. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 22, 2012
  7. 1/4 completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 22, 2012
  8. 2/4 completion: normalize increment/decrement stylePhilip Jägenstedt, Feb 22, 2012
  9. Junio C HamanoFeb 22, 2012
  10. 3/4 completion: remove stale "to submit patches" documentationPhilip Jägenstedt, Feb 22, 2012
  11. 4/4 completion: use tabs for indentationPhilip Jägenstedt, Feb 22, 2012
  12. Thomas RastFeb 22, 2012
  13. Junio C HamanoFeb 21, 2012
  14. SZEDER GáborFeb 22, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.