Patchwork blackbox: do not assume self._bb{vfs, repo, fp} are set in blackboxui.__init__

login
register
mail settings
Submitter Jun Wu
Date March 15, 2016, 10:36 a.m.
Message ID <a2a3a40aa29a33d66341.1458038219@x1c>
Download mbox | patch
Permalink /patch/13897/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 15, 2016, 10:36 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1458038162 0
#      Tue Mar 15 10:36:02 2016 +0000
# Node ID a2a3a40aa29a33d6634170bbd5a6b6b8d042c9bf
# Parent  b22ab2690f3170dc5ef3a807d8c44af6fee862a9
blackbox: do not assume self._bb{vfs,repo,fp} are set in blackboxui.__init__

It's possible for the blackboxui code to do a "del self._bbvfs", then ui.copy()
or similar attempt will fail. It will also fail when constructing a blackboxui
from a non-blackbox ui.
This patch fixes the issue by not assuming any _bb* attr is set.
Yuya Nishihara - March 17, 2016, 2:35 p.m.
On Tue, 15 Mar 2016 10:36:59 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1458038162 0
> #      Tue Mar 15 10:36:02 2016 +0000
> # Node ID a2a3a40aa29a33d6634170bbd5a6b6b8d042c9bf
> # Parent  b22ab2690f3170dc5ef3a807d8c44af6fee862a9
> blackbox: do not assume self._bb{vfs,repo,fp} are set in blackboxui.__init__

Queued this, thanks.

> It's possible for the blackboxui code to do a "del self._bbvfs", then ui.copy()
> or similar attempt will fail. It will also fail when constructing a blackboxui
> from a non-blackbox ui.

Another common reason of such failure is that _dispatch() copies lui.__class__
to ui.__class__ dropping the other attributes set in uisetup().

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -80,10 +80,10 @@ 
             if src is None:
                 self._partialinit()
             else:
-                self._bbfp = src._bbfp
+                self._bbfp = getattr(src, '_bbfp', None)
                 self._bbinlog = False
-                self._bbrepo = src._bbrepo
-                self._bbvfs = src._bbvfs
+                self._bbrepo = getattr(src, '_bbrepo', None)
+                self._bbvfs = getattr(src, '_bbvfs', None)
 
         def _partialinit(self):
             if util.safehasattr(self, '_bbvfs'):