Commits

rcohen  committed 1703a86

Remove the mq dependency

  • Participants
  • Parent commits 7383972

Comments (0)

Files changed (1)

 """
 
 from mercurial.i18n import _
-from mercurial import commands, cmdutil, hg, patch, util, error
+from mercurial import commands, cmdutil, hg, patch, repair, util, error
 from mercurial import extensions, fancyopts, simplemerge
 from mercurial.node import hex, bin
 import cStringIO, os, re, errno, tempfile, sys
                 raise util.Abort(_('local changes found'))
         return m, a, r, d
 
+    def removeundo(self, repo):
+        undo = repo.sjoin('undo')
+        if not os.path.exists(undo):
+            return
+        try:
+            os.unlink(undo)
+        except OSError, inst:
+            self.ui.warn(_('error removing undo: %s\n') % str(inst))
+
+    def strip(self, repo, rev):
+        wlock = lock = None
+        try:
+            wlock = repo.wlock()
+            lock = repo.lock()
+
+            self.removeundo(repo)
+            repair.strip(self.ui, repo, rev, 'none')
+            # strip may have unbundled a set of backed up revisions after
+            # the actual strip
+            self.removeundo(repo)
+        finally:
+            del lock, wlock
+
     def _applypatch(self, repo, patchfile, sim, force=False, **opts):
         """applies a patch the old fashioned way."""
         def epwrapper(orig, *epargs, **epopts):
             patch.patch(patchfile, self.ui, strip=1, files=files)
             patch.updatedir(self.ui, repo, files, similarity=sim/100.)
 
-        try:
-            mq = extensions.find('mq')
-        except KeyError:
-            raise util.Abort(_("'mq' extension not loaded"))
         opener = util.opener('.hg/attic')
         smo = extensions.wrapfunction(simplemerge, 'simplemerge', smwrapper)
         quiet = self.ui.quiet
             simplemerge.simplemerge = smo
             hg.clean(repo, head)
             strip_opts = {'backup': False, 'nobackup': True, 'force': False}
+            if phead and head != phead:
+                self.strip(repo, phead)
             if whead and head != whead:
-                mq.strip(self.ui, repo, whead, **strip_opts)
-            if phead and head != phead:
-                mq.strip(self.ui, repo, phead, **strip_opts)
+                self.strip(repo, whead)
             if not success:
                 applydiff('.saved')
             self.ui.quiet = quiet
         try:
             if p1 and repo[p1]:
                 merge = True
-            try:
-                mq = extensions.find('mq')
-            except KeyError:
-                merge = False
         except error.RepoError:
             pass
         if merge: