Patchwork [4,of,4] chgserver: rename private functions and variables of chgunixservicehandler

login
register
mail settings
Submitter Yuya Nishihara
Date July 18, 2016, 1:53 p.m.
Message ID <357dee3a00fd5a31e2aa.1468850018@mimosa>
Download mbox | patch
Permalink /patch/15939/
State Accepted
Headers show

Comments

Yuya Nishihara - July 18, 2016, 1:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463822199 -32400
#      Sat May 21 18:16:39 2016 +0900
# Node ID 357dee3a00fd5a31e2aa4560a2045825d240ba4d
# Parent  793c1bbd113d7cf862f17a91f6b6ccb8cbc9b15c
chgserver: rename private functions and variables of chgunixservicehandler

self.address has been reanmed to self._realaddress to clarify that it can
be different from the address argument.
Jun Wu - July 18, 2016, 9:24 p.m.
These look good to me. Marked as Pre-Reviewed.

Excerpts from Yuya Nishihara's message of 2016-07-18 22:53:38 +0900:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1463822199 -32400
> #      Sat May 21 18:16:39 2016 +0900
> # Node ID 357dee3a00fd5a31e2aa4560a2045825d240ba4d
> # Parent  793c1bbd113d7cf862f17a91f6b6ccb8cbc9b15c
> chgserver: rename private functions and variables of chgunixservicehandler
> 
> self.address has been reanmed to self._realaddress to clarify that it can
> be different from the address argument.
> 
> diff --git a/hgext/chgserver.py b/hgext/chgserver.py
> --- a/hgext/chgserver.py
> +++ b/hgext/chgserver.py
> @@ -542,8 +542,8 @@ class chgunixservicehandler(object):
>  
>      def __init__(self, ui):
>          self.ui = ui
> -        self.idletimeout = ui.configint('chgserver', 'idletimeout', 3600)
> -        self.lastactive = time.time()
> +        self._idletimeout = ui.configint('chgserver', 'idletimeout', 3600)
> +        self._lastactive = time.time()
>  
>      def bindsocket(self, sock, address):
>          self._inithashstate(address)
> @@ -552,57 +552,57 @@ class chgunixservicehandler(object):
>          self._createsymlink()
>  
>      def _inithashstate(self, address):
> -        self.baseaddress = address
> +        self._baseaddress = address
>          if self.ui.configbool('chgserver', 'skiphash', False):
> -            self.hashstate = None
> -            self.address = address
> +            self._hashstate = None
> +            self._realaddress = address
>              return
> -        self.hashstate = hashstate.fromui(self.ui)
> -        self.address = _hashaddress(address, self.hashstate.confighash)
> +        self._hashstate = hashstate.fromui(self.ui)
> +        self._realaddress = _hashaddress(address, self._hashstate.confighash)
>  
>      def _checkextensions(self):
> -        if not self.hashstate:
> +        if not self._hashstate:
>              return
>          if extensions.notloaded():
>              # one or more extensions failed to load. mtimehash becomes
>              # meaningless because we do not know the paths of those extensions.
>              # set mtimehash to an illegal hash value to invalidate the server.
> -            self.hashstate.mtimehash = ''
> +            self._hashstate.mtimehash = ''
>  
>      def _bind(self, sock):
>          # use a unique temp address so we can stat the file and do ownership
>          # check later
> -        tempaddress = _tempaddress(self.address)
> +        tempaddress = _tempaddress(self._realaddress)
>          util.bindunixsocket(sock, tempaddress)
>          self._socketstat = os.stat(tempaddress)
>          # rename will replace the old socket file if exists atomically. the
>          # old server will detect ownership change and exit.
> -        util.rename(tempaddress, self.address)
> +        util.rename(tempaddress, self._realaddress)
>  
>      def _createsymlink(self):
> -        if self.baseaddress == self.address:
> +        if self._baseaddress == self._realaddress:
>              return
> -        tempaddress = _tempaddress(self.baseaddress)
> -        os.symlink(os.path.basename(self.address), tempaddress)
> -        util.rename(tempaddress, self.baseaddress)
> +        tempaddress = _tempaddress(self._baseaddress)
> +        os.symlink(os.path.basename(self._realaddress), tempaddress)
> +        util.rename(tempaddress, self._baseaddress)
>  
> -    def issocketowner(self):
> +    def _issocketowner(self):
>          try:
> -            stat = os.stat(self.address)
> +            stat = os.stat(self._realaddress)
>              return (stat.st_ino == self._socketstat.st_ino and
>                      stat.st_mtime == self._socketstat.st_mtime)
>          except OSError:
>              return False
>  
>      def unlinksocket(self, address):
> -        if not self.issocketowner():
> +        if not self._issocketowner():
>              return
>          # it is possible to have a race condition here that we may
>          # remove another server's socket file. but that's okay
>          # since that server will detect and exit automatically and
>          # the client will start a new server on demand.
>          try:
> -            os.unlink(self.address)
> +            os.unlink(self._realaddress)
>          except OSError as exc:
>              if exc.errno != errno.ENOENT:
>                  raise
> @@ -612,20 +612,20 @@ class chgunixservicehandler(object):
>          pass
>  
>      def shouldexit(self):
> -        if not self.issocketowner():
> -            self.ui.debug('%s is not owned, exiting.\n' % self.address)
> +        if not self._issocketowner():
> +            self.ui.debug('%s is not owned, exiting.\n' % self._realaddress)
>              return True
> -        if time.time() - self.lastactive > self.idletimeout:
> +        if time.time() - self._lastactive > self._idletimeout:
>              self.ui.debug('being idle too long. exiting.\n')
>              return True
>          return False
>  
>      def newconnection(self):
> -        self.lastactive = time.time()
> +        self._lastactive = time.time()
>  
>      def createcmdserver(self, repo, conn, fin, fout):
>          return chgcmdserver(self.ui, repo, fin, fout, conn,
> -                            self.hashstate, self.baseaddress)
> +                            self._hashstate, self._baseaddress)
>  
>  def chgunixservice(ui, repo, opts):
>      if repo:
Matt Mackall - July 19, 2016, 3:50 a.m.
On Mon, 2016-07-18 at 22:53 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1463822199 -32400
> #      Sat May 21 18:16:39 2016 +0900
> # Node ID 357dee3a00fd5a31e2aa4560a2045825d240ba4d
> # Parent  793c1bbd113d7cf862f17a91f6b6ccb8cbc9b15c
> chgserver: rename private functions and variables of chgunixservicehandler

These are queued for default, thanks.
-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -542,8 +542,8 @@  class chgunixservicehandler(object):
 
     def __init__(self, ui):
         self.ui = ui
-        self.idletimeout = ui.configint('chgserver', 'idletimeout', 3600)
-        self.lastactive = time.time()
+        self._idletimeout = ui.configint('chgserver', 'idletimeout', 3600)
+        self._lastactive = time.time()
 
     def bindsocket(self, sock, address):
         self._inithashstate(address)
@@ -552,57 +552,57 @@  class chgunixservicehandler(object):
         self._createsymlink()
 
     def _inithashstate(self, address):
-        self.baseaddress = address
+        self._baseaddress = address
         if self.ui.configbool('chgserver', 'skiphash', False):
-            self.hashstate = None
-            self.address = address
+            self._hashstate = None
+            self._realaddress = address
             return
-        self.hashstate = hashstate.fromui(self.ui)
-        self.address = _hashaddress(address, self.hashstate.confighash)
+        self._hashstate = hashstate.fromui(self.ui)
+        self._realaddress = _hashaddress(address, self._hashstate.confighash)
 
     def _checkextensions(self):
-        if not self.hashstate:
+        if not self._hashstate:
             return
         if extensions.notloaded():
             # one or more extensions failed to load. mtimehash becomes
             # meaningless because we do not know the paths of those extensions.
             # set mtimehash to an illegal hash value to invalidate the server.
-            self.hashstate.mtimehash = ''
+            self._hashstate.mtimehash = ''
 
     def _bind(self, sock):
         # use a unique temp address so we can stat the file and do ownership
         # check later
-        tempaddress = _tempaddress(self.address)
+        tempaddress = _tempaddress(self._realaddress)
         util.bindunixsocket(sock, tempaddress)
         self._socketstat = os.stat(tempaddress)
         # rename will replace the old socket file if exists atomically. the
         # old server will detect ownership change and exit.
-        util.rename(tempaddress, self.address)
+        util.rename(tempaddress, self._realaddress)
 
     def _createsymlink(self):
-        if self.baseaddress == self.address:
+        if self._baseaddress == self._realaddress:
             return
-        tempaddress = _tempaddress(self.baseaddress)
-        os.symlink(os.path.basename(self.address), tempaddress)
-        util.rename(tempaddress, self.baseaddress)
+        tempaddress = _tempaddress(self._baseaddress)
+        os.symlink(os.path.basename(self._realaddress), tempaddress)
+        util.rename(tempaddress, self._baseaddress)
 
-    def issocketowner(self):
+    def _issocketowner(self):
         try:
-            stat = os.stat(self.address)
+            stat = os.stat(self._realaddress)
             return (stat.st_ino == self._socketstat.st_ino and
                     stat.st_mtime == self._socketstat.st_mtime)
         except OSError:
             return False
 
     def unlinksocket(self, address):
-        if not self.issocketowner():
+        if not self._issocketowner():
             return
         # it is possible to have a race condition here that we may
         # remove another server's socket file. but that's okay
         # since that server will detect and exit automatically and
         # the client will start a new server on demand.
         try:
-            os.unlink(self.address)
+            os.unlink(self._realaddress)
         except OSError as exc:
             if exc.errno != errno.ENOENT:
                 raise
@@ -612,20 +612,20 @@  class chgunixservicehandler(object):
         pass
 
     def shouldexit(self):
-        if not self.issocketowner():
-            self.ui.debug('%s is not owned, exiting.\n' % self.address)
+        if not self._issocketowner():
+            self.ui.debug('%s is not owned, exiting.\n' % self._realaddress)
             return True
-        if time.time() - self.lastactive > self.idletimeout:
+        if time.time() - self._lastactive > self._idletimeout:
             self.ui.debug('being idle too long. exiting.\n')
             return True
         return False
 
     def newconnection(self):
-        self.lastactive = time.time()
+        self._lastactive = time.time()
 
     def createcmdserver(self, repo, conn, fin, fout):
         return chgcmdserver(self.ui, repo, fin, fout, conn,
-                            self.hashstate, self.baseaddress)
+                            self._hashstate, self._baseaddress)
 
 def chgunixservice(ui, repo, opts):
     if repo: