Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 52645:4cb75772818d
pyupgrade: drop the quoting around type annotations
This is the `typing_pep563` fixer in `pyupgrade`. Quoting to delay evaluation
hasn't been necessary since adding `from __future__ import annotations` in
1c5810ce737e.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 06 Jan 2025 00:30:55 -0500 |
parents | e627cc25b6f3 |
children | f066fc0bdc7a |
comparison
equal
deleted
inserted
replaced
52644:e627cc25b6f3 | 52645:4cb75772818d |
---|---|
144 # against itself. | 144 # against itself. |
145 for subpath in missing: | 145 for subpath in missing: |
146 yield subpath, ctx2.nullsub(subpath, ctx1) | 146 yield subpath, ctx2.nullsub(subpath, ctx1) |
147 | 147 |
148 | 148 |
149 def nochangesfound(ui: "uimod.ui", repo, excluded=None) -> None: | 149 def nochangesfound(ui: uimod.ui, repo, excluded=None) -> None: |
150 """Report no changes for push/pull, excluded is None or a list of | 150 """Report no changes for push/pull, excluded is None or a list of |
151 nodes excluded from the push/pull. | 151 nodes excluded from the push/pull. |
152 """ | 152 """ |
153 secretlist = [] | 153 secretlist = [] |
154 if excluded: | 154 if excluded: |
164 ) | 164 ) |
165 else: | 165 else: |
166 ui.status(_(b"no changes found\n")) | 166 ui.status(_(b"no changes found\n")) |
167 | 167 |
168 | 168 |
169 def callcatch(ui: "uimod.ui", func: Callable[[], int]) -> int: | 169 def callcatch(ui: uimod.ui, func: Callable[[], int]) -> int: |
170 """call func() with global exception handling | 170 """call func() with global exception handling |
171 | 171 |
172 return func() if no exception happens. otherwise do some error handling | 172 return func() if no exception happens. otherwise do some error handling |
173 and return an exit code accordingly. does not handle all exceptions. | 173 and return an exit code accordingly. does not handle all exceptions. |
174 """ | 174 """ |
321 _(b"'\\n' and '\\r' disallowed in filenames: %r") | 321 _(b"'\\n' and '\\r' disallowed in filenames: %r") |
322 % pycompat.bytestr(f) | 322 % pycompat.bytestr(f) |
323 ) | 323 ) |
324 | 324 |
325 | 325 |
326 def checkportable(ui: "uimod.ui", f: bytes) -> None: | 326 def checkportable(ui: uimod.ui, f: bytes) -> None: |
327 '''Check if filename f is portable and warn or abort depending on config''' | 327 '''Check if filename f is portable and warn or abort depending on config''' |
328 checkfilename(f) | 328 checkfilename(f) |
329 abort, warn = checkportabilityalert(ui) | 329 abort, warn = checkportabilityalert(ui) |
330 if abort or warn: | 330 if abort or warn: |
331 msg = util.checkwinfilename(f) | 331 msg = util.checkwinfilename(f) |
334 if abort: | 334 if abort: |
335 raise error.InputError(msg) | 335 raise error.InputError(msg) |
336 ui.warn(_(b"warning: %s\n") % msg) | 336 ui.warn(_(b"warning: %s\n") % msg) |
337 | 337 |
338 | 338 |
339 def checkportabilityalert(ui: "uimod.ui") -> Tuple[bool, bool]: | 339 def checkportabilityalert(ui: uimod.ui) -> Tuple[bool, bool]: |
340 """check if the user's config requests nothing, a warning, or abort for | 340 """check if the user's config requests nothing, a warning, or abort for |
341 non-portable filenames""" | 341 non-portable filenames""" |
342 val = ui.config(b'ui', b'portablefilenames') | 342 val = ui.config(b'ui', b'portablefilenames') |
343 lval = val.lower() | 343 lval = val.lower() |
344 bval = stringutil.parsebool(val) | 344 bval = stringutil.parsebool(val) |
350 ) | 350 ) |
351 return abort, warn | 351 return abort, warn |
352 | 352 |
353 | 353 |
354 class casecollisionauditor: | 354 class casecollisionauditor: |
355 def __init__(self, ui: "uimod.ui", abort: bool, dirstate) -> None: | 355 def __init__(self, ui: uimod.ui, abort: bool, dirstate) -> None: |
356 self._ui = ui | 356 self._ui = ui |
357 self._abort = abort | 357 self._abort = abort |
358 allfiles = b'\0'.join(dirstate) | 358 allfiles = b'\0'.join(dirstate) |
359 self._loweredfiles = set(encoding.lower(allfiles).split(b'\0')) | 359 self._loweredfiles = set(encoding.lower(allfiles).split(b'\0')) |
360 self._dirstate = dirstate | 360 self._dirstate = dirstate |
542 template provided by logcmdutil.changesettemplater""" | 542 template provided by logcmdutil.changesettemplater""" |
543 repo = ctx.repo() | 543 repo = ctx.repo() |
544 return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) | 544 return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) |
545 | 545 |
546 | 546 |
547 def formatrevnode(ui: "uimod.ui", rev: int, node: bytes) -> bytes: | 547 def formatrevnode(ui: uimod.ui, rev: int, node: bytes) -> bytes: |
548 """Format given revision and node depending on the current verbosity""" | 548 """Format given revision and node depending on the current verbosity""" |
549 if ui.debugflag: | 549 if ui.debugflag: |
550 hexfunc = hex | 550 hexfunc = hex |
551 else: | 551 else: |
552 hexfunc = short | 552 hexfunc = short |
1078 if len(files) != 1: | 1078 if len(files) != 1: |
1079 raise error.ParseError(msg) | 1079 raise error.ParseError(msg) |
1080 return files[0] | 1080 return files[0] |
1081 | 1081 |
1082 | 1082 |
1083 def getorigvfs(ui: "uimod.ui", repo): | 1083 def getorigvfs(ui: uimod.ui, repo): |
1084 """return a vfs suitable to save 'orig' file | 1084 """return a vfs suitable to save 'orig' file |
1085 | 1085 |
1086 return None if no special directory is configured""" | 1086 return None if no special directory is configured""" |
1087 origbackuppath = ui.config(b'ui', b'origbackuppath') | 1087 origbackuppath = ui.config(b'ui', b'origbackuppath') |
1088 if not origbackuppath: | 1088 if not origbackuppath: |
1089 return None | 1089 return None |
1090 return vfs.vfs(repo.wvfs.join(origbackuppath)) | 1090 return vfs.vfs(repo.wvfs.join(origbackuppath)) |
1091 | 1091 |
1092 | 1092 |
1093 def backuppath(ui: "uimod.ui", repo, filepath: bytes) -> bytes: | 1093 def backuppath(ui: uimod.ui, repo, filepath: bytes) -> bytes: |
1094 """customize where working copy backup files (.orig files) are created | 1094 """customize where working copy backup files (.orig files) are created |
1095 | 1095 |
1096 Fetch user defined path from config file: [ui] origbackuppath = <path> | 1096 Fetch user defined path from config file: [ui] origbackuppath = <path> |
1097 Fall back to default (filepath with .orig suffix) if not specified | 1097 Fall back to default (filepath with .orig suffix) if not specified |
1098 | 1098 |
1578 | 1578 |
1579 return copiesfn | 1579 return copiesfn |
1580 | 1580 |
1581 | 1581 |
1582 def dirstatecopy( | 1582 def dirstatecopy( |
1583 ui: "uimod.ui", | 1583 ui: uimod.ui, |
1584 repo, | 1584 repo, |
1585 wctx, | 1585 wctx, |
1586 src, | 1586 src, |
1587 dst, | 1587 dst, |
1588 dryrun: bool = False, | 1588 dryrun: bool = False, |
1954 | 1954 |
1955 return data | 1955 return data |
1956 | 1956 |
1957 | 1957 |
1958 class progress: | 1958 class progress: |
1959 ui: "uimod.ui" | 1959 ui: uimod.ui |
1960 pos: Optional[int] # None once complete | 1960 pos: Optional[int] # None once complete |
1961 topic: bytes | 1961 topic: bytes |
1962 unit: bytes | 1962 unit: bytes |
1963 total: Optional[int] | 1963 total: Optional[int] |
1964 debug: bool | 1964 debug: bool |
1965 | 1965 |
1966 def __init__( | 1966 def __init__( |
1967 self, | 1967 self, |
1968 ui: "uimod.ui", | 1968 ui: uimod.ui, |
1969 updatebar, | 1969 updatebar, |
1970 topic: bytes, | 1970 topic: bytes, |
1971 unit: bytes = b"", | 1971 unit: bytes = b"", |
1972 total: Optional[int] = None, | 1972 total: Optional[int] = None, |
1973 ) -> None: | 1973 ) -> None: |
2022 ) | 2022 ) |
2023 else: | 2023 else: |
2024 self.ui.debug(b'%s:%s %d%s\n' % (self.topic, item, self.pos, unit)) | 2024 self.ui.debug(b'%s:%s %d%s\n' % (self.topic, item, self.pos, unit)) |
2025 | 2025 |
2026 | 2026 |
2027 def gdinitconfig(ui: "uimod.ui"): | 2027 def gdinitconfig(ui: uimod.ui): |
2028 """helper function to know if a repo should be created as general delta""" | 2028 """helper function to know if a repo should be created as general delta""" |
2029 # experimental config: format.generaldelta | 2029 # experimental config: format.generaldelta |
2030 return ui.configbool(b'format', b'generaldelta') or ui.configbool( | 2030 return ui.configbool(b'format', b'generaldelta') or ui.configbool( |
2031 b'format', b'usegeneraldelta' | 2031 b'format', b'usegeneraldelta' |
2032 ) | 2032 ) |
2033 | 2033 |
2034 | 2034 |
2035 def gddeltaconfig(ui: "uimod.ui"): | 2035 def gddeltaconfig(ui: uimod.ui): |
2036 """helper function to know if incoming deltas should be optimized | 2036 """helper function to know if incoming deltas should be optimized |
2037 | 2037 |
2038 The `format.generaldelta` config is an old form of the config that also | 2038 The `format.generaldelta` config is an old form of the config that also |
2039 implies that incoming delta-bases should be never be trusted. This function | 2039 implies that incoming delta-bases should be never be trusted. This function |
2040 exists for this purpose. | 2040 exists for this purpose. |
2483 mark, | 2483 mark, |
2484 mark, | 2484 mark, |
2485 ) | 2485 ) |
2486 | 2486 |
2487 | 2487 |
2488 def ismember(ui: "uimod.ui", username: bytes, userlist: List[bytes]) -> bool: | 2488 def ismember(ui: uimod.ui, username: bytes, userlist: List[bytes]) -> bool: |
2489 """Check if username is a member of userlist. | 2489 """Check if username is a member of userlist. |
2490 | 2490 |
2491 If userlist has a single '*' member, all users are considered members. | 2491 If userlist has a single '*' member, all users are considered members. |
2492 Can be overridden by extensions to provide more complex authorization | 2492 Can be overridden by extensions to provide more complex authorization |
2493 schemes. | 2493 schemes. |
2509 | 2509 |
2510 DEFAULT_RESOURCE: int = RESOURCE_MEDIUM | 2510 DEFAULT_RESOURCE: int = RESOURCE_MEDIUM |
2511 | 2511 |
2512 | 2512 |
2513 def get_resource_profile( | 2513 def get_resource_profile( |
2514 ui: "uimod.ui", dimension: Optional[bytes] = None | 2514 ui: uimod.ui, dimension: Optional[bytes] = None |
2515 ) -> int: | 2515 ) -> int: |
2516 """return the resource profile for a dimension | 2516 """return the resource profile for a dimension |
2517 | 2517 |
2518 If no dimension is specified, the generic value is returned""" | 2518 If no dimension is specified, the generic value is returned""" |
2519 generic_name = ui.config(b'usage', b'resources') | 2519 generic_name = ui.config(b'usage', b'resources') |