[PATCH 2 of 8] hg: warn if repo.ui is passed when creating a peer or a localrepo

Simon Heimberg simohe at besonet.ch
Tue Oct 23 02:28:24 CDT 2012


Am Montag, den 22.10.2012, 16:01 -0500 schrieb Matt Mackall:
> On Mon, 2012-10-22 at 11:55 +0200, Simon Heimberg wrote:
> > # HG changeset patch
> > # User Simon Heimberg <simohe at besonet.ch>
> > # Date 1349372803 -7200
> > # Node ID a20a8a4dd3c5dc4d25cb38d04bff96e75b50e95f
> > # Parent  75053afab605dfef2f51075550fcebf6e10f80db
> > hg: warn if repo.ui is passed when creating a peer or a localrepo
> 
> Fails tests:
> 
> +      src.write_err(' PROGRAMMER WARNING: %s\n' % warnmsg)
> +  NameError: global name 'src' is not defined
> 
> > For not getting the configuration of another repo, baseui has to be used when
> > crating a new repository (or a new peer). Therefore we warn the programmer if
> > the ui of a repo is passed.
> > Because a user also sees this warning (when there is a programming error), the
> > message is short.
> 
> Ugh, no. Let's not pester end users with things they're powerless to
> fix. That anti-pattern is best left to Python core developers.

Agree. But I did not find a better solution. How could a extension
developer be warned his doing something wrong?

> 
> > diff -r 75053afab605 -r a20a8a4dd3c5 mercurial/hg.py
> > --- a/mercurial/hg.py	Don Okt 04 19:46:42 2012 +0200
> > +++ b/mercurial/hg.py	Don Okt 04 19:46:43 2012 +0200
> > @@ -587,6 +587,7 @@
> >          src = src.ui # copy target options from repo
> >      else: # assume it's a global ui object
> >          dst = src.copy() # keep all global options
> > +        src.notinrepo('pass repo (not repo.ui) to hg.peer')
> 
> We make a point of having the ui object have no idea that repo objects
> exist ("layering"). This runs against that, which makes it a "layering
> violation".
> 
peer has no chance to see if a ui object is a global one or inside a
repo when it is not specially marked. And a localrepo should also not
get a global configuration. This is why I moved the check into ui.
Would the function name isglobal be more appropriate?

> Instead, it might be friendlier all around to have the peer constuctor
> look for ui.baseui itself.
> 

ui.baseui does not exist. I do not see a possibility to extract the
global ui out of a ui from a repo . The two configurations only exist
inside a repo (as ui and baseui). So when peer gets ui instead of repo,
it is already to late do do anything than warn.


More information about the Mercurial-devel mailing list