Patchwork workingfilectx: add exists, lexists

login
register
mail settings
Submitter Phillip Cohen
Date July 5, 2017, 5:35 a.m.
Message ID <f62300ac0b720dae3e69.1499232958@phillco-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/22009/
State Accepted
Headers show

Comments

Phillip Cohen - July 5, 2017, 5:35 a.m.
# HG changeset patch
# User Phil Cohen <phillco@fb.com>
# Date 1499232952 25200
#      Tue Jul 04 22:35:52 2017 -0700
# Node ID f62300ac0b720dae3e6966550c8db8c52d0170d1
# Parent  5c9ad50fd62fbc2057ef7b44f921f22e7359af32
workingfilectx: add exists, lexists

Switch the lone call in merge.py to use it.

As with past refactors, the goal is to make wctx hot-swappable with an
in-memory context in the future. This change should be a no-op today.
Yuya Nishihara - July 6, 2017, 1:07 p.m.
On Tue, 4 Jul 2017 22:35:58 -0700, Phil Cohen wrote:
> # HG changeset patch
> # User Phil Cohen <phillco@fb.com>
> # Date 1499232952 25200
> #      Tue Jul 04 22:35:52 2017 -0700
> # Node ID f62300ac0b720dae3e6966550c8db8c52d0170d1
> # Parent  5c9ad50fd62fbc2057ef7b44f921f22e7359af32
> workingfilectx: add exists, lexists

Queued, thanks.

> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -1206,7 +1206,7 @@
>  
>      # remove renamed files after safely stored
>      for f in moves:
> -        if os.path.lexists(repo.wjoin(f)):
> +        if wctx[f].lexists():
>              repo.ui.debug("removing %s\n" % f)
>              wctx[f].audit()
>              wctx[f].remove()

Maybe you've noticed, these wctx[f] constructions can be merged into one.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1879,6 +1879,12 @@ 
                 raise
             return (t, tz)
 
+    def exists(self):
+        return self._repo.wvfs.exists(self._path)
+
+    def lexists(self):
+        return self._repo.wvfs.lexists(self._path)
+
     def audit(self):
         return self._repo.wvfs.audit(self._path)
 
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1206,7 +1206,7 @@ 
 
     # remove renamed files after safely stored
     for f in moves:
-        if os.path.lexists(repo.wjoin(f)):
+        if wctx[f].lexists():
             repo.ui.debug("removing %s\n" % f)
             wctx[f].audit()
             wctx[f].remove()