[PATCH 4 of 4] patch: add lexists() to backends, use it in selectfile()

Patrick Mezard pmezard at gmail.com
Sun May 8 11:43:35 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1304872413 -7200
# Node ID 8e96d99c5f557d9377b4e5d1c3d3af9dd3a305da
# Parent  6a0365fbf2f78fcc2fb33e96bf0eab44cc9f317a
patch: add lexists() to backends, use it in selectfile()

At this point, all applydiff() filesystem calls should pass through fsbackend.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1173,7 +1173,7 @@
                 if wcfiles:
                     for patchname in s:
                         pf = os.path.join(self.path, patchname)
-                        patchfiles = patchmod.changedfiles(pf, strip=1)
+                        patchfiles = patchmod.changedfiles(self.ui, repo, pf)
                         if not wcfiles.isdisjoint(patchfiles):
                             self.localchangesfound(self.applied)
             elif mergeq:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -394,6 +394,9 @@
         """
         raise NotImplementedError
 
+    def exists(self, fname):
+        raise NotImplementedError
+
 class fsbackend(abstractbackend):
     def __init__(self, ui, basedir):
         super(fsbackend, self).__init__(ui)
@@ -461,6 +464,9 @@
                     % dst)
         util.copyfile(abssrc, absdst)
 
+    def exists(self, fname):
+        return os.path.lexists(fname)
+
 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@')
 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
@@ -970,16 +976,16 @@
         count -= 1
     return path[:i].lstrip(), path[i:].rstrip()
 
-def selectfile(afile_orig, bfile_orig, hunk, strip):
+def selectfile(backend, afile_orig, bfile_orig, hunk, strip):
     nulla = afile_orig == "/dev/null"
     nullb = bfile_orig == "/dev/null"
     abase, afile = pathstrip(afile_orig, strip)
-    gooda = not nulla and os.path.lexists(afile)
+    gooda = not nulla and backend.exists(afile)
     bbase, bfile = pathstrip(bfile_orig, strip)
     if afile == bfile:
         goodb = gooda
     else:
-        goodb = not nullb and os.path.lexists(bfile)
+        goodb = not nullb and backend.exists(bfile)
     createfunc = hunk.createfile
     missing = not goodb and not gooda and not createfunc()
 
@@ -1176,7 +1182,7 @@
                 rejects += current_file.close()
             afile, bfile, first_hunk = values
             try:
-                current_file, missing = selectfile(afile, bfile,
+                current_file, missing = selectfile(backend, afile, bfile,
                                                    first_hunk, strip)
                 current_file = patcher(ui, current_file, backend,
                                        missing=missing, eolmode=eolmode)
@@ -1347,7 +1353,8 @@
     except PatchError, err:
         raise util.Abort(str(err))
 
-def changedfiles(patchpath, strip=1):
+def changedfiles(ui, repo, patchpath, strip=1):
+    backend = fsbackend(ui, repo.root)
     fp = open(patchpath, 'rb')
     try:
         changed = set()
@@ -1356,7 +1363,7 @@
                 continue
             elif state == 'file':
                 afile, bfile, first_hunk = values
-                current_file, missing = selectfile(afile, bfile,
+                current_file, missing = selectfile(backend, afile, bfile,
                                                    first_hunk, strip)
                 changed.add(current_file)
             elif state == 'git':


More information about the Mercurial-devel mailing list