changeset 14260:00a881581400

patch: make patch()/internalpatch() always update the dirstate
author Patrick Mezard <pmezard@gmail.com>
date Sun, 08 May 2011 17:48:31 +0200
parents df9ccd39828c
children e3649bcca3f6 66257848c154
files hgext/mq.py hgext/record.py hgext/transplant.py mercurial/commands.py mercurial/patch.py
diffstat 5 files changed, 32 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Sun May 08 17:48:30 2011 +0200
+++ b/hgext/mq.py	Sun May 08 17:48:31 2011 +0200
@@ -614,17 +614,14 @@
         patchfile: name of patch file'''
         files = {}
         try:
-            try:
-                fuzz = patchmod.patch(patchfile, self.ui, strip=1,
-                                      cwd=repo.root, files=files, eolmode=None)
-            finally:
-                files = patchmod.updatedir(self.ui, repo, files)
-            return (True, files, fuzz)
+            fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1,
+                                  cwd=repo.root, files=files, eolmode=None)
+            return (True, list(files), fuzz)
         except Exception, inst:
             self.ui.note(str(inst) + '\n')
             if not self.ui.verbose:
                 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
-            return (False, files, False)
+            return (False, list(files), False)
 
     def apply(self, repo, series, list=False, update_status=True,
               strict=False, patchdir=None, merge=None, all_files=None):
--- a/hgext/record.py	Sun May 08 17:48:30 2011 +0200
+++ b/hgext/record.py	Sun May 08 17:48:31 2011 +0200
@@ -477,12 +477,8 @@
                 try:
                     ui.debug('applying patch\n')
                     ui.debug(fp.getvalue())
-                    pfiles = {}
-                    try:
-                        patch.internalpatch(fp, ui, 1, repo.root, files=pfiles,
-                                            eolmode=None)
-                    finally:
-                        patch.updatedir(ui, repo, pfiles)
+                    patch.internalpatch(ui, repo, fp, 1, repo.root,
+                                        eolmode=None)
                 except patch.PatchError, err:
                     raise util.Abort(str(err))
             del fp
--- a/hgext/transplant.py	Sun May 08 17:48:30 2011 +0200
+++ b/hgext/transplant.py	Sun May 08 17:48:31 2011 +0200
@@ -224,15 +224,12 @@
         if patchfile:
             try:
                 files = {}
-                try:
-                    patch.patch(patchfile, self.ui, cwd=repo.root,
-                                files=files, eolmode=None)
-                    if not files:
-                        self.ui.warn(_('%s: empty changeset')
-                                     % revlog.hex(node))
-                        return None
-                finally:
-                    files = patch.updatedir(self.ui, repo, files)
+                patch.patch(self.ui, repo, patchfile, cwd=repo.root,
+                            files=files, eolmode=None)
+                files = list(files)
+                if not files:
+                    self.ui.warn(_('%s: empty changeset') % revlog.hex(node))
+                    return None
             except Exception, inst:
                 seriespath = os.path.join(self.path, 'series')
                 if os.path.exists(seriespath):
--- a/mercurial/commands.py	Sun May 08 17:48:30 2011 +0200
+++ b/mercurial/commands.py	Sun May 08 17:48:31 2011 +0200
@@ -2623,12 +2623,9 @@
                 repo.dirstate.setbranch(branch or 'default')
 
             files = {}
-            try:
-                patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
-                            files=files, eolmode=None)
-            finally:
-                files = patch.updatedir(ui, repo, files,
-                                        similarity=sim / 100.0)
+            patch.patch(ui, repo, tmpname, strip=strip, cwd=repo.root,
+                        files=files, eolmode=None, similarity=sim / 100.0)
+            files = list(files)
             if opts.get('no_commit'):
                 if message:
                     msgs.append(message)
--- a/mercurial/patch.py	Sun May 08 17:48:30 2011 +0200
+++ b/mercurial/patch.py	Sun May 08 17:48:31 2011 +0200
@@ -428,7 +428,7 @@
 
     def writelines(self, fname, lines):
         # Ensure supplied data ends in fname, being a regular file or
-        # a symlink. cmdutil.updatedir will -too magically- take care
+        # a symlink. _updatedir will -too magically- take care
         # of setting it to the proper type afterwards.
         st_mode = None
         islink = os.path.islink(fname)
@@ -1101,7 +1101,7 @@
     read in binary mode. Otherwise, line endings are ignored when
     patching then normalized according to 'eolmode'.
 
-    Callers probably want to call 'cmdutil.updatedir' after this to
+    Callers probably want to call '_updatedir' after this to
     apply certain categories of changes not done by this function.
     """
     return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip,
@@ -1157,7 +1157,7 @@
         return -1
     return err
 
-def updatedir(ui, repo, patches, similarity=0):
+def _updatedir(ui, repo, patches, similarity=0):
     '''Update dirstate after patch application according to metadata'''
     if not patches:
         return []
@@ -1237,7 +1237,8 @@
                          util.explainexit(code)[0])
     return fuzz
 
-def internalpatch(patchobj, ui, strip, cwd, files=None, eolmode='strict'):
+def internalpatch(ui, repo, patchobj, strip, cwd, files=None, eolmode='strict',
+                  similarity=0):
     """use builtin patch to apply <patchobj> to the working directory.
     returns whether patch was applied with fuzz factor."""
 
@@ -1263,11 +1264,14 @@
             os.chdir(curdir)
         if fp != patchobj:
             fp.close()
+        touched = _updatedir(ui, repo, files, similarity)
+        files.update(dict.fromkeys(touched))
     if ret < 0:
         raise PatchError(_('patch failed to apply'))
     return ret > 0
 
-def patch(patchname, ui, strip=1, cwd=None, files=None, eolmode='strict'):
+def patch(ui, repo, patchname, strip=1, cwd=None, files=None, eolmode='strict',
+          similarity=0):
     """Apply <patchname> to the working directory.
 
     'eolmode' specifies how end of lines should be handled. It can be:
@@ -1284,8 +1288,14 @@
         files = {}
     try:
         if patcher:
-            return _externalpatch(patcher, patchname, ui, strip, cwd, files)
-        return internalpatch(patchname, ui, strip, cwd, files, eolmode)
+            try:
+                return _externalpatch(patcher, patchname, ui, strip, cwd,
+                                      files)
+            finally:
+                touched = _updatedir(ui, repo, files, similarity)
+                files.update(dict.fromkeys(touched))
+        return internalpatch(ui, repo, patchname, strip, cwd, files, eolmode,
+                             similarity)
     except PatchError, err:
         raise util.Abort(str(err))