comparison mercurial/context.py @ 52668:5cc8deb96b48

pyupgrade: modernize calls to superclass methods This is the `legacy` fixer in `pyupgrade`, with the loop yielding the offset of `yield` statements commented out.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 22:23:31 -0500
parents 24ee91ba9aa8
children e627cc25b6f3
comparison
equal deleted inserted replaced
52667:73ab542565e0 52668:5cc8deb96b48
503 """A changecontext object makes access to data related to a particular 503 """A changecontext object makes access to data related to a particular
504 changeset convenient. It represents a read-only context already present in 504 changeset convenient. It represents a read-only context already present in
505 the repo.""" 505 the repo."""
506 506
507 def __init__(self, repo, rev, node, maybe_filtered=True): 507 def __init__(self, repo, rev, node, maybe_filtered=True):
508 super(changectx, self).__init__(repo) 508 super().__init__(repo)
509 self._rev = rev 509 self._rev = rev
510 self._node = node 510 self._node = node
511 # When maybe_filtered is True, the revision might be affected by 511 # When maybe_filtered is True, the revision might be affected by
512 # changelog filtering and operation through the filtered changelog must be used. 512 # changelog filtering and operation through the filtered changelog must be used.
513 # 513 #
658 elif source != b'compatibility': 658 elif source != b'compatibility':
659 # filelog mode, ignore any changelog content 659 # filelog mode, ignore any changelog content
660 p1copies = p2copies = None 660 p1copies = p2copies = None
661 if p1copies is None: 661 if p1copies is None:
662 if compute_on_none: 662 if compute_on_none:
663 p1copies, p2copies = super(changectx, self)._copies 663 p1copies, p2copies = super()._copies
664 else: 664 else:
665 if p1copies is None: 665 if p1copies is None:
666 p1copies = {} 666 p1copies = {}
667 if p2copies is None: 667 if p2copies is None:
668 p2copies = {} 668 p2copies = {}
1398 date=None, 1398 date=None,
1399 extra=None, 1399 extra=None,
1400 changes=None, 1400 changes=None,
1401 branch=None, 1401 branch=None,
1402 ): 1402 ):
1403 super(committablectx, self).__init__(repo) 1403 super().__init__(repo)
1404 self._rev = None 1404 self._rev = None
1405 self._node = None 1405 self._node = None
1406 self._text = text 1406 self._text = text
1407 if date: 1407 if date:
1408 self._date = dateutil.parsedate(date) 1408 self._date = dateutil.parsedate(date)
1572 if not extra or b'branch' not in extra: 1572 if not extra or b'branch' not in extra:
1573 try: 1573 try:
1574 branch = repo.dirstate.branch() 1574 branch = repo.dirstate.branch()
1575 except UnicodeDecodeError: 1575 except UnicodeDecodeError:
1576 raise error.Abort(_(b'branch name not in UTF-8!')) 1576 raise error.Abort(_(b'branch name not in UTF-8!'))
1577 super(workingctx, self).__init__( 1577 super().__init__(repo, text, user, date, extra, changes, branch=branch)
1578 repo, text, user, date, extra, changes, branch=branch
1579 )
1580 1578
1581 def __iter__(self): 1579 def __iter__(self):
1582 d = self._repo.dirstate 1580 d = self._repo.dirstate
1583 for f in d: 1581 for f in d:
1584 if d.get_entry(f).tracked: 1582 if d.get_entry(f).tracked:
1624 dirstate.copy(None, f) 1622 dirstate.copy(None, f)
1625 1623
1626 def _fileinfo(self, path): 1624 def _fileinfo(self, path):
1627 # populate __dict__['_manifest'] as workingctx has no _manifestdelta 1625 # populate __dict__['_manifest'] as workingctx has no _manifestdelta
1628 self._manifest 1626 self._manifest
1629 return super(workingctx, self)._fileinfo(path) 1627 return super()._fileinfo(path)
1630 1628
1631 def _buildflagfunc(self): 1629 def _buildflagfunc(self):
1632 # Create a fallback function for getting file flags when the 1630 # Create a fallback function for getting file flags when the
1633 # filesystem doesn't support them 1631 # filesystem doesn't support them
1634 1632
2016 # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, 2014 # Filter out symlinks that, in the case of FAT32 and NTFS filesystems,
2017 # might have accidentally ended up with the entire contents of the file 2015 # might have accidentally ended up with the entire contents of the file
2018 # they are supposed to be linking to. 2016 # they are supposed to be linking to.
2019 s.modified[:] = self._filtersuspectsymlink(s.modified) 2017 s.modified[:] = self._filtersuspectsymlink(s.modified)
2020 if other != self._repo[b'.']: 2018 if other != self._repo[b'.']:
2021 s = super(workingctx, self)._buildstatus( 2019 s = super()._buildstatus(
2022 other, s, match, listignored, listclean, listunknown 2020 other, s, match, listignored, listclean, listunknown
2023 ) 2021 )
2024 return s 2022 return s
2025 2023
2026 def _matchstatus(self, other, match): 2024 def _matchstatus(self, other, match):
2155 class workingfilectx(committablefilectx): 2153 class workingfilectx(committablefilectx):
2156 """A workingfilectx object makes access to data related to a particular 2154 """A workingfilectx object makes access to data related to a particular
2157 file in the working directory convenient.""" 2155 file in the working directory convenient."""
2158 2156
2159 def __init__(self, repo, path, filelog=None, workingctx=None): 2157 def __init__(self, repo, path, filelog=None, workingctx=None):
2160 super(workingfilectx, self).__init__(repo, path, filelog, workingctx) 2158 super().__init__(repo, path, filelog, workingctx)
2161 2159
2162 @propertycache 2160 @propertycache
2163 def _changectx(self): 2161 def _changectx(self):
2164 return workingctx(self._repo) 2162 return workingctx(self._repo)
2165 2163
2258 If `exists` is True, `flags` must be non-None and 'date' is non-None. If it 2256 If `exists` is True, `flags` must be non-None and 'date' is non-None. If it
2259 is `False`, the file was deleted. 2257 is `False`, the file was deleted.
2260 """ 2258 """
2261 2259
2262 def __init__(self, repo): 2260 def __init__(self, repo):
2263 super(overlayworkingctx, self).__init__(repo) 2261 super().__init__(repo)
2264 self.clean() 2262 self.clean()
2265 2263
2266 def setbase(self, wrappedctx): 2264 def setbase(self, wrappedctx):
2267 self._wrappedctx = wrappedctx 2265 self._wrappedctx = wrappedctx
2268 self._parents = [wrappedctx] 2266 self._parents = [wrappedctx]
2666 class overlayworkingfilectx(committablefilectx): 2664 class overlayworkingfilectx(committablefilectx):
2667 """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory 2665 """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory
2668 cache, which can be flushed through later by calling ``flush()``.""" 2666 cache, which can be flushed through later by calling ``flush()``."""
2669 2667
2670 def __init__(self, repo, path, filelog=None, parent=None): 2668 def __init__(self, repo, path, filelog=None, parent=None):
2671 super(overlayworkingfilectx, self).__init__(repo, path, filelog, parent) 2669 super().__init__(repo, path, filelog, parent)
2672 self._repo = repo 2670 self._repo = repo
2673 self._parent = parent 2671 self._parent = parent
2674 self._path = path 2672 self._path = path
2675 2673
2676 def cmp(self, fctx): 2674 def cmp(self, fctx):
2728 """ 2726 """
2729 2727
2730 def __init__( 2728 def __init__(
2731 self, repo, changes, text=b"", user=None, date=None, extra=None 2729 self, repo, changes, text=b"", user=None, date=None, extra=None
2732 ): 2730 ):
2733 super(workingcommitctx, self).__init__( 2731 super().__init__(repo, text, user, date, extra, changes)
2734 repo, text, user, date, extra, changes
2735 )
2736 2732
2737 def _dirstatestatus( 2733 def _dirstatestatus(
2738 self, match, ignored=False, clean=False, unknown=False 2734 self, match, ignored=False, clean=False, unknown=False
2739 ) -> istatus.Status: 2735 ) -> istatus.Status:
2740 """Return matched files only in ``self._status`` 2736 """Return matched files only in ``self._status``
2873 date=None, 2869 date=None,
2874 extra=None, 2870 extra=None,
2875 branch=None, 2871 branch=None,
2876 editor=None, 2872 editor=None,
2877 ): 2873 ):
2878 super(memctx, self).__init__( 2874 super().__init__(repo, text, user, date, extra, branch=branch)
2879 repo, text, user, date, extra, branch=branch
2880 )
2881 self._rev = None 2875 self._rev = None
2882 self._node = None 2876 self._node = None
2883 parents = [(p or self._repo.nodeconstants.nullid) for p in parents] 2877 parents = [(p or self._repo.nodeconstants.nullid) for p in parents]
2884 p1, p2 = parents 2878 p1, p2 = parents
2885 self._parents = [self._repo[p] for p in (p1, p2)] 2879 self._parents = [self._repo[p] for p in (p1, p2)]
2982 data is the file content as a string. 2976 data is the file content as a string.
2983 islink is True if the file is a symbolic link. 2977 islink is True if the file is a symbolic link.
2984 isexec is True if the file is executable. 2978 isexec is True if the file is executable.
2985 copied is the source file path if current file was copied in the 2979 copied is the source file path if current file was copied in the
2986 revision being committed, or None.""" 2980 revision being committed, or None."""
2987 super(memfilectx, self).__init__(repo, path, None, changectx) 2981 super().__init__(repo, path, None, changectx)
2988 self._data = data 2982 self._data = data
2989 if islink: 2983 if islink:
2990 self._flags = b'l' 2984 self._flags = b'l'
2991 elif isexec: 2985 elif isexec:
2992 self._flags = b'x' 2986 self._flags = b'x'
3040 extra=None, 3034 extra=None,
3041 editor=None, 3035 editor=None,
3042 ): 3036 ):
3043 if text is None: 3037 if text is None:
3044 text = originalctx.description() 3038 text = originalctx.description()
3045 super(metadataonlyctx, self).__init__(repo, text, user, date, extra) 3039 super().__init__(repo, text, user, date, extra)
3046 self._rev = None 3040 self._rev = None
3047 self._node = None 3041 self._node = None
3048 self._originalctx = originalctx 3042 self._originalctx = originalctx
3049 self._manifestnode = originalctx.manifestnode() 3043 self._manifestnode = originalctx.manifestnode()
3050 if parents is None: 3044 if parents is None: