Mercurial > hg
comparison hgext/mq.py @ 6645:37eedb1a1848
mq: introduce the qfinish command
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Tue, 03 Jun 2008 09:34:14 +0200 |
parents | 8c01ce1f2530 |
children | 2c9565971abc |
comparison
equal
deleted
inserted
replaced
6644:8c01ce1f2530 | 6645:37eedb1a1848 |
---|---|
533 self.ui.warn("fuzz found when applying patch, stopping\n") | 533 self.ui.warn("fuzz found when applying patch, stopping\n") |
534 err = 1 | 534 err = 1 |
535 break | 535 break |
536 return (err, n) | 536 return (err, n) |
537 | 537 |
538 def _clean_series(self, patches): | |
539 indices = [self.find_series(p) for p in patches] | |
540 indices.sort() | |
541 for i in indices[-1::-1]: | |
542 del self.full_series[i] | |
543 self.parse_series() | |
544 self.series_dirty = 1 | |
545 | |
546 def finish(self, repo, revs): | |
547 revs.sort() | |
548 firstrev = repo.changelog.rev(revlog.bin(self.applied[0].rev)) | |
549 appliedbase = 0 | |
550 patches = [] | |
551 for rev in revs: | |
552 if rev < firstrev: | |
553 raise util.Abort(_('revision %d is not managed') % rev) | |
554 base = revlog.bin(self.applied[appliedbase].rev) | |
555 node = repo.changelog.node(rev) | |
556 if node != base: | |
557 raise util.Abort(_('cannot delete revision %d above ' | |
558 'applied patches') % rev) | |
559 patches.append(self.applied[appliedbase].name) | |
560 appliedbase += 1 | |
561 | |
562 r = self.qrepo() | |
563 if r: | |
564 r.remove(patches, True) | |
565 else: | |
566 for p in patches: | |
567 os.unlink(self.join(p)) | |
568 | |
569 del self.applied[:appliedbase] | |
570 self.applied_dirty = 1 | |
571 self._clean_series(patches) | |
572 | |
538 def delete(self, repo, patches, opts): | 573 def delete(self, repo, patches, opts): |
539 if not patches and not opts.get('rev'): | 574 if not patches and not opts.get('rev'): |
540 raise util.Abort(_('qdelete requires at least one revision or ' | 575 raise util.Abort(_('qdelete requires at least one revision or ' |
541 'patch name')) | 576 'patch name')) |
542 | 577 |
578 os.unlink(self.join(p)) | 613 os.unlink(self.join(p)) |
579 | 614 |
580 if appliedbase: | 615 if appliedbase: |
581 del self.applied[:appliedbase] | 616 del self.applied[:appliedbase] |
582 self.applied_dirty = 1 | 617 self.applied_dirty = 1 |
583 indices = [self.find_series(p) for p in realpatches] | 618 self._clean_series(realpatches) |
584 indices.sort() | |
585 for i in indices[-1::-1]: | |
586 del self.full_series[i] | |
587 self.parse_series() | |
588 self.series_dirty = 1 | |
589 | 619 |
590 def check_toppatch(self, repo): | 620 def check_toppatch(self, repo): |
591 if len(self.applied) > 0: | 621 if len(self.applied) > 0: |
592 top = revlog.bin(self.applied[-1].rev) | 622 top = revlog.bin(self.applied[-1].rev) |
593 pp = repo.dirstate.parents() | 623 pp = repo.dirstate.parents() |
1495 | 1525 |
1496 The patches must not be applied, unless they are arguments to | 1526 The patches must not be applied, unless they are arguments to |
1497 the --rev parameter. At least one patch or revision is required. | 1527 the --rev parameter. At least one patch or revision is required. |
1498 | 1528 |
1499 With --rev, mq will stop managing the named revisions (converting | 1529 With --rev, mq will stop managing the named revisions (converting |
1500 them to regular mercurial changesets). The patches must be applied | 1530 them to regular mercurial changesets). The qfinish command should be |
1501 and at the base of the stack. This option is useful when the patches | 1531 used as an alternative for qdel -r, as the latter option is deprecated. |
1502 have been applied upstream. | |
1503 | 1532 |
1504 With --keep, the patch files are preserved in the patch directory.""" | 1533 With --keep, the patch files are preserved in the patch directory.""" |
1505 q = repo.mq | 1534 q = repo.mq |
1506 q.delete(repo, patches, opts) | 1535 q.delete(repo, patches, opts) |
1507 q.save_dirty() | 1536 q.save_dirty() |
2182 if reapply: | 2211 if reapply: |
2183 ui.status(_('reapplying unguarded patches\n')) | 2212 ui.status(_('reapplying unguarded patches\n')) |
2184 q.push(repo, reapply) | 2213 q.push(repo, reapply) |
2185 finally: | 2214 finally: |
2186 q.save_dirty() | 2215 q.save_dirty() |
2216 | |
2217 def finish(ui, repo, *revrange, **opts): | |
2218 """move applied patches into repository history | |
2219 | |
2220 Finishes the specified revisions (corresponding to applied patches) by | |
2221 moving them out of mq control into regular repository history. | |
2222 | |
2223 Accepts a revision range or the --all option. If --all is specified, all | |
2224 applied mq revisions are removed from mq control. Otherwise, the given | |
2225 revisions must be at the base of the stack of applied patches. | |
2226 | |
2227 This can be especially useful if your changes have been applied to an | |
2228 upstream repository, or if you are about to push your changes to upstream. | |
2229 """ | |
2230 if not opts['applied'] and not revrange: | |
2231 raise util.Abort(_('no revisions specified')) | |
2232 elif opts['applied']: | |
2233 revrange = ('qbase:qtip',) + revrange | |
2234 | |
2235 q = repo.mq | |
2236 if not q.applied: | |
2237 ui.status(_('no patches applied\n')) | |
2238 return 0 | |
2239 | |
2240 revs = cmdutil.revrange(repo, revrange) | |
2241 q.finish(repo, revs) | |
2242 q.save_dirty() | |
2243 return 0 | |
2187 | 2244 |
2188 def reposetup(ui, repo): | 2245 def reposetup(ui, repo): |
2189 class mqrepo(repo.__class__): | 2246 class mqrepo(repo.__class__): |
2190 def abort_if_wdir_patched(self, errmsg, force=False): | 2247 def abort_if_wdir_patched(self, errmsg, force=False): |
2191 if self.mq.applied and not force: | 2248 if self.mq.applied and not force: |
2393 ('b', 'backup', None, _('bundle unrelated changesets')), | 2450 ('b', 'backup', None, _('bundle unrelated changesets')), |
2394 ('n', 'nobackup', None, _('no backups'))], | 2451 ('n', 'nobackup', None, _('no backups'))], |
2395 _('hg strip [-f] [-b] [-n] REV')), | 2452 _('hg strip [-f] [-b] [-n] REV')), |
2396 "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), | 2453 "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), |
2397 "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), | 2454 "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), |
2455 "qfinish": | |
2456 (finish, | |
2457 [('a', 'applied', None, _('finish all applied changesets'))], | |
2458 _('hg qfinish [-a] [REV...]')), | |
2398 } | 2459 } |