[PATCH 4 of 4] patch: make patch()/internalpatch() always update the dirstate

Patrick Mezard pmezard at gmail.com
Sat May 7 12:16:49 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1304787688 -7200
# Node ID dccd8e834bb67d2474e7e9c1faa8fe826c956e80
# Parent  398726bef83770ec2548aeb49b60f75154390aab
patch: make patch()/internalpatch() always update the dirstate

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -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):
diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -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
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -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):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2613,12 +2613,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)
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -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))
 


More information about the Mercurial-devel mailing list