Patchwork [8,of,9] context: use "vfs.lstat()" to examine target path instead of "os.path.*"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 14, 2013, 4:16 p.m.
Message ID <62800e7add063b806039.1381767368@juju>
Download mbox | patch
Permalink /patch/2766/
State Accepted
Commit 12a8bdd97b4fe2a578082bbffee721ed9c1a8c2f
Headers show

Comments

Katsunori FUJIWARA - Oct. 14, 2013, 4:16 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1381765865 -32400
#      Tue Oct 15 00:51:05 2013 +0900
# Node ID 62800e7add063b8060396c4188ab87ef2bbe316d
# Parent  8dc8f40fa668af56f75491aef75e3aec48bca477
context: use "vfs.lstat()" to examine target path instead of "os.path.*"

This patch gets stat object of target path by "vfs.lstat()", and
examines stat object to know the type of it. This follows the way in
"workingctx.add()".

This should be cheaper than original implementation invoking
"lexists()", "isfile()" and "islink()".

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1173,10 +1173,14 @@ 
             wlock.release()
 
     def copy(self, source, dest):
-        p = self._repo.wjoin(dest)
-        if not os.path.lexists(p):
+        try:
+            st = self._repo.wvfs.lstat(dest)
+        except OSError, err:
+            if err.errno != errno.ENOENT:
+                raise
             self._repo.ui.warn(_("%s does not exist!\n") % dest)
-        elif not (os.path.isfile(p) or os.path.islink(p)):
+            return
+        if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
             self._repo.ui.warn(_("copy failed: %s is not a file or a "
                                  "symbolic link\n") % dest)
         else: