diff hgext/mq.py @ 2920:ef8ee4477019

merge with mpm.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Wed, 16 Aug 2006 10:46:24 -0700
parents b70740aefa4d 3848488244fc
children 773c5b82d052
line wrap: on
line diff
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -77,7 +77,7 @@ class queue:
 
     def diffopts(self):
         if self._diffopts is None:
-            self._diffopts = self.ui.diffopts()
+            self._diffopts = patch.diffopts(self.ui)
         return self._diffopts
 
     def join(self, *p):
@@ -400,15 +400,39 @@ class queue:
         '''Apply patchfile  to the working directory.
         patchfile: file name of patch'''
         try:
-            (files, fuzz) = patch.patch(patchfile, self.ui, strip=1,
-                                        cwd=repo.root)
-        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, [], False)
+            pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
+            f = os.popen("%s -d %s -p1 --no-backup-if-mismatch < %s" %
+                         (pp, util.shellquote(repo.root), util.shellquote(patchfile)))
+        except:
+            self.ui.warn("patch failed, unable to continue (try -v)\n")
+            return (None, [], False)
+        files = []
+        fuzz = False
+        for l in f:
+            l = l.rstrip('\r\n');
+            if self.ui.verbose:
+                self.ui.warn(l + "\n")
+            if l[:14] == 'patching file ':
+                pf = os.path.normpath(util.parse_patch_output(l))
+                if pf not in files:
+                    files.append(pf)
+                printed_file = False
+                file_str = l
+            elif l.find('with fuzz') >= 0:
+                if not printed_file:
+                    self.ui.warn(file_str + '\n')
+                    printed_file = True
+                self.ui.warn(l + '\n')
+                fuzz = True
+            elif l.find('saving rejects to file') >= 0:
+                self.ui.warn(l + '\n')
+            elif l.find('FAILED') >= 0:
+                if not printed_file:
+                    self.ui.warn(file_str + '\n')
+                    printed_file = True
+                self.ui.warn(l + '\n')
 
-        return (True, files.keys(), fuzz)
+        return (not f.close(), files, fuzz)
 
     def apply(self, repo, series, list=False, update_status=True,
               strict=False, patchdir=None, merge=None, wlock=None):
@@ -482,28 +506,21 @@ class queue:
         tr.close()
         return (err, n)
 
-    def delete(self, repo, patches, keep=False):
-        realpatches = []
-        for patch in patches:
-            patch = self.lookup(patch, strict=True)
-            info = self.isapplied(patch)
-            if info:
-                raise util.Abort(_("cannot delete applied patch %s") % patch)
-            if patch not in self.series:
-                raise util.Abort(_("patch %s not in series file") % patch)
-            realpatches.append(patch)
-
-        if not keep:
+    def delete(self, repo, patch, force=False):
+        patch = self.lookup(patch, strict=True)
+        info = self.isapplied(patch)
+        if info:
+            raise util.Abort(_("cannot delete applied patch %s") % patch)
+        if patch not in self.series:
+            raise util.Abort(_("patch %s not in series file") % patch)
+        if force:
             r = self.qrepo()
             if r:
-                r.remove(realpatches, True)
+                r.remove([patch], True)
             else:
                 os.unlink(self.join(patch))
-
-        indices = [self.find_series(p) for p in realpatches]
-        indices.sort()
-        for i in indices[-1::-1]:
-            del self.full_series[i]
+        i = self.find_series(patch)
+        del self.full_series[i]
         self.parse_series()
         self.series_dirty = 1
 
@@ -1283,13 +1300,13 @@ class queue:
         if qrepo:
             qrepo.add(added)
 
-def delete(ui, repo, patch, *patches, **opts):
-    """remove patches from queue
+def delete(ui, repo, patch, **opts):
+    """remove a patch from the series file
 
-    The patches must not be applied.
-    With -k, the patch files are preserved in the patch directory."""
+    The patch must not be applied.
+    With -f, deletes the patch file as well as the series entry."""
     q = repo.mq
-    q.delete(repo, (patch,) + patches, keep=opts.get('keep'))
+    q.delete(repo, patch, force=opts.get('force'))
     q.save_dirty()
     return 0
 
@@ -1447,7 +1464,7 @@ def fold(ui, repo, *files, **opts):
     applied to the current patch in the order given. If all the
     patches apply successfully, the current patch will be refreshed
     with the new cumulative patch, and the folded patches will
-    be deleted. With -k/--keep, the folded patch files will not
+    be deleted. With -f/--force, the folded patch files will
     be removed afterwards.
 
     The header for each folded patch will be concatenated with
@@ -1497,7 +1514,7 @@ def fold(ui, repo, *files, **opts):
     q.refresh(repo, msg=message)
 
     for patch in patches:
-        q.delete(repo, patch, keep=opts['keep'])
+        q.delete(repo, patch, force=opts['force'])
 
     q.save_dirty()
 
@@ -1886,14 +1903,14 @@ cmdtable = {
          commands.table["^commit|ci"][1],
          'hg qcommit [OPTION]... [FILE]...'),
     "^qdiff": (diff, [], 'hg qdiff [FILE]...'),
-    "qdelete|qremove|qrm":
+    "qdelete":
         (delete,
-         [('k', 'keep', None, _('keep patch file'))],
-          'hg qdelete [-k] PATCH'),
+         [('f', 'force', None, _('delete patch file'))],
+          'hg qdelete [-f] PATCH'),
     'qfold':
         (fold,
          [('e', 'edit', None, _('edit patch header')),
-          ('k', 'keep', None, _('keep folded patch files')),
+          ('f', 'force', None, _('delete folded patch files')),
           ('m', 'message', '', _('set patch header to <text>')),
           ('l', 'logfile', '', _('set patch header to contents of <file>'))],
          'hg qfold [-e] [-m <text>] [-l <file] PATCH...'),