patch: break import cycle with cmdutil
authorMartin Geisler <mg@lazybytes.net>
Mon, 13 Sep 2010 13:08:09 +0200
changeset 12266 00658492e2aa
parent 12265 1ed2dc9d4368
child 12267 69e43c0515f2
patch: break import cycle with cmdutil The patch module imported cmdutil but used it only in updatedir.
hgext/mq.py
hgext/record.py
hgext/transplant.py
mercurial/cmdutil.py
mercurial/commands.py
mercurial/patch.py
--- a/hgext/mq.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/hgext/mq.py	Mon Sep 13 13:08:09 2010 +0200
@@ -685,7 +685,7 @@
                 p1, p2 = repo.dirstate.parents()
                 repo.dirstate.setparents(p1, merge)
 
-            files = patch.updatedir(self.ui, repo, files)
+            files = cmdutil.updatedir(self.ui, repo, files)
             match = cmdutil.matchfiles(repo, files or [])
             n = repo.commit(message, ph.user, ph.date, match=match, force=True)
 
@@ -2134,7 +2134,7 @@
         (patchsuccess, files, fuzz) = q.patch(repo, pf)
         if not patchsuccess:
             raise util.Abort(_('error folding patch %s') % p)
-        patch.updatedir(ui, repo, files)
+        cmdutil.updatedir(ui, repo, files)
 
     if not message:
         ph = patchheader(q.join(parent), q.plainmode)
--- a/hgext/record.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/hgext/record.py	Mon Sep 13 13:08:09 2010 +0200
@@ -497,7 +497,7 @@
                     pfiles = {}
                     patch.internalpatch(fp, ui, 1, repo.root, files=pfiles,
                                         eolmode=None)
-                    patch.updatedir(ui, repo, pfiles)
+                    cmdutil.updatedir(ui, repo, pfiles)
                 except patch.PatchError, err:
                     s = str(err)
                     if s:
--- a/hgext/transplant.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/hgext/transplant.py	Mon Sep 13 13:08:09 2010 +0200
@@ -225,7 +225,7 @@
                                      % revlog.hex(node))
                         return None
                 finally:
-                    files = patch.updatedir(self.ui, repo, files)
+                    files = cmdutil.updatedir(self.ui, repo, files)
             except Exception, inst:
                 seriespath = os.path.join(self.path, 'series')
                 if os.path.exists(seriespath):
--- a/mercurial/cmdutil.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/mercurial/cmdutil.py	Mon Sep 13 13:08:09 2010 +0200
@@ -329,6 +329,49 @@
         finally:
             wlock.release()
 
+def updatedir(ui, repo, patches, similarity=0):
+    '''Update dirstate after patch application according to metadata'''
+    if not patches:
+        return
+    copies = []
+    removes = set()
+    cfiles = patches.keys()
+    cwd = repo.getcwd()
+    if cwd:
+        cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()]
+    for f in patches:
+        gp = patches[f]
+        if not gp:
+            continue
+        if gp.op == 'RENAME':
+            copies.append((gp.oldpath, gp.path))
+            removes.add(gp.oldpath)
+        elif gp.op == 'COPY':
+            copies.append((gp.oldpath, gp.path))
+        elif gp.op == 'DELETE':
+            removes.add(gp.path)
+
+    wctx = repo[None]
+    for src, dst in copies:
+        wctx.copy(src, dst)
+    if (not similarity) and removes:
+        wctx.remove(sorted(removes), True)
+
+    for f in patches:
+        gp = patches[f]
+        if gp and gp.mode:
+            islink, isexec = gp.mode
+            dst = repo.wjoin(gp.path)
+            # patch won't create empty files
+            if gp.op == 'ADD' and not os.path.exists(dst):
+                flags = (isexec and 'x' or '') + (islink and 'l' or '')
+                repo.wwrite(gp.path, '', flags)
+            util.set_flags(dst, islink, isexec)
+    addremove(repo, cfiles, similarity=similarity)
+    files = patches.keys()
+    files.extend([r for r in removes if r not in files])
+    return sorted(files)
+
 def copy(ui, repo, pats, opts, rename=False):
     # called with the repo lock held
     #
--- a/mercurial/commands.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/mercurial/commands.py	Mon Sep 13 13:08:09 2010 +0200
@@ -2301,8 +2301,8 @@
                 patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
                             files=files, eolmode=None)
             finally:
-                files = patch.updatedir(ui, repo, files,
-                                        similarity=sim / 100.0)
+                files = cmdutil.updatedir(ui, repo, files,
+                                          similarity=sim / 100.0)
             if not opts.get('no_commit'):
                 if opts.get('exact'):
                     m = None
--- a/mercurial/patch.py	Sun Sep 12 16:10:41 2010 +0900
+++ b/mercurial/patch.py	Mon Sep 13 13:08:09 2010 +0200
@@ -11,7 +11,7 @@
 
 from i18n import _
 from node import hex, nullid, short
-import base85, cmdutil, mdiff, util, diffhelpers, copies, encoding
+import base85, mdiff, util, diffhelpers, copies, encoding
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 
@@ -444,8 +444,8 @@
 
     def writelines(self, fname, lines):
         # Ensure supplied data ends in fname, being a regular file or
-        # a symlink. updatedir() will -too magically- take care of
-        # setting it to the proper type afterwards.
+        # a symlink. cmdutil.updatedir will -too magically- take care
+        # of setting it to the proper type afterwards.
         islink = os.path.islink(fname)
         if islink:
             fp = cStringIO.StringIO()
@@ -1129,8 +1129,8 @@
     read in binary mode. Otherwise, line endings are ignored when
     patching then normalized according to 'eolmode'.
 
-    Callers probably want to call 'updatedir' after this to apply
-    certain categories of changes not done by this function.
+    Callers probably want to call 'cmdutil.updatedir' after this to
+    apply certain categories of changes not done by this function.
     """
     return _applydiff(
         ui, fp, patchfile, copyfile,
@@ -1196,49 +1196,6 @@
         return -1
     return err
 
-def updatedir(ui, repo, patches, similarity=0):
-    '''Update dirstate after patch application according to metadata'''
-    if not patches:
-        return
-    copies = []
-    removes = set()
-    cfiles = patches.keys()
-    cwd = repo.getcwd()
-    if cwd:
-        cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()]
-    for f in patches:
-        gp = patches[f]
-        if not gp:
-            continue
-        if gp.op == 'RENAME':
-            copies.append((gp.oldpath, gp.path))
-            removes.add(gp.oldpath)
-        elif gp.op == 'COPY':
-            copies.append((gp.oldpath, gp.path))
-        elif gp.op == 'DELETE':
-            removes.add(gp.path)
-
-    wctx = repo[None]
-    for src, dst in copies:
-        wctx.copy(src, dst)
-    if (not similarity) and removes:
-        wctx.remove(sorted(removes), True)
-
-    for f in patches:
-        gp = patches[f]
-        if gp and gp.mode:
-            islink, isexec = gp.mode
-            dst = repo.wjoin(gp.path)
-            # patch won't create empty files
-            if gp.op == 'ADD' and not os.path.exists(dst):
-                flags = (isexec and 'x' or '') + (islink and 'l' or '')
-                repo.wwrite(gp.path, '', flags)
-            util.set_flags(dst, islink, isexec)
-    cmdutil.addremove(repo, cfiles, similarity=similarity)
-    files = patches.keys()
-    files.extend([r for r in removes if r not in files])
-    return sorted(files)
-
 def externalpatch(patcher, args, patchname, ui, strip, cwd, files):
     """use <patcher> to apply <patchname> to the working directory.
     returns whether patch was applied with fuzz factor."""