diff --git a/hgext/absorb.py b/hgext/absorb.py --- a/hgext/absorb.py +++ b/hgext/absorb.py @@ -862,7 +862,7 @@ # be slow. in absorb's case, no need to invalidate fsmonitorstate. noop = lambda: 0 restore = noop - if util.safehasattr(dirstate, b'_fsmonitorstate'): + if util.safehasattr(dirstate, '_fsmonitorstate'): bak = dirstate._fsmonitorstate.invalidate def restore(): diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py --- a/hgext/bugzilla.py +++ b/hgext/bugzilla.py @@ -731,13 +731,13 @@ # inheritance with a new-style class. class cookietransport(cookietransportrequest, xmlrpclib.Transport): def __init__(self, use_datetime=0): - if util.safehasattr(xmlrpclib.Transport, b"__init__"): + if util.safehasattr(xmlrpclib.Transport, "__init__"): xmlrpclib.Transport.__init__(self, use_datetime) class cookiesafetransport(cookietransportrequest, xmlrpclib.SafeTransport): def __init__(self, use_datetime=0): - if util.safehasattr(xmlrpclib.Transport, b"__init__"): + if util.safehasattr(xmlrpclib.Transport, "__init__"): xmlrpclib.SafeTransport.__init__(self, use_datetime) diff --git a/hgext/commitextras.py b/hgext/commitextras.py --- a/hgext/commitextras.py +++ b/hgext/commitextras.py @@ -53,7 +53,7 @@ def _commit(orig, ui, repo, *pats, **opts): - if util.safehasattr(repo, b'unfiltered'): + if util.safehasattr(repo, 'unfiltered'): repo = repo.unfiltered() class repoextra(repo.__class__): diff --git a/hgext/fastannotate/commands.py b/hgext/fastannotate/commands.py --- a/hgext/fastannotate/commands.py +++ b/hgext/fastannotate/commands.py @@ -218,7 +218,7 @@ paths = list(_matchpaths(repo, rev, pats, opts, aopts)) # for client, prefetch from the server - if util.safehasattr(repo, b'prefetchfastannotate'): + if util.safehasattr(repo, 'prefetchfastannotate'): repo.prefetchfastannotate(paths) for path in paths: @@ -273,7 +273,7 @@ # check if we need to do prefetch (client-side) rev = opts.get(r'rev') - if util.safehasattr(repo, b'prefetchfastannotate') and rev is not None: + if util.safehasattr(repo, 'prefetchfastannotate') and rev is not None: paths = list(_matchpaths(repo, rev, pats, pycompat.byteskwargs(opts))) repo.prefetchfastannotate(paths) @@ -320,7 +320,7 @@ ctx = scmutil.revsingle(repo, rev) m = scmutil.match(ctx, pats, opts) paths = list(ctx.walk(m)) - if util.safehasattr(repo, b'prefetchfastannotate'): + if util.safehasattr(repo, 'prefetchfastannotate'): # client if opts.get(b'REV'): raise error.Abort(_(b'--rev cannot be used for client')) diff --git a/hgext/fsmonitor/watchmanclient.py b/hgext/fsmonitor/watchmanclient.py --- a/hgext/fsmonitor/watchmanclient.py +++ b/hgext/fsmonitor/watchmanclient.py @@ -61,7 +61,7 @@ def getcurrentclock(self): result = self.command(b'clock') - if not util.safehasattr(result, b'clock'): + if not util.safehasattr(result, 'clock'): raise Unavailable( b'clock result is missing clock value', invalidate=True ) diff --git a/hgext/journal.py b/hgext/journal.py --- a/hgext/journal.py +++ b/hgext/journal.py @@ -102,7 +102,7 @@ def wrapdirstate(orig, repo): """Make journal storage available to the dirstate object""" dirstate = orig(repo) - if util.safehasattr(repo, b'journal'): + if util.safehasattr(repo, 'journal'): _setupdirstate(repo, dirstate) return dirstate @@ -111,7 +111,7 @@ """Records all dirstate parent changes in the journal.""" old = list(old) new = list(new) - if util.safehasattr(dirstate, b'journalstorage'): + if util.safehasattr(dirstate, 'journalstorage'): # only record two hashes if there was a merge oldhashes = old[:1] if old[1] == node.nullid else old newhashes = new[:1] if new[1] == node.nullid else new @@ -124,7 +124,7 @@ def recordbookmarks(orig, store, fp): """Records all bookmark changes in the journal.""" repo = store._repo - if util.safehasattr(repo, b'journal'): + if util.safehasattr(repo, 'journal'): oldmarks = bookmarks.bmstore(repo) for mark, value in pycompat.iteritems(store): oldvalue = oldmarks.get(mark, node.nullid) @@ -186,7 +186,7 @@ if ( repo.path == repopath and repo.shared() - and util.safehasattr(repo, b'journal') + and util.safehasattr(repo, 'journal') ): sharedrepo = hg.sharedreposource(repo) sharedfeatures = _readsharedfeatures(repo) diff --git a/hgext/lfs/wireprotolfsserver.py b/hgext/lfs/wireprotolfsserver.py --- a/hgext/lfs/wireprotolfsserver.py +++ b/hgext/lfs/wireprotolfsserver.py @@ -45,7 +45,7 @@ if not rctx.repo.ui.configbool(b'experimental', b'lfs.serve'): return False - if not util.safehasattr(rctx.repo.svfs, b'lfslocalblobstore'): + if not util.safehasattr(rctx.repo.svfs, 'lfslocalblobstore'): return False if not req.dispatchpath: diff --git a/hgext/narrow/narrowbundle2.py b/hgext/narrow/narrowbundle2.py --- a/hgext/narrow/narrowbundle2.py +++ b/hgext/narrow/narrowbundle2.py @@ -266,7 +266,7 @@ # will currently always be there when using the core+narrowhg server, but # other servers may include a changespec part even when not widening (e.g. # because we're deepening a shallow repo). - if util.safehasattr(repo, b'setnewnarrowpats'): + if util.safehasattr(repo, 'setnewnarrowpats'): repo.setnewnarrowpats() @@ -348,9 +348,9 @@ def wrappedcghandler(op, inpart): origcghandler(op, inpart) - if util.safehasattr(op, b'_widen_bundle'): + if util.safehasattr(op, '_widen_bundle'): handlechangegroup_widen(op, inpart) - if util.safehasattr(op, b'_bookmarksbackup'): + if util.safehasattr(op, '_bookmarksbackup'): localrepo.localrepository._bookmarks.set( op.repo, op._bookmarksbackup ) diff --git a/hgext/remotefilelog/connectionpool.py b/hgext/remotefilelog/connectionpool.py --- a/hgext/remotefilelog/connectionpool.py +++ b/hgext/remotefilelog/connectionpool.py @@ -47,12 +47,12 @@ # close pipee first so peer.cleanup reading it won't deadlock, # if there are other processes with pipeo open (i.e. us). peer = orig.im_self - if util.safehasattr(peer, b'pipee'): + if util.safehasattr(peer, 'pipee'): peer.pipee.close() return orig() peer = hg.peer(self._repo.ui, {}, path) - if util.safehasattr(peer, b'cleanup'): + if util.safehasattr(peer, 'cleanup'): extensions.wrapfunction(peer, b'cleanup', _cleanup) conn = connection(pathpool, peer) @@ -84,5 +84,5 @@ self.close() def close(self): - if util.safehasattr(self.peer, b'cleanup'): + if util.safehasattr(self.peer, 'cleanup'): self.peer.cleanup() diff --git a/hgext/remotefilelog/fileserverclient.py b/hgext/remotefilelog/fileserverclient.py --- a/hgext/remotefilelog/fileserverclient.py +++ b/hgext/remotefilelog/fileserverclient.py @@ -89,7 +89,7 @@ not in self.capabilities() ): return - if not util.safehasattr(self, b'_localrepo'): + if not util.safehasattr(self, '_localrepo'): return if ( constants.SHALLOWREPO_REQUIREMENT @@ -129,7 +129,7 @@ def _callstream(self, command, **opts): supertype = super(remotefilepeer, self) - if not util.safehasattr(supertype, b'_sendrequest'): + if not util.safehasattr(supertype, '_sendrequest'): self._updatecallstreamopts(command, pycompat.byteskwargs(opts)) return super(remotefilepeer, self)._callstream(command, **opts) diff --git a/hgext/remotefilelog/repack.py b/hgext/remotefilelog/repack.py --- a/hgext/remotefilelog/repack.py +++ b/hgext/remotefilelog/repack.py @@ -54,7 +54,7 @@ def fullrepack(repo, options=None): """If ``packsonly`` is True, stores creating only loose objects are skipped. """ - if util.safehasattr(repo, b'shareddatastores'): + if util.safehasattr(repo, 'shareddatastores'): datasource = contentstore.unioncontentstore(*repo.shareddatastores) historysource = metadatastore.unionmetadatastore( *repo.sharedhistorystores, allowincomplete=True @@ -72,7 +72,7 @@ options=options, ) - if util.safehasattr(repo.manifestlog, b'datastore'): + if util.safehasattr(repo.manifestlog, 'datastore'): localdata, shareddata = _getmanifeststores(repo) lpackpath, ldstores, lhstores = localdata spackpath, sdstores, shstores = shareddata @@ -112,7 +112,7 @@ """This repacks the repo by looking at the distribution of pack files in the repo and performing the most minimal repack to keep the repo in good shape. """ - if util.safehasattr(repo, b'shareddatastores'): + if util.safehasattr(repo, 'shareddatastores'): packpath = shallowutil.getcachepackpath( repo, constants.FILEPACK_CATEGORY ) @@ -125,7 +125,7 @@ options=options, ) - if util.safehasattr(repo.manifestlog, b'datastore'): + if util.safehasattr(repo.manifestlog, 'datastore'): localdata, shareddata = _getmanifeststores(repo) lpackpath, ldstores, lhstores = localdata spackpath, sdstores, shstores = shareddata @@ -901,7 +901,7 @@ def repacklockvfs(repo): - if util.safehasattr(repo, b'name'): + if util.safehasattr(repo, 'name'): # Lock in the shared cache so repacks across multiple copies of the same # repo are coordinated. sharedcachepath = shallowutil.getcachepackpath( diff --git a/hgext/remotefilelog/shallowrepo.py b/hgext/remotefilelog/shallowrepo.py --- a/hgext/remotefilelog/shallowrepo.py +++ b/hgext/remotefilelog/shallowrepo.py @@ -345,7 +345,7 @@ repo.excludepattern = repo.ui.configlist( b"remotefilelog", b"excludepattern", None ) - if not util.safehasattr(repo, b'connectionpool'): + if not util.safehasattr(repo, 'connectionpool'): repo.connectionpool = connectionpool.connectionpool(repo) if repo.includepattern or repo.excludepattern: diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -936,7 +936,7 @@ def close(self): """close underlying file""" - if util.safehasattr(self._fp, b'close'): + if util.safehasattr(self._fp, 'close'): return self._fp.close() @@ -1024,7 +1024,7 @@ The new part have the very same content but no partid assigned yet. Parts with generated data cannot be copied.""" - assert not util.safehasattr(self.data, b'next') + assert not util.safehasattr(self.data, 'next') return self.__class__( self.type, self._mandatoryparams, @@ -1093,7 +1093,7 @@ msg.append(b')') if not self.data: msg.append(b' empty payload') - elif util.safehasattr(self.data, b'next') or util.safehasattr( + elif util.safehasattr(self.data, 'next') or util.safehasattr( self.data, b'__next__' ): msg.append(b' streamed payload') @@ -1189,7 +1189,7 @@ Exists to handle the different methods to provide data to a part.""" # we only support fixed size data now. # This will be improved in the future. - if util.safehasattr(self.data, b'next') or util.safehasattr( + if util.safehasattr(self.data, 'next') or util.safehasattr( self.data, b'__next__' ): buff = util.chunkbuffer(self.data) @@ -1336,7 +1336,7 @@ def __init__(self, ui, header, fp): super(unbundlepart, self).__init__(fp) - self._seekable = util.safehasattr(fp, b'seek') and util.safehasattr( + self._seekable = util.safehasattr(fp, 'seek') and util.safehasattr( fp, b'tell' ) self.ui = ui diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -212,7 +212,7 @@ class bundlephasecache(phases.phasecache): def __init__(self, *args, **kwargs): super(bundlephasecache, self).__init__(*args, **kwargs) - if util.safehasattr(self, b'opener'): + if util.safehasattr(self, 'opener'): self.opener = vfsmod.readonlyvfs(self.opener) def write(self): diff --git a/mercurial/pvec.py b/mercurial/pvec.py --- a/mercurial/pvec.py +++ b/mercurial/pvec.py @@ -159,7 +159,7 @@ def ctxpvec(ctx): '''construct a pvec for ctx while filling in the cache''' r = ctx.repo() - if not util.safehasattr(r, b"_pveccache"): + if not util.safehasattr(r, "_pveccache"): r._pveccache = {} pvc = r._pveccache if ctx.rev() not in pvc: diff --git a/mercurial/registrar.py b/mercurial/registrar.py --- a/mercurial/registrar.py +++ b/mercurial/registrar.py @@ -65,7 +65,7 @@ msg = b'duplicate registration for name: "%s"' % name raise error.ProgrammingError(msg) - if func.__doc__ and not util.safehasattr(func, b'_origdoc'): + if func.__doc__ and not util.safehasattr(func, '_origdoc'): func._origdoc = func.__doc__.strip() doc = pycompat.sysbytes(func._origdoc) func.__doc__ = pycompat.sysstr(self._formatdoc(decl, doc)) diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py --- a/mercurial/utils/procutil.py +++ b/mercurial/utils/procutil.py @@ -259,8 +259,8 @@ (portable, not much used). """ return ( - pycompat.safehasattr(sys, b"frozen") - or pycompat.safehasattr(sys, b"importers") # new py2exe + pycompat.safehasattr(sys, "frozen") + or pycompat.safehasattr(sys, "importers") # new py2exe or imp.is_frozen(r"__main__") # old py2exe ) # tools/freeze