[Commented On] D11715: dirstate: group return logic and clarify each function in flagfunc
baymax (Baymax, Your Personal Patch-care Companion)
phabricator at mercurial-scm.org
Thu Oct 21 17:51:23 UTC 2021
baymax added a comment.
baymax updated this revision to Diff 30977.
✅ refresh by Heptapod after a successful CI run (🐙 💚)
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11715?vs=30967&id=30977
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11715/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11715
AFFECTED FILES
mercurial/dirstate.py
CHANGE DETAILS
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -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):
To: Alphare, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211021/5b39367d/attachment-0002.html>
More information about the Mercurial-patches
mailing list