[PATCH 2 of 3] share: use the 'sharedpath' attr on repo instead of reloading from the file

Matt Harbison mharbison72 at gmail.com
Sat Dec 20 21:26:27 CST 2014


On Sat, 20 Dec 2014 18:14:42 -0500, Angel Ezquerra  
<angel.ezquerra at gmail.com> wrote:

> On Fri, Dec 19, 2014 at 6:19 AM, Matt Harbison <mharbison72 at gmail.com>  
> wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1418963057 18000
>> #      Thu Dec 18 23:24:17 2014 -0500
>> # Node ID a2dd116c635236b8d37f5ac20a07b185233cca07
>> # Parent  2e2ea8cb73c5a1861c8b249eaf74336513bba263
>> share: use the 'sharedpath' attr on repo instead of reloading from the  
>> file
>>
>> Seems like a useful optimization, and now the exact file content is not  
>> a
>> concern.
>>
>> diff --git a/hgext/share.py b/hgext/share.py
>> --- a/hgext/share.py
>> +++ b/hgext/share.py
>> @@ -90,18 +90,13 @@
>>      Returns the source repository object for a given shared repository.
>>      If repo is not a shared repository, return None.
>>      """
>> -    srcrepo = None
>> -    try:
>> -        # strip because some tools write with newline after
>> -        sharedpath = repo.vfs.read('sharedpath').strip()
>> -        # the sharedpath always ends in the .hg; we want the path to  
>> the repo
>> -        source = repo.vfs.split(sharedpath)[0]
>> -        srcurl, branches = parseurl(source)
>> -        srcrepo = repository(repo.ui, srcurl)
>> -    except IOError, inst:
>> -        if inst.errno != errno.ENOENT:
>> -            raise
>> -    return srcrepo
>> +    if repo.sharedpath == repo.path:
>> +        return None
>
> A bit unrelated to the body of this patch, but I think that we should
> encapsulate this check to tell if a repository is shared into a
> localrepo method (e.g. localrepo.shared()). IMHO this sort of check
> feels too much like using an implementation detail. I will send a
> patch for this soon.

+1 on that.  subrepo.py does the same check, and also chops the '.hg' off  
(but using os.path.dirname).  It might be nice if your method returned the  
chopped path, or None if not shared.  The method 'isshared()' is ambiguous  
in my mind- is it the source of the share, or shared from something else?   
(I don't see anything that tracks when a src repo is shared, but that's  
not obvious when seeing 'isshared()').

OTOH, hg.py uses repo.sharedpath and expects the '.hg' component in the  
path.  I'm not sure if there's a way to name a method that returns a  
slightly different path and not cause other confusion.

--Matt

> Other than that the patch seems to make sense.
>
> Cheers,
>
> Angel


More information about the Mercurial-devel mailing list