Mercurial > public > mercurial-scm > hg
diff hgext/fsmonitor/state.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 8a9e53b974ee |
line wrap: on
line diff
--- a/hgext/fsmonitor/state.py Sun Oct 06 09:45:02 2019 -0400 +++ b/hgext/fsmonitor/state.py Sun Oct 06 09:48:39 2019 -0400 @@ -19,7 +19,7 @@ ) _version = 4 -_versionformat = ">I" +_versionformat = b">I" class state(object): @@ -30,15 +30,15 @@ self._lastclock = None self._identity = util.filestat(None) - self.mode = self._ui.config('fsmonitor', 'mode') + self.mode = self._ui.config(b'fsmonitor', b'mode') self.walk_on_invalidate = self._ui.configbool( - 'fsmonitor', 'walk_on_invalidate' + b'fsmonitor', b'walk_on_invalidate' ) - self.timeout = float(self._ui.config('fsmonitor', 'timeout')) + self.timeout = float(self._ui.config(b'fsmonitor', b'timeout')) def get(self): try: - file = self._vfs('fsmonitor.state', 'rb') + file = self._vfs(b'fsmonitor.state', b'rb') except IOError as inst: self._identity = util.filestat(None) if inst.errno != errno.ENOENT: @@ -50,9 +50,9 @@ versionbytes = file.read(4) if len(versionbytes) < 4: self._ui.log( - 'fsmonitor', - 'fsmonitor: state file only has %d bytes, ' - 'nuking state\n' % len(versionbytes), + b'fsmonitor', + b'fsmonitor: state file only has %d bytes, ' + b'nuking state\n' % len(versionbytes), ) self.invalidate() return None, None, None @@ -61,21 +61,21 @@ if diskversion != _version: # different version, nuke state and start over self._ui.log( - 'fsmonitor', - 'fsmonitor: version switch from %d to ' - '%d, nuking state\n' % (diskversion, _version), + b'fsmonitor', + b'fsmonitor: version switch from %d to ' + b'%d, nuking state\n' % (diskversion, _version), ) self.invalidate() return None, None, None - state = file.read().split('\0') + state = file.read().split(b'\0') # state = hostname\0clock\0ignorehash\0 + list of files, each # followed by a \0 if len(state) < 3: self._ui.log( - 'fsmonitor', - 'fsmonitor: state file truncated (expected ' - '3 chunks, found %d), nuking state\n', + b'fsmonitor', + b'fsmonitor: state file truncated (expected ' + b'3 chunks, found %d), nuking state\n', len(state), ) self.invalidate() @@ -85,9 +85,9 @@ if diskhostname != hostname: # file got moved to a different host self._ui.log( - 'fsmonitor', - 'fsmonitor: stored hostname "%s" ' - 'different from current "%s", nuking state\n' + b'fsmonitor', + b'fsmonitor: stored hostname "%s" ' + b'different from current "%s", nuking state\n' % (diskhostname, hostname), ) self.invalidate() @@ -110,31 +110,33 @@ # Read the identity from the file on disk rather than from the open file # pointer below, because the latter is actually a brand new file. - identity = util.filestat.frompath(self._vfs.join('fsmonitor.state')) + identity = util.filestat.frompath(self._vfs.join(b'fsmonitor.state')) if identity != self._identity: - self._ui.debug('skip updating fsmonitor.state: identity mismatch\n') + self._ui.debug( + b'skip updating fsmonitor.state: identity mismatch\n' + ) return try: file = self._vfs( - 'fsmonitor.state', 'wb', atomictemp=True, checkambig=True + b'fsmonitor.state', b'wb', atomictemp=True, checkambig=True ) except (IOError, OSError): - self._ui.warn(_("warning: unable to write out fsmonitor state\n")) + self._ui.warn(_(b"warning: unable to write out fsmonitor state\n")) return with file: file.write(struct.pack(_versionformat, _version)) - file.write(socket.gethostname() + '\0') - file.write(clock + '\0') - file.write(ignorehash + '\0') + file.write(socket.gethostname() + b'\0') + file.write(clock + b'\0') + file.write(ignorehash + b'\0') if notefiles: - file.write('\0'.join(notefiles)) - file.write('\0') + file.write(b'\0'.join(notefiles)) + file.write(b'\0') def invalidate(self): try: - os.unlink(os.path.join(self._rootdir, '.hg', 'fsmonitor.state')) + os.unlink(os.path.join(self._rootdir, b'.hg', b'fsmonitor.state')) except OSError as inst: if inst.errno != errno.ENOENT: raise