> A small thing, "except ValueError" ?
> (and debug prints)
I I've got this bad habit of not specifying the exception type when I
believe its obvious that only one type of exception can be thrown. I must
stop doing that!
Also, I should create a commit hook that warns me about print statements
our something :-P
> ui.ui() returns merged values of both user and repository settings.
> So we cannot rely on it in settings dialog.
Actually I'm not too happy that I'm relaying on the ui.config methods at
all. They return dicts, which do not prevent the item order as you know. I
want the tools to appear on a predictable order. Using dicts makes this
hard to do. I wish I could use ordereddicts, but I don't think python 2.4
sports them.
Any suggestions?
> Also, it looks some variables of ToolListBox loaded separately:
> - this setValue() updates only `curvalue`
> - `tortoisehgtools`, `toolnames` are loaded at __init__()
> - and value() returns `(tortoisehgtools, toolnames)`
> Isn't it a bit strange?
when I originally wrote this code it made sense to me, but I'll look into
that again (I'm replying from my phone)
>> ui.ui() returns merged values of both user and repository settings.
>> So we cannot rely on it in settings dialog.
> Actually I'm not too happy that I'm relaying on the ui.config methods at
> all. They return dicts, which do not prevent the item order as you know. I
> want the tools to appear on a predictable order. Using dicts makes this
> hard to do. I wish I could use ordereddicts, but I don't think python 2.4
> sports them.
>>> ui.ui() returns merged values of both user and repository settings.
>>> So we cannot rely on it in settings dialog.
>> Actually I'm not too happy that I'm relaying on the ui.config methods at
>> all. They return dicts, which do not prevent the item order as you know.
I
>> want the tools to appear on a predictable order. Using dicts makes this
>> hard to do. I wish I could use ordereddicts, but I don't think python 2.4
>> sports them.
These methods ensure that the last value that is set for a given
configuration key is the one that is taken into account. But they work with
dicts. As far as I know there is no way to retrieve different keys in the
order they were set, is there?
> These methods ensure that the last value that is set for a given
> configuration key is the one that is taken into account. But they work with
> dicts. As far as I know there is no way to retrieve different keys in the
> order they were set, is there?
.items() or iterator should preserve the order. Isn't it sufficient?
In [2]: cfg = config.config()
In [3]: cfg.read('.hgrc')
In [16]: cfg['tortoisehg-tools'].items()
Out[16]:
[('update_to_tip.command', 'hg update tip'),
('update_to_tip.icon', 'hg-update'),
('update_to_tip.showoutput', 'True'),
('update_to_tip.tooltip', 'Update to tip'),
('update_to_nil.command', 'hg update null'),
('update_to_nil.enable', 'istrue'),
('update_to_nil.icon', 'hg-update'),
('update_to_nil.location', 'workbench repowidget'),
('update_to_nil.showoutput', 'False'),
('update_to_nil.tooltip', 'Update to null')]
In [18]: list(cfg['tortoisehg-tools']) # calls __iter__()
Out[18]:
['update_to_tip.command',
'update_to_tip.icon',
'update_to_tip.showoutput',
'update_to_tip.tooltip',
'update_to_nil.command',
'update_to_nil.enable',
'update_to_nil.icon',
'update_to_nil.location',
'update_to_nil.showoutput',
'update_to_nil.tooltip']
>> These methods ensure that the last value that is set for a given
>> configuration key is the one that is taken into account. But they work
>> with
>> dicts. As far as I know there is no way to retrieve different keys in the
>> order they were set, is there?
> .items() or iterator should preserve the order. Isn't it sufficient?
Return a copy of the dictionary’s list of (key, value) pairs.
CPython implementation detail: Keys and values are listed in an
arbitrary order which is non-random, varies across Python
implementations, and depends on the dictionary’s history of insertions
and deletions.
</quote>
So I think it is unwise to rely on the item order to correspond to the
order in which items were added to the dict.
Cheers,
Angel
P.S.- Did you get a chance to have a look at the couple of small
changes to the repowidget context menu that I sent a few days ago?
>>> These methods ensure that the last value that is set for a given
>>> configuration key is the one that is taken into account. But they work
>>> with
>>> dicts. As far as I know there is no way to retrieve different keys in the
>>> order they were set, is there?
>> .items() or iterator should preserve the order. Isn't it sufficient?
> Return a copy of the dictionary s list of (key, value) pairs.
> CPython implementation detail: Keys and values are listed in an
> arbitrary order which is non-random, varies across Python
> implementations, and depends on the dictionary s history of insertions
> and deletions.
> </quote>
> So I think it is unwise to rely on the item order to correspond to the
> order in which items were added to the dict.
> Cheers,
> Angel
> P.S.- Did you get a chance to have a look at the couple of small
> changes to the repowidget context menu that I sent a few days ago?
Sorry, I did't read these mails yet. I'll check them later.
>>>> These methods ensure that the last value that is set for a given
>>>> configuration key is the one that is taken into account. But they work
>>>> with
>>>> dicts. As far as I know there is no way to retrieve different keys in
>>>> the
>>>> order they were set, is there?
>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>>> These methods ensure that the last value that is set for a given
>>>>> configuration key is the one that is taken into account. But they work
>>>>> with
>>>>> dicts. As far as I know there is no way to retrieve different keys in
>>>>> the
>>>>> order they were set, is there?
>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>> It's a sortdict object:
>> In [7]: type(cfg)
>> Out[7]: mercurial.config.config
>> In [8]: type(cfg['tortoisehg-tools'])
>> Out[8]: mercurial.config.sortdict
>> And some methods of sortdict keeps insertion order by using extra _list
>> attribute:
>> In [9]: cfg['tortoisehg-tools']._list
>> Out[9]:
>> ['update_to_tip.command',
>> ...
> That is awesome. It will make things much simpler then! :-D
> Thanks for the info,
> Angel
Yuya,
I've been looking into your suggestion but I am unsure how can I use
it. I have several problems:
1. ui.configitems() returns a list of tuples, with every tuple
representing an entry on the section being read. The order of the list
items is random (i.e. it does not follow the order in which each item
was declared on the hgrc files). This makes me believe that a regular
python dictionary is being used internally by ui.configitems.
2. Even if I use a mercurial.confing.config object, when I do:
> On Wed, May 2, 2012 at 10:39 AM, Angel Ezquerra
> <angel.ezque...@gmail.com> wrote:
>> On Wed, May 2, 2012 at 10:31 AM, Yuya Nishihara<y...@tcha.org> wrote:
>>> On 05/02/2012 05:05 PM, Angel Ezquerra wrote:
>>>> On Wed, May 2, 2012 at 9:58 AM, Yuya Nishihara<y...@tcha.org> wrote:
>>>>> On 05/01/2012 01:00 AM, Angel Ezquerra wrote:
>>>>>> On Apr 30, 2012 5:11 PM, "Yuya Nishihara"<y...@tcha.org> wrote:
>>>>>> These methods ensure that the last value that is set for a given
>>>>>> configuration key is the one that is taken into account. But they work
>>>>>> with
>>>>>> dicts. As far as I know there is no way to retrieve different keys in
>>>>>> the
>>>>>> order they were set, is there?
>>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>>> It's a sortdict object:
>>> In [7]: type(cfg)
>>> Out[7]: mercurial.config.config
>>> In [8]: type(cfg['tortoisehg-tools'])
>>> Out[8]: mercurial.config.sortdict
>>> And some methods of sortdict keeps insertion order by using extra _list
>>> attribute:
>>> In [9]: cfg['tortoisehg-tools']._list
>>> Out[9]:
>>> ['update_to_tip.command',
>>> ...
>> That is awesome. It will make things much simpler then! :-D
>> Thanks for the info,
>> Angel
> Yuya,
> I've been looking into your suggestion but I am unsure how can I use
> it. I have several problems:
> 1. ui.configitems() returns a list of tuples, with every tuple
> representing an entry on the section being read. The order of the list
> items is random (i.e. it does not follow the order in which each item
> was declared on the hgrc files). This makes me believe that a regular
> python dictionary is being used internally by ui.configitems.
> 2. Even if I use a mercurial.confing.config object, when I do:
> type(cfg['tortoisehg-tools'])
> I get:
> <type 'dict'>
> rather than:
> mercurial.config.sortdict()
If it's a normal dict, ui.configitems() won't preserve the original order.
Could you send me a patch to reproduce the problem? I cannot find the culprit.
>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>> work
>>>>>>> with
>>>>>>> dicts. As far as I know there is no way to retrieve different keys in
>>>>>>> the
>>>>>>> order they were set, is there?
>>>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>>>> It's a sortdict object:
>>>> In [7]: type(cfg)
>>>> Out[7]: mercurial.config.config
>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>> Out[8]: mercurial.config.sortdict
>>>> And some methods of sortdict keeps insertion order by using extra _list
>>>> attribute:
>>>> In [9]: cfg['tortoisehg-tools']._list
>>>> Out[9]:
>>>> ['update_to_tip.command',
>>>> ...
>>> That is awesome. It will make things much simpler then! :-D
>>> Thanks for the info,
>>> Angel
>> Yuya,
>> I've been looking into your suggestion but I am unsure how can I use
>> it. I have several problems:
>> 1. ui.configitems() returns a list of tuples, with every tuple
>> representing an entry on the section being read. The order of the list
>> items is random (i.e. it does not follow the order in which each item
>> was declared on the hgrc files). This makes me believe that a regular
>> python dictionary is being used internally by ui.configitems.
>> 2. Even if I use a mercurial.confing.config object, when I do:
>> type(cfg['tortoisehg-tools'])
>> I get:
>> <type 'dict'>
>> rather than:
>> mercurial.config.sortdict()
> If it's a normal dict, ui.configitems() won't preserve the original order.
> Could you send me a patch to reproduce the problem? I cannot find the
> culprit.
> Regards,
Yuya, what do you mean? do you want me to resend the "settings: add
tools panel" patch again?
>>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>>> work
>>>>>>>> with
>>>>>>>> dicts. As far as I know there is no way to retrieve different keys in
>>>>>>>> the
>>>>>>>> order they were set, is there?
>>>>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>>>>> It's a sortdict object:
>>>>> In [7]: type(cfg)
>>>>> Out[7]: mercurial.config.config
>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>> Out[8]: mercurial.config.sortdict
>>>>> And some methods of sortdict keeps insertion order by using extra _list
>>>>> attribute:
>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>> Out[9]:
>>>>> ['update_to_tip.command',
>>>>> ...
>>>> That is awesome. It will make things much simpler then! :-D
>>>> Thanks for the info,
>>>> Angel
>>> Yuya,
>>> I've been looking into your suggestion but I am unsure how can I use
>>> it. I have several problems:
>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>> representing an entry on the section being read. The order of the list
>>> items is random (i.e. it does not follow the order in which each item
>>> was declared on the hgrc files). This makes me believe that a regular
>>> python dictionary is being used internally by ui.configitems.
>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>> type(cfg['tortoisehg-tools'])
>>> I get:
>>> <type 'dict'>
>>> rather than:
>>> mercurial.config.sortdict()
>> If it's a normal dict, ui.configitems() won't preserve the original order.
>> Could you send me a patch to reproduce the problem? I cannot find the
>> culprit.
>> Regards,
> Yuya, what do you mean? do you want me to resend the "settings: add
> tools panel" patch again?
No, I want your test code, in which config dict is a dict.
There may be some code path to change sortdict to dict, but I cannot find
where it is.
>>>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>>>> work
>>>>>>>>> with
>>>>>>>>> dicts. As far as I know there is no way to retrieve different keys
>>>>>>>>> in
>>>>>>>>> the
>>>>>>>>> order they were set, is there?
>>>>>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>>>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>>>>>> It's a sortdict object:
>>>>>> In [7]: type(cfg)
>>>>>> Out[7]: mercurial.config.config
>>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>>> Out[8]: mercurial.config.sortdict
>>>>>> And some methods of sortdict keeps insertion order by using extra
>>>>>> _list
>>>>>> attribute:
>>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>>> Out[9]:
>>>>>> ['update_to_tip.command',
>>>>>> ...
>>>>> That is awesome. It will make things much simpler then! :-D
>>>>> Thanks for the info,
>>>>> Angel
>>>> Yuya,
>>>> I've been looking into your suggestion but I am unsure how can I use
>>>> it. I have several problems:
>>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>>> representing an entry on the section being read. The order of the list
>>>> items is random (i.e. it does not follow the order in which each item
>>>> was declared on the hgrc files). This makes me believe that a regular
>>>> python dictionary is being used internally by ui.configitems.
>>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>>> type(cfg['tortoisehg-tools'])
>>>> I get:
>>>> <type 'dict'>
>>>> rather than:
>>>> mercurial.config.sortdict()
>>> If it's a normal dict, ui.configitems() won't preserve the original
>>> order.
>>> Could you send me a patch to reproduce the problem? I cannot find the
>>> culprit.
>>> Regards,
>> Yuya, what do you mean? do you want me to resend the "settings: add
>> tools panel" patch again?
> No, I want your test code, in which config dict is a dict.
> There may be some code path to change sortdict to dict, but I cannot find
> where it is.
> Regards,
I believe I simply added the following to hglib.tortoisehgtools():
>>>>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>>>>> work
>>>>>>>>>> with
>>>>>>>>>> dicts. As far as I know there is no way to retrieve different keys
>>>>>>>>>> in
>>>>>>>>>> the
>>>>>>>>>> order they were set, is there?
>>>>>>>>> .items() or iterator should preserve the order. Isn't it sufficient?
>>>>>>>> Yuya, cfg is a regular python dictionary in this example, is it not?
>>>>>>> It's a sortdict object:
>>>>>>> In [7]: type(cfg)
>>>>>>> Out[7]: mercurial.config.config
>>>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>>>> Out[8]: mercurial.config.sortdict
>>>>>>> And some methods of sortdict keeps insertion order by using extra
>>>>>>> _list
>>>>>>> attribute:
>>>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>>>> Out[9]:
>>>>>>> ['update_to_tip.command',
>>>>>>> ...
>>>>>> That is awesome. It will make things much simpler then! :-D
>>>>>> Thanks for the info,
>>>>>> Angel
>>>>> Yuya,
>>>>> I've been looking into your suggestion but I am unsure how can I use
>>>>> it. I have several problems:
>>>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>>>> representing an entry on the section being read. The order of the list
>>>>> items is random (i.e. it does not follow the order in which each item
>>>>> was declared on the hgrc files). This makes me believe that a regular
>>>>> python dictionary is being used internally by ui.configitems.
>>>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>>>> type(cfg['tortoisehg-tools'])
>>>>> I get:
>>>>> <type 'dict'>
>>>>> rather than:
>>>>> mercurial.config.sortdict()
>>>> If it's a normal dict, ui.configitems() won't preserve the original
>>>> order.
>>>> Could you send me a patch to reproduce the problem? I cannot find the
>>>> culprit.
>>>> Regards,
>>> Yuya, what do you mean? do you want me to resend the "settings: add
>>> tools panel" patch again?
>> No, I want your test code, in which config dict is a dict.
>> There may be some code path to change sortdict to dict, but I cannot find
>> where it is.
>> Regards,
> I believe I simply added the following to hglib.tortoisehgtools():
>>>>>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>>>>>> work
>>>>>>>>>>> with
>>>>>>>>>>> dicts. As far as I know there is no way to retrieve different
>>>>>>>>>>> keys
>>>>>>>>>>> in
>>>>>>>>>>> the
>>>>>>>>>>> order they were set, is there?
>>>>>>>>>> .items() or iterator should preserve the order. Isn't it
>>>>>>>>>> sufficient?
>>>>>>>>> Yuya, cfg is a regular python dictionary in this example, is it
>>>>>>>>> not?
>>>>>>>> It's a sortdict object:
>>>>>>>> In [7]: type(cfg)
>>>>>>>> Out[7]: mercurial.config.config
>>>>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>>>>> Out[8]: mercurial.config.sortdict
>>>>>>>> And some methods of sortdict keeps insertion order by using extra
>>>>>>>> _list
>>>>>>>> attribute:
>>>>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>>>>> Out[9]:
>>>>>>>> ['update_to_tip.command',
>>>>>>>> ...
>>>>>>> That is awesome. It will make things much simpler then! :-D
>>>>>>> Thanks for the info,
>>>>>>> Angel
>>>>>> Yuya,
>>>>>> I've been looking into your suggestion but I am unsure how can I use
>>>>>> it. I have several problems:
>>>>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>>>>> representing an entry on the section being read. The order of the list
>>>>>> items is random (i.e. it does not follow the order in which each item
>>>>>> was declared on the hgrc files). This makes me believe that a regular
>>>>>> python dictionary is being used internally by ui.configitems.
>>>>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>>>>> type(cfg['tortoisehg-tools'])
>>>>>> I get:
>>>>>> <type 'dict'>
>>>>>> rather than:
>>>>>> mercurial.config.sortdict()
>>>>> If it's a normal dict, ui.configitems() won't preserve the original
>>>>> order.
>>>>> Could you send me a patch to reproduce the problem? I cannot find the
>>>>> culprit.
>>>>> Regards,
>>>> Yuya, what do you mean? do you want me to resend the "settings: add
>>>> tools panel" patch again?
>>> No, I want your test code, in which config dict is a dict.
>>> There may be some code path to change sortdict to dict, but I cannot find
>>> where it is.
>>> Regards,
>> I believe I simply added the following to hglib.tortoisehgtools():
>> while I expected it to print:
>> <class 'mercurial.config.config'>
>> <type 'mercurial.config.sortdict'>
> Does '.hg/hgrc' contain [tortoisehg-tools] section?
> If not, cfg['tortoisehg-tools'] will return empty dict.
You are right. That does work. As you said it returns a regular python
dict if the section is not found.
Is there a way to do something akin to ui.configitems, but which
returns a sortdict instead?
Using mecurial.config.config() requires knowing the path of the hgrc
file that you want to read, and instead I'd like to read all the hgrc
files as mercurial does, in the order that mercurial follows, but get
a sortdict...
>>>>>>>>>>>> These methods ensure that the last value that is set for a given
>>>>>>>>>>>> configuration key is the one that is taken into account. But they
>>>>>>>>>>>> work
>>>>>>>>>>>> with
>>>>>>>>>>>> dicts. As far as I know there is no way to retrieve different
>>>>>>>>>>>> keys
>>>>>>>>>>>> in
>>>>>>>>>>>> the
>>>>>>>>>>>> order they were set, is there?
>>>>>>>>>>> .items() or iterator should preserve the order. Isn't it
>>>>>>>>>>> sufficient?
>>>>>>>>>> Yuya, cfg is a regular python dictionary in this example, is it
>>>>>>>>>> not?
>>>>>>>>> It's a sortdict object:
>>>>>>>>> In [7]: type(cfg)
>>>>>>>>> Out[7]: mercurial.config.config
>>>>>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>>>>>> Out[8]: mercurial.config.sortdict
>>>>>>>>> And some methods of sortdict keeps insertion order by using extra
>>>>>>>>> _list
>>>>>>>>> attribute:
>>>>>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>>>>>> Out[9]:
>>>>>>>>> ['update_to_tip.command',
>>>>>>>>> ...
>>>>>>>> That is awesome. It will make things much simpler then! :-D
>>>>>>>> Thanks for the info,
>>>>>>>> Angel
>>>>>>> Yuya,
>>>>>>> I've been looking into your suggestion but I am unsure how can I use
>>>>>>> it. I have several problems:
>>>>>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>>>>>> representing an entry on the section being read. The order of the list
>>>>>>> items is random (i.e. it does not follow the order in which each item
>>>>>>> was declared on the hgrc files). This makes me believe that a regular
>>>>>>> python dictionary is being used internally by ui.configitems.
>>>>>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>>>>>> type(cfg['tortoisehg-tools'])
>>>>>>> I get:
>>>>>>> <type 'dict'>
>>>>>>> rather than:
>>>>>>> mercurial.config.sortdict()
>>>>>> If it's a normal dict, ui.configitems() won't preserve the original
>>>>>> order.
>>>>>> Could you send me a patch to reproduce the problem? I cannot find the
>>>>>> culprit.
>>>>>> Regards,
>>>>> Yuya, what do you mean? do you want me to resend the "settings: add
>>>>> tools panel" patch again?
>>>> No, I want your test code, in which config dict is a dict.
>>>> There may be some code path to change sortdict to dict, but I cannot find
>>>> where it is.
>>>> Regards,
>>> I believe I simply added the following to hglib.tortoisehgtools():
>>> while I expected it to print:
>>> <class 'mercurial.config.config'>
>>> <type 'mercurial.config.sortdict'>
>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>> If not, cfg['tortoisehg-tools'] will return empty dict.
> You are right. That does work. As you said it returns a regular python
> dict if the section is not found.
> Is there a way to do something akin to ui.configitems, but which
> returns a sortdict instead?
> Using mecurial.config.config() requires knowing the path of the hgrc
> file that you want to read, and instead I'd like to read all the hgrc
> files as mercurial does, in the order that mercurial follows, but get
> a sortdict...
Are you trying to use sortdict out of config or ui module?
I think sortdict is designed for internal use, as it lacks keys() or iteritems().
>>>>>>>>>>>>> These methods ensure that the last value that is set for a
>>>>>>>>>>>>> given
>>>>>>>>>>>>> configuration key is the one that is taken into account. But
>>>>>>>>>>>>> they
>>>>>>>>>>>>> work
>>>>>>>>>>>>> with
>>>>>>>>>>>>> dicts. As far as I know there is no way to retrieve different
>>>>>>>>>>>>> keys
>>>>>>>>>>>>> in
>>>>>>>>>>>>> the
>>>>>>>>>>>>> order they were set, is there?
>>>>>>>>>>>> .items() or iterator should preserve the order. Isn't it
>>>>>>>>>>>> sufficient?
>>>>>>>>>>> Yuya, cfg is a regular python dictionary in this example, is it
>>>>>>>>>>> not?
>>>>>>>>>> It's a sortdict object:
>>>>>>>>>> In [7]: type(cfg)
>>>>>>>>>> Out[7]: mercurial.config.config
>>>>>>>>>> In [8]: type(cfg['tortoisehg-tools'])
>>>>>>>>>> Out[8]: mercurial.config.sortdict
>>>>>>>>>> And some methods of sortdict keeps insertion order by using extra
>>>>>>>>>> _list
>>>>>>>>>> attribute:
>>>>>>>>>> In [9]: cfg['tortoisehg-tools']._list
>>>>>>>>>> Out[9]:
>>>>>>>>>> ['update_to_tip.command',
>>>>>>>>>> ...
>>>>>>>>> That is awesome. It will make things much simpler then! :-D
>>>>>>>>> Thanks for the info,
>>>>>>>>> Angel
>>>>>>>> Yuya,
>>>>>>>> I've been looking into your suggestion but I am unsure how can I use
>>>>>>>> it. I have several problems:
>>>>>>>> 1. ui.configitems() returns a list of tuples, with every tuple
>>>>>>>> representing an entry on the section being read. The order of the
>>>>>>>> list
>>>>>>>> items is random (i.e. it does not follow the order in which each
>>>>>>>> item
>>>>>>>> was declared on the hgrc files). This makes me believe that a
>>>>>>>> regular
>>>>>>>> python dictionary is being used internally by ui.configitems.
>>>>>>>> 2. Even if I use a mercurial.confing.config object, when I do:
>>>>>>>> type(cfg['tortoisehg-tools'])
>>>>>>>> I get:
>>>>>>>> <type 'dict'>
>>>>>>>> rather than:
>>>>>>>> mercurial.config.sortdict()
>>>>>>> If it's a normal dict, ui.configitems() won't preserve the original
>>>>>>> order.
>>>>>>> Could you send me a patch to reproduce the problem? I cannot find the
>>>>>>> culprit.
>>>>>>> Regards,
>>>>>> Yuya, what do you mean? do you want me to resend the "settings: add
>>>>>> tools panel" patch again?
>>>>> No, I want your test code, in which config dict is a dict.
>>>>> There may be some code path to change sortdict to dict, but I cannot
>>>>> find
>>>>> where it is.
>>>>> Regards,
>>>> I believe I simply added the following to hglib.tortoisehgtools():
>>>> while I expected it to print:
>>>> <class 'mercurial.config.config'>
>>>> <type 'mercurial.config.sortdict'>
>>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>>> If not, cfg['tortoisehg-tools'] will return empty dict.
>> You are right. That does work. As you said it returns a regular python
>> dict if the section is not found.
>> Is there a way to do something akin to ui.configitems, but which
>> returns a sortdict instead?
>> Using mecurial.config.config() requires knowing the path of the hgrc
>> file that you want to read, and instead I'd like to read all the hgrc
>> files as mercurial does, in the order that mercurial follows, but get
>> a sortdict...
> Are you trying to use sortdict out of config or ui module?
> I think sortdict is designed for internal use, as it lacks keys() or
> iteritems().
What I want is to get the tools defined in the tortoisehg-tools
section in the order in which they are set in that section. The
ui.config methods do not let you do that because they return regular
python objects. I did not know about the mercurial.config.sortdict or
the mercurial.config.config. When you mentioned it it seemed to me
that I may use those for my purpose?
>>>>> while I expected it to print:
>>>>> <class 'mercurial.config.config'>
>>>>> <type 'mercurial.config.sortdict'>
>>>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>>>> If not, cfg['tortoisehg-tools'] will return empty dict.
>>> You are right. That does work. As you said it returns a regular python
>>> dict if the section is not found.
>>> Is there a way to do something akin to ui.configitems, but which
>>> returns a sortdict instead?
>>> Using mecurial.config.config() requires knowing the path of the hgrc
>>> file that you want to read, and instead I'd like to read all the hgrc
>>> files as mercurial does, in the order that mercurial follows, but get
>>> a sortdict...
>> Are you trying to use sortdict out of config or ui module?
>> I think sortdict is designed for internal use, as it lacks keys() or
>> iteritems().
> What I want is to get the tools defined in the tortoisehg-tools
> section in the order in which they are set in that section. The
> ui.config methods do not let you do that because they return regular
> python objects. I did not know about the mercurial.config.sortdict or
> the mercurial.config.config. When you mentioned it it seemed to me
> that I may use those for my purpose?
ui.configitems() should preserve the order. Doesn't it work?
>>>>>> while I expected it to print:
>>>>>> <class 'mercurial.config.config'>
>>>>>> <type 'mercurial.config.sortdict'>
>>>>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>>>>> If not, cfg['tortoisehg-tools'] will return empty dict.
>>>> You are right. That does work. As you said it returns a regular python
>>>> dict if the section is not found.
>>>> Is there a way to do something akin to ui.configitems, but which
>>>> returns a sortdict instead?
>>>> Using mecurial.config.config() requires knowing the path of the hgrc
>>>> file that you want to read, and instead I'd like to read all the hgrc
>>>> files as mercurial does, in the order that mercurial follows, but get
>>>> a sortdict...
>>> Are you trying to use sortdict out of config or ui module?
>>> I think sortdict is designed for internal use, as it lacks keys() or
>>> iteritems().
>> What I want is to get the tools defined in the tortoisehg-tools
>> section in the order in which they are set in that section. The
>> ui.config methods do not let you do that because they return regular
>> python objects. I did not know about the mercurial.config.sortdict or
>> the mercurial.config.config. When you mentioned it it seemed to me
>> that I may use those for my purpose?
> ui.configitems() should preserve the order. Doesn't it work?
This is very weird. If I run:
ui.configitems('tortoisehg-tools')
from mercurial itself (by running hg --debugger and then executing the
command at the debug prompt) I get the list of config items in the
same order that they are on my config file.
However, if I put:
print ui.configitems('tortoisehg-tools')
inside hglib.tortoisehgtools(), I get them in a different order!
I get a list of items which are not in the same order I put them on my
mercurial.ini file.
I am a bit stuck with this patch. I'd like to be able to preserve the
tool ordering. Otherwise each time you edit the tool list you may end
up with a different tool order...
>>>>>>> while I expected it to print:
>>>>>>> <class 'mercurial.config.config'>
>>>>>>> <type 'mercurial.config.sortdict'>
>>>>>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>>>>>> If not, cfg['tortoisehg-tools'] will return empty dict.
>>>>> You are right. That does work. As you said it returns a regular python
>>>>> dict if the section is not found.
>>>>> Is there a way to do something akin to ui.configitems, but which
>>>>> returns a sortdict instead?
>>>>> Using mecurial.config.config() requires knowing the path of the hgrc
>>>>> file that you want to read, and instead I'd like to read all the hgrc
>>>>> files as mercurial does, in the order that mercurial follows, but get
>>>>> a sortdict...
>>>> Are you trying to use sortdict out of config or ui module?
>>>> I think sortdict is designed for internal use, as it lacks keys() or
>>>> iteritems().
>>> What I want is to get the tools defined in the tortoisehg-tools
>>> section in the order in which they are set in that section. The
>>> ui.config methods do not let you do that because they return regular
>>> python objects. I did not know about the mercurial.config.sortdict or
>>> the mercurial.config.config. When you mentioned it it seemed to me
>>> that I may use those for my purpose?
>> ui.configitems() should preserve the order. Doesn't it work?
> This is very weird. If I run:
> ui.configitems('tortoisehg-tools')
> from mercurial itself (by running hg --debugger and then executing the
> command at the debug prompt) I get the list of config items in the
> same order that they are on my config file.
> However, if I put:
> print ui.configitems('tortoisehg-tools')
> inside hglib.tortoisehgtools(), I get them in a different order!
> I get a list of items which are not in the same order I put them on my
> mercurial.ini file.
> I am a bit stuck with this patch. I'd like to be able to preserve the
> tool ordering. Otherwise each time you edit the tool list you may end
> up with a different tool order...
um, very strange. Just in case, could you test it in fresh environment?
You can switch profile by HGRCPATH and APPDATA environment variable.
If any repository's .hgrc defines [tortoisehg-tools] section and if it's
listed in thg-reporegistry.xml, it may happen to override user config.
>>>>>>>> while I expected it to print:
>>>>>>>> <class 'mercurial.config.config'>
>>>>>>>> <type 'mercurial.config.sortdict'>
>>>>>>> Does '.hg/hgrc' contain [tortoisehg-tools] section?
>>>>>>> If not, cfg['tortoisehg-tools'] will return empty dict.
>>>>>> You are right. That does work. As you said it returns a regular python
>>>>>> dict if the section is not found.
>>>>>> Is there a way to do something akin to ui.configitems, but which
>>>>>> returns a sortdict instead?
>>>>>> Using mecurial.config.config() requires knowing the path of the hgrc
>>>>>> file that you want to read, and instead I'd like to read all the hgrc
>>>>>> files as mercurial does, in the order that mercurial follows, but get
>>>>>> a sortdict...
>>>>> Are you trying to use sortdict out of config or ui module?
>>>>> I think sortdict is designed for internal use, as it lacks keys() or
>>>>> iteritems().
>>>> What I want is to get the tools defined in the tortoisehg-tools
>>>> section in the order in which they are set in that section. The
>>>> ui.config methods do not let you do that because they return regular
>>>> python objects. I did not know about the mercurial.config.sortdict or
>>>> the mercurial.config.config. When you mentioned it it seemed to me
>>>> that I may use those for my purpose?
>>> ui.configitems() should preserve the order. Doesn't it work?
>> This is very weird. If I run:
>> ui.configitems('tortoisehg-tools')
>> from mercurial itself (by running hg --debugger and then executing the
>> command at the debug prompt) I get the list of config items in the
>> same order that they are on my config file.
>> However, if I put:
>> print ui.configitems('tortoisehg-tools')
>> inside hglib.tortoisehgtools(), I get them in a different order!
>> I get a list of items which are not in the same order I put them on my
>> mercurial.ini file.
>> I am a bit stuck with this patch. I'd like to be able to preserve the
>> tool ordering. Otherwise each time you edit the tool list you may end
>> up with a different tool order...
> um, very strange. Just in case, could you test it in fresh environment?
> You can switch profile by HGRCPATH and APPDATA environment variable.
> If any repository's .hgrc defines [tortoisehg-tools] section and if it's
> listed in thg-reporegistry.xml, it may happen to override user config.
I don't think that is the problem.
I did the following:
1. add the following code to the top of hglib.tortoisehgtools():
As you can see hglib.tortoisehgtools is called multiple times during
the TortoiseHg startup. The first time the order is correct! However
the second time the function is called (and all the other times) the
order is wrong!
Looking at the hglib.tortoisehgtools() method there seems to be no
catching which could explain the problem. It is probably something
really simple, but it is quite late here and I faile to see it now :-)
> On Sat, May 12, 2012 at 1:44 PM, Yuya Nishihara<y...@tcha.org> wrote:
>> On 05/12/2012 06:10 AM, Angel Ezquerra wrote:
>>>> ui.configitems() should preserve the order. Doesn't it work?
>>> This is very weird. If I run:
>>> ui.configitems('tortoisehg-tools')
>>> from mercurial itself (by running hg --debugger and then executing the
>>> command at the debug prompt) I get the list of config items in the
>>> same order that they are on my config file.
>>> However, if I put:
>>> print ui.configitems('tortoisehg-tools')
>>> inside hglib.tortoisehgtools(), I get them in a different order!
>>> I get a list of items which are not in the same order I put them on my
>>> mercurial.ini file.
>>> I am a bit stuck with this patch. I'd like to be able to preserve the
>>> tool ordering. Otherwise each time you edit the tool list you may end
>>> up with a different tool order...
>> um, very strange. Just in case, could you test it in fresh environment?
>> You can switch profile by HGRCPATH and APPDATA environment variable.
>> If any repository's .hgrc defines [tortoisehg-tools] section and if it's
>> listed in thg-reporegistry.xml, it may happen to override user config.
> As you can see hglib.tortoisehgtools is called multiple times during
> the TortoiseHg startup. The first time the order is correct! However
> the second time the function is called (and all the other times) the
> order is wrong!
> Looking at the hglib.tortoisehgtools() method there seems to be no
> catching which could explain the problem. It is probably something
> really simple, but it is quite late here and I faile to see it now :-)
On Sun, May 13, 2012 at 7:19 AM, Yuya Nishihara <y...@tcha.org> wrote:
> On 05/13/2012 09:47 AM, Angel Ezquerra wrote:
>> On Sat, May 12, 2012 at 1:44 PM, Yuya Nishihara<y...@tcha.org> wrote:
>>> On 05/12/2012 06:10 AM, Angel Ezquerra wrote:
>>>>> ui.configitems() should preserve the order. Doesn't it work?
>>>> This is very weird. If I run:
>>>> ui.configitems('tortoisehg-tools')
>>>> from mercurial itself (by running hg --debugger and then executing the
>>>> command at the debug prompt) I get the list of config items in the
>>>> same order that they are on my config file.
>>>> However, if I put:
>>>> print ui.configitems('tortoisehg-tools')
>>>> inside hglib.tortoisehgtools(), I get them in a different order!
>>>> I get a list of items which are not in the same order I put them on my
>>>> mercurial.ini file.
>>>> I am a bit stuck with this patch. I'd like to be able to preserve the
>>>> tool ordering. Otherwise each time you edit the tool list you may end
>>>> up with a different tool order...
>>> um, very strange. Just in case, could you test it in fresh environment?
>>> You can switch profile by HGRCPATH and APPDATA environment variable.
>>> If any repository's .hgrc defines [tortoisehg-tools] section and if it's
>>> listed in thg-reporegistry.xml, it may happen to override user config.
>> I don't think that is the problem.
> [...]
>> I then added the tortoisehg-tools section back. Its contents are:
>> [tortoisehg-tools]
>> # Execute a mercurial command. These _MUST_ start with "hg"
>> # Note that we can use any built-in TortoiseHg icon
>> update_to_tip.command = hg update -r tip
>> update_to_tip.enable = istrue
>> update_to_tip.location = repowidget
>> update_to_tip.showoutput = False
>> explore_wd.command = explorer.exe /e,{ROOT}
>> explore_wd.enable = iswd
>> explore_wd.label = Open in explorer
>> explore_wd.location = repowidget
>> explore_wd.showoutput = True
>> update_to_1.command = hg update 1
>> update_to_1.icon = hg-update
>> update_to_1.location = repowidget
>> update_to_1.showoutput = True
>> update_to_1.tooltip = Update to 1
>> name.command = command
>> name.enable = istrue
>> name.label = label
>> name.location = workbench repowidget
>> name.showoutput = True
>> name.tooltip = tooltip
>> As you can see hglib.tortoisehgtools is called multiple times during
>> the TortoiseHg startup. The first time the order is correct! However
>> the second time the function is called (and all the other times) the
>> order is wrong!
>> Looking at the hglib.tortoisehgtools() method there seems to be no
>> catching which could explain the problem. It is probably something
>> really simple, but it is quite late here and I faile to see it now :-)
I got write rights on the projrc repo, so I may even push the fix that
you proposed to Martin :-)
In the meantime I can disable the extension and use the
ui.configitems() as it was intended. I thought that ui.configitems()
returned the items in random order because behind the scenes mercurial
was using dicts. In retrospects it makes sense that mercurial would
preserve the order. It seems that the projrc extension was messing
with me the whole time! :-P
Now I can try to finish this patch once and for all! :-D