LWN.net Logo

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

From:  Matt Mackall <mpm-AT-selenic.com>
To:  Simon Heimberg <simohe-AT-besonet.ch>
Subject:  Re: [PATCH 2 of 8] hg: warn if repo.ui is passed when creating a peer or a localrepo
Date:  Mon, 22 Oct 2012 16:01:43 -0500
Message-ID:  <1350939703.16337.67.camel@calx>
Cc:  Mercurial-devel <Mercurial-devel-AT-selenic.com>
Archive-link:  Article, Thread

On Mon, 2012-10-22 at 11:55 +0200, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@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.

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

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

-- 
Mathematics is the supreme nostalgia of our time.




(Log in to post comments)

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds