Mercurial > hg-stable
changeset 9364:c7c2dd7524dd
mq: add options to qapplied/qunapplied to act like qprev/qnext
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 19 Aug 2009 12:50:46 +0200 |
parents | 8635b33eaade |
children | b8dc3eba4f9d |
files | hgext/mq.py tests/test-mq tests/test-mq.out |
diffstat | 3 files changed, 118 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/mq.py Wed Aug 19 12:47:04 2009 +0200 +++ b/hgext/mq.py Wed Aug 19 12:50:46 2009 +0200 @@ -1682,17 +1682,35 @@ def applied(ui, repo, patch=None, **opts): """print the patches already applied""" + q = repo.mq + l = len(q.applied) + if patch: if patch not in q.series: raise util.Abort(_("patch %s is not in series file") % patch) end = q.series.index(patch) + 1 else: end = q.series_end(True) - return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) + + if opts.get('last') and not end: + ui.write(_("no patches applied\n")) + return 1 + elif opts.get('last') and end == 1: + ui.write(_("only one patch applied\n")) + return 1 + elif opts.get('last'): + start = end - 2 + end = 1 + else: + start = 0 + + return q.qseries(repo, length=end, start=start, status='A', + summary=opts.get('summary')) def unapplied(ui, repo, patch=None, **opts): """print the patches not yet applied""" + q = repo.mq if patch: if patch not in q.series: @@ -1700,7 +1718,14 @@ start = q.series.index(patch) + 1 else: start = q.series_end(True) - q.qseries(repo, start=start, status='U', summary=opts.get('summary')) + + if start == len(q.series) and opts.get('first'): + ui.write(_("all patches applied\n")) + return 1 + + length = opts.get('first') and 1 or None + return q.qseries(repo, start=start, length=length, status='U', + summary=opts.get('summary')) def qimport(ui, repo, *filename, **opts): """import a patch @@ -2522,7 +2547,10 @@ seriesopts = [('s', 'summary', None, _('print first line of patch header'))] cmdtable = { - "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), + "qapplied": + (applied, + [('1', 'last', None, _('show only the last patch'))] + seriesopts, + _('hg qapplied [-s] [PATCH]')), "qclone": (clone, [('', 'pull', None, _('use pull protocol to copy metadata')), @@ -2645,7 +2673,10 @@ ('n', 'nobackup', None, _('no backups'))], _('hg strip [-f] [-b] [-n] REV')), "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), - "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), + "qunapplied": + (unapplied, + [('1', 'first', None, _('show only the first patch'))] + seriesopts, + _('hg qunapplied [-s] [PATCH]')), "qfinish": (finish, [('a', 'applied', None, _('finish all applied changesets'))],
--- a/tests/test-mq Wed Aug 19 12:47:04 2009 +0200 +++ b/tests/test-mq Wed Aug 19 12:50:46 2009 +0200 @@ -155,18 +155,13 @@ echo % qtop hg qtop -echo % qprev -hg qprev - -echo % qnext -hg qnext +echo % prev +hg qapp -1 -echo % pop, qnext, qprev, qapplied +echo % next +hg qunapp -1 + hg qpop -hg qnext -hg qprev -hg qapplied - echo % commit should fail hg commit @@ -197,6 +192,42 @@ hg qpop test2.patch-2 hg qpush test1b.patch+1 +echo % pop, qapplied, qunapplied +hg qseries -v +echo % qapplied -1 test.patch +hg qapplied -1 test.patch +echo % qapplied -1 test1b.patch +hg qapplied -1 test1b.patch +echo % qapplied -1 test2.patch +hg qapplied -1 test2.patch +echo % qapplied -1 +hg qapplied -1 +echo % qapplied +hg qapplied +echo % qapplied test1b.patch +hg qapplied test1b.patch +echo % qunapplied -1 +hg qunapplied -1 +echo % qunapplied +hg qunapplied +echo % popping +hg qpop +echo % qunapplied -1 +hg qunapplied -1 +echo % qunapplied +hg qunapplied +echo % qunapplied test2.patch +hg qunapplied test2.patch +echo % qunapplied -1 test2.patch +hg qunapplied -1 test2.patch +echo % popping -a +hg qpop -a +echo % qapplied +hg qapplied +echo % qapplied -1 +hg qapplied -1 +hg qpush + echo % push should succeed hg qpop -a hg push ../../k
--- a/tests/test-mq.out Wed Aug 19 12:47:04 2009 +0200 +++ b/tests/test-mq.out Wed Aug 19 12:50:46 2009 +0200 @@ -146,16 +146,12 @@ test2.patch % qtop test2.patch -% qprev +% prev test.patch -% qnext +% next all patches applied -% pop, qnext, qprev, qapplied popping test2.patch now at: test.patch -test2.patch -only one patch applied -test.patch % commit should fail abort: cannot commit over an applied mq patch % push should fail @@ -182,11 +178,50 @@ applying test1b.patch applying test2.patch now at: test2.patch -% push should succeed +% pop, qapplied, qunapplied +0 A test.patch +1 A test1b.patch +2 A test2.patch +% qapplied -1 test.patch +only one patch applied +% qapplied -1 test1b.patch +test.patch +% qapplied -1 test2.patch +test1b.patch +% qapplied -1 +test1b.patch +% qapplied +test.patch +test1b.patch +test2.patch +% qapplied test1b.patch +test.patch +test1b.patch +% qunapplied -1 +all patches applied +% qunapplied +% popping popping test2.patch +now at: test1b.patch +% qunapplied -1 +test2.patch +% qunapplied +test2.patch +% qunapplied test2.patch +% qunapplied -1 test2.patch +all patches applied +% popping -a popping test1b.patch popping test.patch patch queue now empty +% qapplied +% qapplied -1 +no patches applied +applying test.patch +now at: test.patch +% push should succeed +popping test.patch +patch queue now empty pushing to ../../k searching for changes adding changesets