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

Re: Alphabetize git config --list

From
Jeff King <peff@peff.net>
Date
May 29, 2012, 08:49 UTC
Message-ID
<20120529084940.GA15145@sigill.intra.peff.net>
In-Reply-To
<4FC45CEB.4070808@alum.mit.edu>
On Tue, May 29, 2012 at 07:21:47AM +0200, Michael Haggerty wrote:
Show 11 quoted lines
> >>Essentially this
> >>$ git config --list | sort
> >
> >No, it's not a good idea; the order of keys is important. For example,
> >[...]
> 
> Is the order of *keys* important, or only the order of *values* for a
> given key?  I believe that one could sort the output by key as long
> as the values for each key are kept in their original order (i.e.,
> sort stably by key).  This would indeed make it easier to read the
> output.

Good question. I was thinking of the order of values, but you're right that a stable key-only sort would handle that.

In general, keys are independent, but there are two exceptions I can think of:

  1. We sometimes have aliased keys that get parsed to the same memory
     location (usually this is to maintain backwards compatibility when
     a key is renamed, or wants to grow incompatible features). For
     example, "diff.color" and "color.diff" override each other, and
     their order is important. Also, "diff.funcname" and "diff.xfuncname".
     There may also be others.
  2. Keys which involve pattern matching. The url.*.insteadOf keys seem
     to be order-independent, as they the longest match is used, not the
     first. The credential context-matching code takes all matches
     (though technically, things like the order in which helpers are
     called would be changed by a sort). I can't think of any others
     offhand.

So yes, I think the key order does matter, though only in a few corner cases.

-Peff
Previous: Michael Haggerty
Message 4 of 4 in “Alphabetize git config --list”
  1. ZachMay 28, 2012
  2. Jeff KingMay 28, 2012
  3. Michael HaggertyMay 29, 2012
  4. Jeff KingMay 29, 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.