comparison hgext3rd/topic/discovery.py @ 3182:bc09dd507c41 stable

topic: fix new head detection when using --publish on a topic I suspected a bug lurking around there and I found one.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 14 Nov 2017 21:05:59 +0100
parents a32afe67e8a6
children 9d9ff55d1bb1
comparison
equal deleted inserted replaced
3179:cae57c9b5a94 3182:bc09dd507c41
1 from __future__ import absolute_import 1 from __future__ import absolute_import
2 2
3 import collections
3 import weakref 4 import weakref
4 5
5 from mercurial.i18n import _ 6 from mercurial.i18n import _
6 from mercurial import ( 7 from mercurial import (
7 bundle2, 8 bundle2,
29 msg = 'topic-ext _headssummary() takes 1 or 3 arguments (%d given)' 30 msg = 'topic-ext _headssummary() takes 1 or 3 arguments (%d given)'
30 raise TypeError(msg % len(args)) 31 raise TypeError(msg % len(args))
31 32
32 publishing = ('phases' not in remote.listkeys('namespaces') 33 publishing = ('phases' not in remote.listkeys('namespaces')
33 or bool(remote.listkeys('phases').get('publishing', False))) 34 or bool(remote.listkeys('phases').get('publishing', False)))
34 if publishing or not remote.capable('topics'): 35 if ((publishing or not remote.capable('topics'))
36 and (pushoparg and not pushop.publish)):
35 return orig(*args) 37 return orig(*args)
38
39 publishedset = ()
40 remotebranchmap = None
41 origremotebranchmap = remote.branchmap
42 if pushoparg: # < hg-4.4 do not have a --publish flag anyway
43 publishednode = [c.node() for c in pushop.outdatedphases]
44 publishedset = repo.revs('ancestors(%ln + %ln)',
45 publishednode,
46 pushop.remotephases.publicheads)
47
48 rev = repo.unfiltered().changelog.nodemap.get
49
50 def remotebranchmap():
51 # drop topic information from changeset about to be published
52 result = collections.defaultdict(list)
53 for branch, heads in origremotebranchmap().iteritems():
54 if ':' not in branch:
55 result[branch].extend(heads)
56 else:
57 namedbranch = branch.split(':', 1)[0]
58 for h in heads:
59 r = rev(h)
60 if r is not None and r in publishedset:
61 result[namedbranch].append(h)
62 else:
63 result[branch].append(h)
64 for heads in result.itervalues():
65 heads.sort()
66 return result
36 67
37 class repocls(repo.__class__): 68 class repocls(repo.__class__):
38 # awful hack to see branch as "branch:topic" 69 # awful hack to see branch as "branch:topic"
39 def __getitem__(self, key): 70 def __getitem__(self, key):
40 ctx = super(repocls, self).__getitem__(key) 71 ctx = super(repocls, self).__getitem__(key)
41 oldbranch = ctx.branch 72 oldbranch = ctx.branch
73 rev = ctx.rev()
42 74
43 def branch(): 75 def branch():
44 branch = oldbranch() 76 branch = oldbranch()
77 if rev in publishedset:
78 return branch
45 topic = ctx.topic() 79 topic = ctx.topic()
46 if topic: 80 if topic:
47 branch = "%s:%s" % (branch, topic) 81 branch = "%s:%s" % (branch, topic)
48 return branch 82 return branch
49 83
54 rbc = super(repocls, self).revbranchcache() 88 rbc = super(repocls, self).revbranchcache()
55 changelog = self.changelog 89 changelog = self.changelog
56 90
57 def branchinfo(rev): 91 def branchinfo(rev):
58 branch, close = changelog.branchinfo(rev) 92 branch, close = changelog.branchinfo(rev)
93 if rev in publishedset:
94 return branch, close
59 topic = repo[rev].topic() 95 topic = repo[rev].topic()
60 if topic: 96 if topic:
61 branch = "%s:%s" % (branch, topic) 97 branch = "%s:%s" % (branch, topic)
62 return branch, close 98 return branch, close
63 99
65 return rbc 101 return rbc
66 102
67 oldrepocls = repo.__class__ 103 oldrepocls = repo.__class__
68 try: 104 try:
69 repo.__class__ = repocls 105 repo.__class__ = repocls
106 remote.branchmap = remotebranchmap
70 unxx = repo.filtered('unfiltered-topic') 107 unxx = repo.filtered('unfiltered-topic')
71 repo.unfiltered = lambda: unxx 108 repo.unfiltered = lambda: unxx
72 if pushoparg: 109 if pushoparg:
73 pushop.repo = repo 110 pushop.repo = repo
74 summary = orig(pushop) 111 summary = orig(pushop)
81 return summary 118 return summary
82 finally: 119 finally:
83 if 'unfiltered' in vars(repo): 120 if 'unfiltered' in vars(repo):
84 del repo.unfiltered 121 del repo.unfiltered
85 repo.__class__ = oldrepocls 122 repo.__class__ = oldrepocls
123 remote.branchmap = origremotebranchmap
86 124
87 def wireprotobranchmap(orig, repo, proto): 125 def wireprotobranchmap(orig, repo, proto):
88 oldrepo = repo.__class__ 126 oldrepo = repo.__class__
89 try: 127 try:
90 class repocls(repo.__class__): 128 class repocls(repo.__class__):