Patchwork [stable] bugzilla: stop trying to cache setup across hook invocation

login
register
mail settings
Submitter Jim Hague
Date July 3, 2014, 9:51 a.m.
Message ID <b727de5ad91b70fd4a69.1404381099@url.hover.com>
Download mbox | patch
Permalink /patch/5094/
State Accepted
Commit 1eda3e55684531a1ebd564d8146e8a5f6f4ffcfa
Headers show

Comments

Jim Hague - July 3, 2014, 9:51 a.m.
# HG changeset patch
# User Jim Hague <jim.hague@acm.org>
# Date 1404380917 -3600
#      Thu Jul 03 10:48:37 2014 +0100
# Branch stable
# Node ID b727de5ad91b70fd4a694e54e663b58bce93be99
# Parent  2392b9e1936628faeec818368169a68b1fadd95f
bugzilla: stop trying to cache setup across hook invocation

In the context of standalone Hg receiving a set of incoming changes, it makes
sense for the Bugzilla module to cache basic setup to avoid reconnecting
to Bugzilla for each change. After processing the changes, Hg will exit
and so the connection is short-lived.

But this doesn't work too well when used from a long-lived environment
such as hgweb or RhodeCode where, for example, the connection can time out.
So take the simple approach, abandon the cache and do the basic setup on
each call. This fixes current problems with RhodeCode.
Matt Mackall - July 13, 2014, 5:09 p.m.
On Thu, 2014-07-03 at 10:51 +0100, Jim Hague wrote:
> # HG changeset patch
> # User Jim Hague <jim.hague@acm.org>
> # Date 1404380917 -3600
> #      Thu Jul 03 10:48:37 2014 +0100
> # Branch stable
> # Node ID b727de5ad91b70fd4a694e54e663b58bce93be99
> # Parent  2392b9e1936628faeec818368169a68b1fadd95f
> bugzilla: stop trying to cache setup across hook invocation

Queued for stable, thanks.

Patch

diff -r 2392b9e19366 -r b727de5ad91b hgext/bugzilla.py
--- a/hgext/bugzilla.py	Tue Jul 01 23:32:18 2014 -0500
+++ b/hgext/bugzilla.py	Thu Jul 03 10:48:37 2014 +0100
@@ -777,32 +777,25 @@ 
                        r'(?P<ids>(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
                        r'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?')
 
-    _bz = None
-
     def __init__(self, ui, repo):
         self.ui = ui
         self.repo = repo
 
-    def bz(self):
-        '''return object that knows how to talk to bugzilla version in
-        use.'''
+        bzversion = self.ui.config('bugzilla', 'version')
+        try:
+            bzclass = bugzilla._versions[bzversion]
+        except KeyError:
+            raise util.Abort(_('bugzilla version %s not supported') %
+                             bzversion)
+        self.bzdriver = bzclass(self.ui)
 
-        if bugzilla._bz is None:
-            bzversion = self.ui.config('bugzilla', 'version')
-            try:
-                bzclass = bugzilla._versions[bzversion]
-            except KeyError:
-                raise util.Abort(_('bugzilla version %s not supported') %
-                                 bzversion)
-            bugzilla._bz = bzclass(self.ui)
-        return bugzilla._bz
-
-    def __getattr__(self, key):
-        return getattr(self.bz(), key)
-
-    _bug_re = None
-    _fix_re = None
-    _split_re = None
+        self.bug_re = re.compile(
+            self.ui.config('bugzilla', 'regexp',
+                           bugzilla._default_bug_re), re.IGNORECASE)
+        self.fix_re = re.compile(
+            self.ui.config('bugzilla', 'fixregexp',
+                           bugzilla._default_fix_re), re.IGNORECASE)
+        self.split_re = re.compile(r'\D+')
 
     def find_bugs(self, ctx):
         '''return bugs dictionary created from commit comment.
@@ -811,19 +804,11 @@ 
         not known to Bugzilla, and any that already have a reference to
         the given changeset in their comments.
         '''
-        if bugzilla._bug_re is None:
-            bugzilla._bug_re = re.compile(
-                self.ui.config('bugzilla', 'regexp',
-                               bugzilla._default_bug_re), re.IGNORECASE)
-            bugzilla._fix_re = re.compile(
-                self.ui.config('bugzilla', 'fixregexp',
-                               bugzilla._default_fix_re), re.IGNORECASE)
-            bugzilla._split_re = re.compile(r'\D+')
         start = 0
         hours = 0.0
         bugs = {}
-        bugmatch = bugzilla._bug_re.search(ctx.description(), start)
-        fixmatch = bugzilla._fix_re.search(ctx.description(), start)
+        bugmatch = self.bug_re.search(ctx.description(), start)
+        fixmatch = self.fix_re.search(ctx.description(), start)
         while True:
             bugattribs = {}
             if not bugmatch and not fixmatch:
@@ -839,11 +824,11 @@ 
                     m = fixmatch
             start = m.end()
             if m is bugmatch:
-                bugmatch = bugzilla._bug_re.search(ctx.description(), start)
+                bugmatch = self.bug_re.search(ctx.description(), start)
                 if 'fix' in bugattribs:
                     del bugattribs['fix']
             else:
-                fixmatch = bugzilla._fix_re.search(ctx.description(), start)
+                fixmatch = self.fix_re.search(ctx.description(), start)
                 bugattribs['fix'] = None
 
             try:
@@ -860,14 +845,14 @@ 
             except ValueError:
                 self.ui.status(_("%s: invalid hours\n") % m.group('hours'))
 
-            for id in bugzilla._split_re.split(ids):
+            for id in self.split_re.split(ids):
                 if not id:
                     continue
                 bugs[int(id)] = bugattribs
         if bugs:
-            self.filter_real_bug_ids(bugs)
+            self.bzdriver.filter_real_bug_ids(bugs)
         if bugs:
-            self.filter_cset_known_bug_ids(ctx.node(), bugs)
+            self.bzdriver.filter_cset_known_bug_ids(ctx.node(), bugs)
         return bugs
 
     def update(self, bugid, newstate, ctx):
@@ -902,7 +887,11 @@ 
                root=self.repo.root,
                webroot=webroot(self.repo.root))
         data = self.ui.popbuffer()
-        self.updatebug(bugid, newstate, data, util.email(ctx.user()))
+        self.bzdriver.updatebug(bugid, newstate, data, util.email(ctx.user()))
+
+    def notify(self, bugs, committer):
+        '''ensure Bugzilla users are notified of bug change.'''
+        self.bzdriver.notify(bugs, committer)
 
 def hook(ui, repo, hooktype, node=None, **kwargs):
     '''add comment to bugzilla for each changeset that refers to a