[PATCH RFC] clone: copy hgrc paths if source and dest are local

Adrian Buehlmann adrian at cadifra.com
Mon Jun 14 03:51:46 CDT 2010


On 14.06.2010 08:48, Peter Arrenbrecht wrote:
> On Sun, Jun 13, 2010 at 8:13 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:
>> On 13.06.2010 16:35, Bill Barry wrote:
>>> Adrian Buehlmann wrote:
>>>> On 13.06.2010 15:32, Adrian Buehlmann wrote:
>>>>
>>>>> On 13.06.2010 15:28, Adrian Buehlmann wrote:
>>>>>
>>>>>> # HG changeset patch
>>>>>> # User Adrian Buehlmann <adrian at cadifra.com>
>>>>>> # Date 1276435473 -7200
>>>>>> # Node ID 237a4167922c61f1ac6ad68e6fcf62a3f15c446f
>>>>>> # Parent  285bcf40e04bf8ec0980d3238a4d71e886054ed9
>>>>>> clone: copy hgrc paths if source and dest are local
>>>>>>
>>>>>> diff --git a/mercurial/hg.py b/mercurial/hg.py
>>>>>> --- a/mercurial/hg.py
>>>>>> +++ b/mercurial/hg.py
>>>>>> @@ -344,6 +344,10 @@ def clone(ui, source, dest=None, pull=Fa
>>>>>>              fp = dest_repo.opener("hgrc", "w", text=True)
>>>>>>              fp.write("[paths]\n")
>>>>>>              fp.write("default = %s\n" % abspath)
>>>>>> +            if src_repo.local():
>>>>>> +                for n, p in src_repo.ui.configitems('paths'):
>>>>>> +                    if n != 'default':
>>>>>> +                        fp.write("%s = %s\n" % (n, p))
>>>>>>              fp.close()
>>>>>>
>>>>>>              dest_repo.ui.setconfig('paths', 'default', abspath)
>>>>>>
>>>>> Would this make sense?
>>>>>
>>>>>
>>>>
>>>> No it doesn't, as it sets repo-local identical overrides for global
>>>> config paths in the local .hg/hgrc of the destination repo, which is
>>>> unwanted.
>>>
>>> +1
>>>
>>> If you want global paths, simply set them up globally. My local paths
>>> are usually localized from one repo to another.
>>
>> It's not possible to setup subgroups of global paths though.
>>
>> For example, when doing a GUI (TortoiseHg in my case), we show a list of
>> all paths available (repo.ui.configitems('paths')) for a repo, which
>> then includes all global paths (let's assume there is one global
>> 'mercurial.ini' or 'hgrc' for the user with those global paths).
>>
>> But I as a user have repositories that are grouped into related
>> repositories, e.g. group A is "all mercurial clones", group B is "all
>> TortoiseHg clones", etc.
>>
>> If I am inside a mercurial clone (opened in my GUI), I don't want to
>> have the TortoiseHg paths in scope, i.e. the UI shouldn't show me the
>> TortoiseHg paths if I open the list of defined paths.
> 
> Just an idea: We add a [groups] setting to .hg/hgrc, and this causes
> hg to also read ~/.hgrc.x for every x in [groups], containing
> per-group overrides for ~/.hgrc. Then we make local clones copy the
> [groups] setting. This might also be a solution for what I once
> attempted to solve by having hg go back the parent dir hierarchy
> looking for .hgrc.defaults files. Or we use a single group=x setting
> to keep this simpler and use include files in ~/.hgrc.x instead if we
> need composable aspects in .hgrc.
> -parren
> 

Thanks for the idea. Perhaps we can avoid introducing yet more config files.

How about defining a new section [pathgroups] (or just take the name
[groups] for it, dunno).

A path group consists of a set of paths.

Then we define a reserved path group name 'default', which sets the
default path group ("the scope").

Example:

Contents of file 'mercurial.ini' for user A (user-global):

[paths]
thg = https://abuehl@bitbucket.org/tortoisehg/stable
thgqt = https://abuehl@bitbucket.org/tortoisehg/thg
thg-cplex = https://abuehl@hg01.codeplex.com/tortoisehg
thgqt-cplex = https://abuehl@hg01.codeplex.com/thgqt
hg-main = http://selenic.com/repo/hg
hg-crew = http://hg.intevation.org/mercurial/crew

[pathgroups]
thg-group = thg thgqt thg-cplex thgqt-cplex
hg-group = hg-main hg-crew
default = thg-group


Contents of the file '.hg/hgrc' of repo X:

[paths]
default = http://selenic.com/repo/hg

[pathgroups]
default = hg-group


If I then open repo X in TortoiseHg and look at the list of paths for
pulling and pushing, that list then consists of

http://selenic.com/repo/hg
http://hg.intevation.org/mercurial/crew

We could then copy the 'default' entry of [pathgroups] when doing a
local clone.

For command line mercurial usage, the effect of setting a default group
could be that the 'hg paths' command would list only the paths of the
default group (if a default group has been set). Using my above example:

$ hg paths
hg-main = http://selenic.com/repo/hg
hg-crew = http://hg.intevation.org/mercurial/crew

when I'm inside repo X.

With a new '--all' option, we could list all paths:

$ hg paths --all
thg = https://abuehl@bitbucket.org/tortoisehg/stable/
thgqt = https://abuehl@bitbucket.org/tortoisehg/thg
thg-cplex = https://abuehl@hg01.codeplex.com/tortoisehg
thgqt-cplex = https://abuehl@hg01.codeplex.com/thgqt
hg-main = http://selenic.com/repo/hg
hg-crew = http://hg.intevation.org/mercurial/crew


Older versions of mercurial/TortoiseHg would just ignore [pathgroups]
and continue to work exactly as they did before.

More recent versions of mercurial/TortoiseHg would honor [pathgroups]
and behave as described above (if a default group has been set).

We might as well just declare [pathgroups] specific for TortoiseHg for
now and first implement it on TortoiseHg only.


More information about the Mercurial-devel mailing list