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

Re: [PATCH 1/2] ref-filter: apply --ignore-case to all sorting keys

From
Jeff King <peff@peff.net>
Date
May 4, 2020, 15:13 UTC
Message-ID
<20200504151351.GC11373@coredump.intra.peff.net>
In-Reply-To
<20200503114351.GA28680@danh.dev>
On Sun, May 03, 2020 at 06:44:02PM +0700, Danh Doan wrote:
Show 18 quoted lines
> On 2020-05-03 05:11:57-0400, Jeff King <peff@peff.net> wrote:
> > +test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
> > +	# name refs numerically to avoid case-insensitive filesystem conflicts
> > +	nr=0 &&
> > +	for email in a A b B
> > +	do
> > +		for subject in a A b B
> > +		do
> > +			GIT_COMMITTER_EMAIL="$email@example.com" \
> > +			git tag -m "tag $subject" icase-$(printf %02d $nr) &&
> > +			nr=$((nr+1))||
> 
> The CodingGuidelines said we want to spell `$nr` instead of `nr`
> inside arithmetic expansion for dash older than 0.5.4
> 
> I'm not sure if we should go with just `$((nr+1))` or it's better to
> loosen our Guidelines. Since Debian Jessie (oldest supported Debian)
> ships 0.5.7. I don't know about other systems.

Hmm, somehow I didn't know about that rule. We have many cases already in the test suite and elsewhere (try grepping for '$(([a-z]', which isn't exhaustive but turns up many examples).

Maybe it's time to loosen the rule?

I've actually seen style guides suggesting to never use "$" there for a few reasons:

  - it's slightly cleaner to read (this is the recommendation and
    rationale in Google's shell style guide)
  - it's less surprising if you somehow end up with a non-number in your
    variable:
      $ foo=bar
      $ bar=41
      $ echo $((foo + 1))
      dash: 8: Illegal number: bar
      $ echo $(($foo + 1))
      42
    That's using dash. With bash, both produce the answer 42! Clearly
    this isn't something we should be doing either way, but I'd much
    rather see "illegal number" in some cases which would alert us that
    something confusing is going on.
-Peff
Previous: Danh DoanNext: Junio C Hamano
Message 5 of 21 in “git for-each-ref - sorting by multiple keys”
  1. climeMay 2, 2020
  2. Jeff KingMay 3, 2020
  3. 1/2 ref-filter: apply --ignore-case to all sorting keysJeff King, May 3, 2020
  4. Danh DoanMay 3, 2020
  5. Jeff KingMay 4, 2020
  6. Junio C HamanoMay 4, 2020
  7. CodingGuidelines: drop arithmetic expansion advice to use "$x"Jeff King, May 4, 2020
  8. Carlo Marcelo Arenas BelónMay 4, 2020
  9. Jeff KingMay 4, 2020
  10. Junio C HamanoMay 4, 2020
  11. Danh DoanMay 4, 2020
  12. Junio C HamanoMay 5, 2020
  13. Jeff KingMay 5, 2020
  14. Junio C HamanoMay 5, 2020
  15. Junio C HamanoMay 4, 2020
  16. Jeff KingMay 5, 2020
  17. Taylor BlauMay 5, 2020
  18. 2/2 ref-filter: apply fallback refname sort only after all user sortsJeff King, May 3, 2020
  19. Junio C HamanoMay 4, 2020
  20. Taylor BlauMay 5, 2020
  21. climeMay 3, 2020

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.