[PATCH 2 of 7] blackbox: store the blackbox ui object instead of the log file

Durham Goode durham at fb.com
Wed Feb 3 21:45:08 UTC 2016



On 2/1/16 8:14 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at mozdev.org>
> # Date 1454009662 0
> #      Thu Jan 28 19:34:22 2016 +0000
> # Node ID f74757227e3cfdbfbd64e37085d0772e6dae4e29
> # Parent  13667e60c651f6db247234ec46fd040e002420fc
> blackbox: store the blackbox ui object instead of the log file
>
> This enables access to the repo (it does mean one repo leaks
> until process exit...)
>
> diff --git a/hgext/blackbox.py b/hgext/blackbox.py
> --- a/hgext/blackbox.py
> +++ b/hgext/blackbox.py
> @@ -95,7 +95,7 @@
>                   return
>   
>               if util.safehasattr(self, '_blackbox'):
> -                blackbox = self._blackbox
> +                blackbox = self
>               elif util.safehasattr(self, '_bbopener'):
>                   try:
>                       self._blackbox = self._openlogfile()
> @@ -104,28 +104,29 @@
>                                  err.strerror)
>                       del self._bbopener
>                       self._blackbox = None
> -                blackbox = self._blackbox
> +                blackbox = self
>               else:
>                   # certain ui instances exist outside the context of
>                   # a repo, so just default to the last blackbox that
>                   # was seen.
>                   blackbox = lastblackbox
>   
> -            if blackbox:
> +            if (util.safehasattr(blackbox, '_blackbox') and
> +                blackbox._blackbox is not None):
The old check verified that blackbox wasn't None, but you no longer do. 
Is that safe?  Seems like if lastblackbox was None, blackbox here could 
be None as well.

>                   date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
>                   user = util.getuser()
>                   pid = str(os.getpid())
>                   formattedmsg = msg[0] % msg[1:]
>                   rev = '(unknown)'
>                   changed = ''
> -                if util.safehasattr(self, '_bbopenerrepo'):
> -                    ctx = self._bbopenerrepo['.']
> -                    rev = hexfn(self, ctx.node())
> -                    if (any(self._bbopenerrepo.status())
> +                if util.safehasattr(blackbox, '_bbopenerrepo'):
> +                    ctx = blackbox._bbopenerrepo['.']
> +                    rev = hexfn(blackbox, ctx.node())
> +                    if (any(blackbox._bbopenerrepo.status())
>                           or any(ctx.sub(s).dirty() for s in ctx.substate)):
>                           changed = '+'
>                   try:
> -                    blackbox.write('%s %s @%s%s (%s)> %s' %
> +                    blackbox._blackbox.write('%s %s @%s%s (%s)> %s' %
>                                      (date, user, rev, changed, pid, formattedmsg))
The "blackbox._blackbox" naming is a bit confusing.  Is one the ui class 
and one is the file?  Can we stick 'ui' and 'file' on the name to 
distinguish them?  Or rename them entirely?


More information about the Mercurial-devel mailing list