Mercurial > hg
changeset 48282:0d6a099bba58
dirstate: group return logic and clarify each function in flagfunc
As suggested by spectral during review of my fix of the missing return, this
makes it more obvious that all cases are covered and improves readability of
the functions with new names and a small docstring.
Differential Revision: https://phab.mercurial-scm.org/D11715
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 21 Oct 2021 09:22:06 +0200 |
parents | 8f54d9c79b12 |
children | ebac18733142 |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 55 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Wed Oct 20 18:40:03 2021 +0200 +++ b/mercurial/dirstate.py Thu Oct 21 09:22:06 2021 +0200 @@ -242,65 +242,68 @@ return self._rootdir + f def flagfunc(self, buildfallback): - if self._checklink and self._checkexec: - - def f(x): - try: - st = os.lstat(self._join(x)) - if util.statislink(st): - return b'l' - if util.statisexec(st): - return b'x' - except OSError: - pass - return b'' + if not (self._checklink and self._checkexec): + fallback = buildfallback() - return f - - fallback = buildfallback() - if self._checklink: - - def f(x): - if os.path.islink(self._join(x)): + def check_both(x): + """This platform supports symlinks and exec permissions""" + try: + st = os.lstat(self._join(x)) + if util.statislink(st): return b'l' - entry = self.get_entry(x) - if entry.has_fallback_exec: - if entry.fallback_exec: - return b'x' - elif b'x' in fallback(x): + if util.statisexec(st): return b'x' - return b'' + except OSError: + pass + return b'' + + def check_link(x): + """This platform only supports symlinks""" + if os.path.islink(self._join(x)): + return b'l' + entry = self.get_entry(x) + if entry.has_fallback_exec: + if entry.fallback_exec: + return b'x' + elif b'x' in fallback(x): + return b'x' + return b'' - return f - if self._checkexec: - - def f(x): - if b'l' in fallback(x): + def check_exec(x): + """This platform only supports exec permissions""" + if b'l' in fallback(x): + return b'l' + entry = self.get_entry(x) + if entry.has_fallback_symlink: + if entry.fallback_symlink: return b'l' - entry = self.get_entry(x) - if entry.has_fallback_symlink: - if entry.fallback_symlink: - return b'l' - if util.isexec(self._join(x)): - return b'x' - return b'' + if util.isexec(self._join(x)): + return b'x' + return b'' - return f - else: + def check_fallback(x): + """This platform supports neither symlinks nor exec permissions, so + check the fallback in the dirstate if it exists, otherwise figure it + out the more expensive way from the parents.""" + entry = self.get_entry(x) + if entry.has_fallback_symlink: + if entry.fallback_symlink: + return b'l' + if entry.has_fallback_exec: + if entry.fallback_exec: + return b'x' + elif entry.has_fallback_symlink: + return b'' + return fallback(x) - def f(x): - entry = self.get_entry(x) - if entry.has_fallback_symlink: - if entry.fallback_symlink: - return b'l' - if entry.has_fallback_exec: - if entry.fallback_exec: - return b'x' - elif entry.has_fallback_symlink: - return b'' - return fallback(x) - - return f + if self._checklink and self._checkexec: + return check_both + elif self._checklink: + return check_link + elif self._checkexec: + return check_exec + else: + return check_fallback @propertycache def _cwd(self):