hgext/mq.py
changeset 3371 9851f46d6ecc
parent 3243 1d3aceae87c1
child 3373 58202386deb7
equal deleted inserted replaced
3370:b7fe334ff4fb 3371:9851f46d6ecc
   486         tr.close()
   486         tr.close()
   487         return (err, n)
   487         return (err, n)
   488 
   488 
   489     def delete(self, repo, patches, opts):
   489     def delete(self, repo, patches, opts):
   490         realpatches = []
   490         realpatches = []
   491         appliedbase = 0
       
   492         forget = opts.get('forget')
       
   493         for patch in patches:
   491         for patch in patches:
   494             patch = self.lookup(patch, strict=True)
   492             patch = self.lookup(patch, strict=True)
   495             info = self.isapplied(patch)
   493             info = self.isapplied(patch)
   496             if info and not forget:
   494             if info:
   497                 raise util.Abort(_("cannot delete applied patch %s") % patch)
   495                 raise util.Abort(_("cannot delete applied patch %s") % patch)
   498             if patch not in self.series:
   496             if patch not in self.series:
   499                 raise util.Abort(_("patch %s not in series file") % patch)
   497                 raise util.Abort(_("patch %s not in series file") % patch)
   500             if forget:
   498             realpatches.append(patch)
   501                 if not info:
   499 
   502                     raise util.Abort(_("cannot forget unapplied patch %s") % patch)
   500         appliedbase = 0
   503                 if info[0] != appliedbase:
   501         if opts.get('rev'):
   504                     raise util.Abort(_("patch %s not at base") % patch)
   502             if not self.applied:
       
   503                 raise util.Abort(_('no patches applied'))
       
   504             revs = [int(r) for r in cmdutil.revrange(ui, repo, opts['rev'])]
       
   505             if len(revs) > 1 and revs[0] > revs[1]:
       
   506                 revs.reverse()
       
   507             for rev in revs:
       
   508                 if appliedbase >= len(self.applied):
       
   509                     raise util.Abort(_("revision %d is not managed") % rev)
       
   510 
       
   511                 base = revlog.bin(self.applied[appliedbase].rev)
       
   512                 node = repo.changelog.node(rev)
       
   513                 if node != base:
       
   514                     raise util.Abort(_("cannot delete revision %d above "
       
   515                                        "applied patches") % rev)
       
   516                 realpatches.append(self.applied[appliedbase].name)
   505                 appliedbase += 1
   517                 appliedbase += 1
   506             realpatches.append(patch)
       
   507 
   518 
   508         if not opts.get('keep'):
   519         if not opts.get('keep'):
   509             r = self.qrepo()
   520             r = self.qrepo()
   510             if r:
   521             if r:
   511                 r.remove(realpatches, True)
   522                 r.remove(realpatches, True)
   512             else:
   523             else:
   513                 os.unlink(self.join(patch))
   524                 os.unlink(self.join(patch))
   514 
   525 
   515         if forget:
   526         if appliedbase:
   516             del self.applied[:appliedbase]
   527             del self.applied[:appliedbase]
   517             self.applied_dirty = 1
   528             self.applied_dirty = 1
   518         indices = [self.find_series(p) for p in realpatches]
   529         indices = [self.find_series(p) for p in realpatches]
   519         indices.sort()
   530         indices.sort()
   520         for i in indices[-1::-1]:
   531         for i in indices[-1::-1]:
  1349         self.series_dirty = 1
  1360         self.series_dirty = 1
  1350         qrepo = self.qrepo()
  1361         qrepo = self.qrepo()
  1351         if qrepo:
  1362         if qrepo:
  1352             qrepo.add(added)
  1363             qrepo.add(added)
  1353 
  1364 
  1354 def delete(ui, repo, patch, *patches, **opts):
  1365 def delete(ui, repo, *patches, **opts):
  1355     """remove patches from queue
  1366     """remove patches from queue
  1356 
  1367 
  1357     With --forget, mq will stop managing the named patches. The
  1368     With --rev, mq will stop managing the named revisions. The
  1358     patches must be applied and at the base of the stack. This option
  1369     patches must be applied and at the base of the stack. This option
  1359     is useful when the patches have been applied upstream.
  1370     is useful when the patches have been applied upstream.
  1360 
  1371 
  1361     Otherwise, the patches must not be applied.
  1372     Otherwise, the patches must not be applied.
  1362 
  1373 
  1363     With --keep, the patch files are preserved in the patch directory."""
  1374     With --keep, the patch files are preserved in the patch directory."""
  1364     q = repo.mq
  1375     q = repo.mq
  1365     q.delete(repo, (patch,) + patches, opts)
  1376     q.delete(repo, patches, opts)
  1366     q.save_dirty()
  1377     q.save_dirty()
  1367     return 0
  1378     return 0
  1368 
  1379 
  1369 def applied(ui, repo, patch=None, **opts):
  1380 def applied(ui, repo, patch=None, **opts):
  1370     """print the patches already applied"""
  1381     """print the patches already applied"""
  2016                [('I', 'include', [], _('include names matching the given patterns')),
  2027                [('I', 'include', [], _('include names matching the given patterns')),
  2017                 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2028                 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2018                'hg qdiff [-I] [-X] [FILE]...'),
  2029                'hg qdiff [-I] [-X] [FILE]...'),
  2019     "qdelete|qremove|qrm":
  2030     "qdelete|qremove|qrm":
  2020         (delete,
  2031         (delete,
  2021          [('f', 'forget', None, _('stop managing an applied patch')),
  2032          [('k', 'keep', None, _('keep patch file')),
  2022           ('k', 'keep', None, _('keep patch file'))],
  2033           ('r', 'rev', [], _('stop managing a revision'))],
  2023           'hg qdelete [-f] [-k] PATCH'),
  2034           'hg qdelete [-k] [-r REV]... PATCH...'),
  2024     'qfold':
  2035     'qfold':
  2025         (fold,
  2036         (fold,
  2026          [('e', 'edit', None, _('edit patch header')),
  2037          [('e', 'edit', None, _('edit patch header')),
  2027           ('k', 'keep', None, _('keep folded patch files')),
  2038           ('k', 'keep', None, _('keep folded patch files')),
  2028           ('m', 'message', '', _('set patch header to <text>')),
  2039           ('m', 'message', '', _('set patch header to <text>')),