##// END OF EJS Templates
typing: add type hints to `mercurial.shelve`...
typing: add type hints to `mercurial.shelve` Pytype wasn't flagging anything here yet, but PyCharm was really unhappy about the usage of `state` objects being passed to various methods that accessed attrs on it, without any obvious attrs on the class because there's no contructor. Filling that out made PyCharm happy, and a few other things needed to be filled in to make that easier, so I made a pass over the whole file and filled in the trivial hints. The other repo, ui, context, matcher, and pats items can be filled in after the context and match modules are typed.

File last commit:

r52596:ca7bde5d default
r52709:a1a94d48 default
Show More
connectionpool.py
85 lines | 2.3 KiB | text/x-python | PythonLexer
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 # connectionpool.py - class for pooling peer connections for reuse
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from mercurial import (
hg,
sshpeer,
)
_sshv1peer = sshpeer.sshv1peer
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class connectionpool:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 def __init__(self, repo):
self._repo = repo
self._pool = dict()
def get(self, path):
pathpool = self._pool.get(path)
if pathpool is None:
pathpool = list()
self._pool[path] = pathpool
conn = None
if len(pathpool) > 0:
try:
conn = pathpool.pop()
peer = conn.peer
# If the connection has died, drop it
if isinstance(peer, _sshv1peer):
if peer._subprocess.poll() is not None:
conn = None
except IndexError:
pass
if conn is None:
Valentin Gatien-Baron
remotefilelog: rework workaround for sshpeer deadlocks...
r47417 peer = hg.peer(self._repo.ui, {}, path)
safehasattr: drop usage in favor of hasattr...
r51821 if hasattr(peer, '_cleanup'):
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
Valentin Gatien-Baron
remotefilelog: rework workaround for sshpeer deadlocks...
r47417 class mypeer(peer.__class__):
Valentin Gatien-Baron
sshpeer: add a develwarning if an sshpeer is not closed explicitly...
r47418 def _cleanup(self, warn=None):
Valentin Gatien-Baron
remotefilelog: rework workaround for sshpeer deadlocks...
r47417 # close pipee first so peer.cleanup reading it won't
# deadlock, if there are other processes with pipeo
# open (i.e. us).
safehasattr: drop usage in favor of hasattr...
r51821 if hasattr(self, 'pipee'):
Valentin Gatien-Baron
remotefilelog: rework workaround for sshpeer deadlocks...
r47417 self.pipee.close()
return super(mypeer, self)._cleanup()
peer.__class__ = mypeer
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530
conn = connection(pathpool, peer)
return conn
def close(self):
Gregory Szorc
py3: replace pycompat.itervalues(x) with x.values()...
r49790 for pathpool in self._pool.values():
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 for conn in pathpool:
conn.close()
del pathpool[:]
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class connection:
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 def __init__(self, pool, peer):
self._pool = pool
self.peer = peer
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
# Only add the connection back to the pool if there was no exception,
# since an exception could mean the connection is not in a reusable
# state.
if type is None:
self._pool.append(self)
else:
self.close()
def close(self):
safehasattr: drop usage in favor of hasattr...
r51821 if hasattr(self.peer, 'cleanup'):
Augie Fackler
remotefilelog: import pruned-down remotefilelog extension from hg-experimental...
r40530 self.peer.cleanup()