Patchwork [4,of,6] profile: make the contextmanager object available to the callers

login
register
mail settings
Submitter Pierre-Yves David
Date June 9, 2017, 12:33 p.m.
Message ID <1642a7b657e057cd0404.1497011580@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21281/
State Accepted
Headers show

Comments

Pierre-Yves David - June 9, 2017, 12:33 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497004965 -3600
#      Fri Jun 09 11:42:45 2017 +0100
# Node ID 1642a7b657e057cd0404cd4f33528e3cc272dfee
# Parent  83187f3e565e3f5cfa68056554cd0c6dff97daa4
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 1642a7b657e0
profile: make the contextmanager object available to the callers

This will allow calling methods on the object in the code using the context
manager.

Patch

diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -160,6 +160,7 @@  class profile(object):
         self._entered = True
         if self._enabled:
             self.start()
+        return self
 
     def start(self):
         """Start profiling.
@@ -230,5 +231,5 @@  def maybeprofile(ui):
     just use a single code path for calling into code you may want to profile
     and this function determines whether to start profiling.
     """
-    with profile(ui, enabled=ui.configbool('profiling', 'enabled')):
-        yield
+    with profile(ui, enabled=ui.configbool('profiling', 'enabled')) as p:
+        yield p