Patchwork [2,of,2,V2] patch: replace functions in fsbackend to use vfs

login
register
mail settings
Submitter Chinmay Joshi
Date June 5, 2014, 10:46 a.m.
Message ID <8409375408a3d8626de5.1401965168@ubuntu>
Download mbox | patch
Permalink /patch/4935/
State Accepted
Headers show

Comments

Chinmay Joshi - June 5, 2014, 10:46 a.m.
# HG changeset patch
# User Chinmay Joshi <c@chinmayjoshi.com>
# Date 1401962069 -19800
#      Thu Jun 05 15:24:29 2014 +0530
# Node ID 8409375408a3d8626de54cce515babd03c7a78fb
# Parent  03dfb48d6b03dd6129f19be65b3e95534dfbb96f
patch: replace functions in fsbackend to use vfs

Several functions in fsbackend are replaced to use vfs functions.
vfs operations are applied on filename and path is joined by _join().
Katsunori FUJIWARA - June 5, 2014, 1:55 p.m.
At Thu, 05 Jun 2014 16:16:08 +0530,
Chinmay Joshi wrote:
> 
> # HG changeset patch
> # User Chinmay Joshi <c@chinmayjoshi.com>
> # Date 1401962069 -19800
> #      Thu Jun 05 15:24:29 2014 +0530
> # Node ID 8409375408a3d8626de54cce515babd03c7a78fb
> # Parent  03dfb48d6b03dd6129f19be65b3e95534dfbb96f
> patch: replace functions in fsbackend to use vfs
> 
> Several functions in fsbackend are replaced to use vfs functions.
> vfs operations are applied on filename and path is joined by _join().
> 
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -417,12 +417,12 @@
>          return os.path.join(self.opener.base, f)
>  
>      def getfile(self, fname):
> -        path = self._join(fname)
> -        if os.path.islink(path):
> -            return (os.readlink(path), (True, False))
> +        if self.opener.islink(fname):
> +            return (self.opener.readlink(fname), (True, False))
> +
>          isexec = False
>          try:
> -            isexec = os.lstat(path).st_mode & 0100 != 0
> +            isexec = self.opener.lstat(fname).st_mode & 0100 != 0
>          except OSError, e:
>              if e.errno != errno.ENOENT:
>                  raise

This patch looks good to me.

BTW, for performance efficiency, it may be desirable to avoid
'islink' by reusing result of 'lstat', in another patch: 'islink'
also causes 'lstat' system call invocation in underlying layer,
and it costs much in large scale repositories.

'stat.S_ISLNK' usage in 'add'/'copy' of 'workingctx' can be referred
for such improvement.



> @@ -431,17 +431,17 @@
>      def setfile(self, fname, data, mode, copysource):
>          islink, isexec = mode
>          if data is None:
> -            util.setflags(self._join(fname), islink, isexec)
> +            self.opener.setflags(fname, islink, isexec)
>              return
>          if islink:
>              self.opener.symlink(data, fname)
>          else:
>              self.opener.write(fname, data)
>              if isexec:
> -                util.setflags(self._join(fname), False, True)
> +                self.opener.setflags(fname, False, True)
>  
>      def unlink(self, fname):
> -        util.unlinkpath(self._join(fname), ignoremissing=True)
> +        self.opener.unlinkpath(fname, ignoremissing=True)
>  
>      def writerej(self, fname, failed, total, lines):
>          fname = fname + ".rej"
> @@ -453,7 +453,7 @@
>          fp.close()
>  
>      def exists(self, fname):
> -        return os.path.lexists(self._join(fname))
> +        return self.opener.lexists(fname)
>  
>  class workingbackend(fsbackend):
>      def __init__(self, ui, repo, similarity):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
> 

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp
Pierre-Yves David - June 5, 2014, 11:59 p.m.
On 06/05/2014 03:46 AM, Chinmay Joshi wrote:
> # HG changeset patch
> # User Chinmay Joshi <c@chinmayjoshi.com>
> # Date 1401962069 -19800
> #      Thu Jun 05 15:24:29 2014 +0530
> # Node ID 8409375408a3d8626de54cce515babd03c7a78fb
> # Parent  03dfb48d6b03dd6129f19be65b3e95534dfbb96f
> patch: replace functions in fsbackend to use vfs

Those two are pushed, Thanks!

Additional thanks goes to Foozy for his review.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -417,12 +417,12 @@ 
         return os.path.join(self.opener.base, f)
 
     def getfile(self, fname):
-        path = self._join(fname)
-        if os.path.islink(path):
-            return (os.readlink(path), (True, False))
+        if self.opener.islink(fname):
+            return (self.opener.readlink(fname), (True, False))
+
         isexec = False
         try:
-            isexec = os.lstat(path).st_mode & 0100 != 0
+            isexec = self.opener.lstat(fname).st_mode & 0100 != 0
         except OSError, e:
             if e.errno != errno.ENOENT:
                 raise
@@ -431,17 +431,17 @@ 
     def setfile(self, fname, data, mode, copysource):
         islink, isexec = mode
         if data is None:
-            util.setflags(self._join(fname), islink, isexec)
+            self.opener.setflags(fname, islink, isexec)
             return
         if islink:
             self.opener.symlink(data, fname)
         else:
             self.opener.write(fname, data)
             if isexec:
-                util.setflags(self._join(fname), False, True)
+                self.opener.setflags(fname, False, True)
 
     def unlink(self, fname):
-        util.unlinkpath(self._join(fname), ignoremissing=True)
+        self.opener.unlinkpath(fname, ignoremissing=True)
 
     def writerej(self, fname, failed, total, lines):
         fname = fname + ".rej"
@@ -453,7 +453,7 @@ 
         fp.close()
 
     def exists(self, fname):
-        return os.path.lexists(self._join(fname))
+        return self.opener.lexists(fname)
 
 class workingbackend(fsbackend):
     def __init__(self, ui, repo, similarity):