comparison src/topic/__init__.py @ 1844:862cabc132fd

topic: add ability to change topic of non-public changes This is a little crude, but it gets the job done. You probably don't want to use this without evolution for now.
author Augie Fackler <augie@google.com>
date Wed, 10 Jun 2015 15:03:39 -0400
parents 0ba067a97d06
children 24d8053020a2
comparison
equal deleted inserted replaced
1843:0ba067a97d06 1844:862cabc132fd
10 """ 10 """
11 import functools 11 import functools
12 12
13 from mercurial import cmdutil 13 from mercurial import cmdutil
14 from mercurial import commands 14 from mercurial import commands
15 from mercurial import context
15 from mercurial import extensions 16 from mercurial import extensions
16 from mercurial import namespaces 17 from mercurial import namespaces
17 from mercurial import obsolete 18 from mercurial import obsolete
18 from mercurial import phases 19 from mercurial import phases
19 from mercurial import util 20 from mercurial import util
60 'topics', 'topic', namemap=_namemap, nodemap=_nodemap)) 61 'topics', 'topic', namemap=_namemap, nodemap=_nodemap))
61 repo.__class__ = topicrepo 62 repo.__class__ = topicrepo
62 63
63 @command('topics', [ 64 @command('topics', [
64 ('', 'clear', False, 'clear active topic if any'), 65 ('', 'clear', False, 'clear active topic if any'),
66 ('', 'change', '', 'revset of existing revisions to change topic'),
65 ]) 67 ])
66 def topics(ui, repo, topic=None, clear=False): 68 def topics(ui, repo, topic=None, clear=False, change=None):
67 """View current topic, set current topic, or see all topics.""" 69 """View current topic, set current topic, or see all topics."""
68 if not obsolete.isenabled(repo, obsolete.createmarkersopt): 70 if not obsolete.isenabled(repo, obsolete.createmarkersopt):
69 raise util.Abort('current reality means you should only ' 71 raise util.Abort('current reality means you should only '
70 'use topic with obsolete enabled') 72 'use topic with obsolete enabled')
73 if change:
74 if topic is None and not clear:
75 raise util.Abort('changing topic requires a topic name or --clear')
76 if any(not c.mutable() for c in repo.set('%r and public()', change)):
77 raise util.Abort("can't change topic of a public change")
78 rewrote = 0
79 needevolve = False
80 for c in repo.set('%r', change):
81 def filectxfn(repo, ctx, path):
82 try:
83 return c[path]
84 except error.ManifestLookupError:
85 return None
86 fixedextra = dict(c.extra())
87 newtopic = None if clear else topic
88 if fixedextra.get('topic', None) == topic:
89 continue
90 if clear and 'topic' in fixedextra:
91 del fixedextra['topic']
92 else:
93 fixedextra['topic'] = topic
94 c.parents()
95 mc = context.memctx(
96 repo, (c.p1().node(), c.p2().node()), c.description(),
97 c.files(), filectxfn,
98 user=c.user(), date=c.date(), extra=fixedextra)
99 newnode = repo.commitctx(mc)
100 needevolve = needevolve or (len(c.children()) > 0)
101 obsolete.createmarkers(repo, [(c, (repo[newnode],))])
102 rewrote += 1
103 ui.status('changed topic on %d changes\n' % rewrote)
104 if needevolve:
105 evolvetarget = 'topic(%s)' % topic if topic else 'not topic()'
106 ui.status('please run hg evolve --rev "%s" now\n' % evolvetarget)
71 if clear: 107 if clear:
72 if repo.vfs.exists('topic'): 108 if repo.vfs.exists('topic'):
73 repo.vfs.unlink('topic') 109 repo.vfs.unlink('topic')
74 return 110 return
75 if topic is not None: 111 if topic is not None: