Mercurial > evolve
changeset 2898:3dfc88c06378
topic: support --rev argument and properly process then as user input
Revisions inputed by the users should be processed using `scmutil.revrange`.
This will take alias into account and allow extensions to monitor the user
inputs.
As a side effect, the '_changetopics' function takes revisions as argument.
make the API clearer.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 01 Sep 2017 17:53:14 +0200 |
parents | bd04a614b866 |
children | 32306ee32806 |
files | hgext3rd/topic/__init__.py tests/test-topic.t |
diffstat | 2 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py Fri Sep 01 17:37:47 2017 +0200 +++ b/hgext3rd/topic/__init__.py Fri Sep 01 17:53:14 2017 +0200 @@ -310,7 +310,7 @@ @command('topics', [ ('', 'clear', False, 'clear active topic if any'), - ('r', 'rev', '', 'revset of existing revisions', _('REV')), + ('r', 'rev', [], 'revset of existing revisions', _('REV')), ('l', 'list', False, 'show the stack of changeset in the topic'), ('', 'age', False, 'show when you last touched the topics'), ('', 'current', None, 'display the current topic only'), @@ -354,6 +354,10 @@ if clear and topic: raise error.Abort(_("cannot use --clear when setting a topic")) + touchedrevs = set() + if rev: + touchedrevs = scmutil.revrange(repo, rev) + if topic: topic = topic.strip() if not topic: @@ -370,7 +374,7 @@ raise error.Abort(_('no active topic to list')) return stack.showstack(ui, repo, topic=topic, opts=opts) - if rev: + if touchedrevs: if not obsolete.isenabled(repo, obsolete.createmarkersopt): raise error.Abort(_('must have obsolete enabled to change topics')) if clear: @@ -379,14 +383,14 @@ topic = repo.currenttopic elif not topic: raise error.Abort('changing topic requires a topic name or --clear') - if any(not c.mutable() for c in repo.set('%r and public()', rev)): + if repo.revs('%ld and public()', touchedrevs): raise error.Abort("can't change topic of a public change") wl = l = txn = None try: wl = repo.wlock() l = repo.lock() txn = repo.transaction('rewrite-topics') - rewrote = _changetopics(ui, repo, rev, topic) + rewrote = _changetopics(ui, repo, touchedrevs, topic) txn.close() ui.status('changed topic on %d changes\n' % rewrote) finally: @@ -446,7 +450,7 @@ if repo.vfs.exists('topic'): repo.vfs.unlink('topic') -def _changetopics(ui, repo, revset, newtopic): +def _changetopics(ui, repo, revs, newtopic): """ Changes topic to newtopic of all the revisions in the revset and return the count of revisions whose topic has been changed. """ @@ -454,7 +458,9 @@ p1 = None p2 = None successors = {} - for c in repo.set('%r', revset): + for r in revs: + c = repo[r] + def filectxfn(repo, ctx, path): try: return c[path]
--- a/tests/test-topic.t Fri Sep 01 17:37:47 2017 +0200 +++ b/tests/test-topic.t Fri Sep 01 17:53:14 2017 +0200 @@ -45,13 +45,13 @@ The --verbose version of this command display various information on the state of each topic. - options: + options ([+] can be repeated): - --clear clear active topic if any - -r --rev REV revset of existing revisions - -l --list show the stack of changeset in the topic - --age show when you last touched the topics - --current display the current topic only + --clear clear active topic if any + -r --rev REV [+] revset of existing revisions + -l --list show the stack of changeset in the topic + --age show when you last touched the topics + --current display the current topic only (some details hidden, use --verbose to show complete help) $ hg topics