All of lore.kernel.org
 help / color / mirror / Atom feed
* Alphabetize git config --list
@ 2012-05-28 20:58 Zach
  2012-05-28 21:23 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Zach @ 2012-05-28 20:58 UTC (permalink / raw)
  To: git

I was wondering if it would be possible to alphabetically order git
config --list by default.

Essentially this
$ git config --list | sort

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

* Re: Alphabetize git config --list
  2012-05-28 20:58 Alphabetize git config --list Zach
@ 2012-05-28 21:23 ` Jeff King
  2012-05-29  5:21   ` Michael Haggerty
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2012-05-28 21:23 UTC (permalink / raw)
  To: Zach; +Cc: git

On Mon, May 28, 2012 at 01:58:28PM -0700, Zach wrote:

> I was wondering if it would be possible to alphabetically order git
> config --list by default.
> 
> Essentially this
> $ git config --list | sort

No, it's not a good idea; the order of keys is important. For example,
this config:

  [color]
    ui = true
    ui = false

is different than this:

  [color]
    ui = false
    ui = true

While that seems like a contrived example, consider something like a
.git/config repo-specific config file overriding a user-wide
~/.gitconfig file. We do it by overwriting the old key.

There are also some "multi" values which accept multiple entries to
create a list, and the list order may be relevant (I'd have to check,
though; the only one that comes to mind is refspecs, and I don't know
that order matters there).

-Peff

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

* Re: Alphabetize git config --list
  2012-05-28 21:23 ` Jeff King
@ 2012-05-29  5:21   ` Michael Haggerty
  2012-05-29  8:49     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Haggerty @ 2012-05-29  5:21 UTC (permalink / raw)
  To: Jeff King; +Cc: Zach, git

On 05/28/2012 11:23 PM, Jeff King wrote:
> On Mon, May 28, 2012 at 01:58:28PM -0700, Zach wrote:
>
>> I was wondering if it would be possible to alphabetically order git
>> config --list by default.
>>
>> 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.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

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

* Re: Alphabetize git config --list
  2012-05-29  5:21   ` Michael Haggerty
@ 2012-05-29  8:49     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2012-05-29  8:49 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: Zach, git

On Tue, May 29, 2012 at 07:21:47AM +0200, Michael Haggerty wrote:

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

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

end of thread, other threads:[~2012-05-29  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-28 20:58 Alphabetize git config --list Zach
2012-05-28 21:23 ` Jeff King
2012-05-29  5:21   ` Michael Haggerty
2012-05-29  8:49     ` Jeff King

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.