11 common, |
11 common, |
12 topicmap, |
12 topicmap, |
13 ) |
13 ) |
14 from .evolvebits import builddependencies |
14 from .evolvebits import builddependencies |
15 |
15 |
16 def _destmergebranch(orig, repo, action='merge', sourceset=None, |
16 def _destmergebranch(orig, repo, action=b'merge', sourceset=None, |
17 onheadcheck=True, destspace=None): |
17 onheadcheck=True, destspace=None): |
18 # XXX: take destspace into account |
18 # XXX: take destspace into account |
19 if sourceset is None: |
19 if sourceset is None: |
20 p1 = repo['.'] |
20 p1 = repo[b'.'] |
21 else: |
21 else: |
22 # XXX: using only the max here is flacky. That code should eventually |
22 # XXX: using only the max here is flacky. That code should eventually |
23 # be updated to take care of the whole sourceset. |
23 # be updated to take care of the whole sourceset. |
24 p1 = repo[max(sourceset)] |
24 p1 = repo[max(sourceset)] |
25 top = None |
25 top = None |
26 if common.hastopicext(repo): |
26 if common.hastopicext(repo): |
27 top = p1.topic() |
27 top = p1.topic() |
28 if top: |
28 if top: |
29 revs = repo.revs('topic(%s) - obsolete()', top) |
29 revs = repo.revs(b'topic(%s) - obsolete()', top) |
30 deps, rdeps = builddependencies(repo, revs) |
30 deps, rdeps = builddependencies(repo, revs) |
31 heads = [r for r in revs if not rdeps[r]] |
31 heads = [r for r in revs if not rdeps[r]] |
32 if onheadcheck and p1.rev() not in heads: |
32 if onheadcheck and p1.rev() not in heads: |
33 raise error.Abort(_("not at topic head, update or explicit")) |
33 raise error.Abort(_(b"not at topic head, update or explicit")) |
34 |
34 |
35 # prune heads above the source |
35 # prune heads above the source |
36 otherheads = set(heads) |
36 otherheads = set(heads) |
37 pool = set([p1.rev()]) |
37 pool = set([p1.rev()]) |
38 while pool: |
38 while pool: |
41 pool.update(rdeps[current]) |
41 pool.update(rdeps[current]) |
42 if not otherheads: |
42 if not otherheads: |
43 # nothing to do at the topic level |
43 # nothing to do at the topic level |
44 bhead = ngtip(repo, p1.branch(), all=True) |
44 bhead = ngtip(repo, p1.branch(), all=True) |
45 if not bhead: |
45 if not bhead: |
46 raise error.NoMergeDestAbort(_("nothing to merge")) |
46 raise error.NoMergeDestAbort(_(b"nothing to merge")) |
47 elif 1 == len(bhead): |
47 elif 1 == len(bhead): |
48 return bhead[0] |
48 return bhead[0] |
49 else: |
49 else: |
50 msg = _("branch '%s' has %d heads " |
50 msg = _(b"branch '%s' has %d heads " |
51 "- please merge with an explicit rev") |
51 b"- please merge with an explicit rev") |
52 hint = _("run 'hg heads .' to see heads") |
52 hint = _(b"run 'hg heads .' to see heads") |
53 raise error.ManyMergeDestAbort(msg % (p1.branch(), len(bhead)), |
53 raise error.ManyMergeDestAbort(msg % (p1.branch(), len(bhead)), |
54 hint=hint) |
54 hint=hint) |
55 elif len(otherheads) == 1: |
55 elif len(otherheads) == 1: |
56 return otherheads.pop() |
56 return otherheads.pop() |
57 else: |
57 else: |
58 msg = _("topic '%s' has %d heads " |
58 msg = _(b"topic '%s' has %d heads " |
59 "- please merge with an explicit rev") % (top, len(heads)) |
59 b"- please merge with an explicit rev") % (top, len(heads)) |
60 raise error.ManyMergeDestAbort(msg) |
60 raise error.ManyMergeDestAbort(msg) |
61 return orig(repo, action, sourceset, onheadcheck, destspace=destspace) |
61 return orig(repo, action, sourceset, onheadcheck, destspace=destspace) |
62 |
62 |
63 def _destupdatetopic(repo, clean, check=None): |
63 def _destupdatetopic(repo, clean, check=None): |
64 """decide on an update destination from current topic""" |
64 """decide on an update destination from current topic""" |
65 if not common.hastopicext(repo): |
65 if not common.hastopicext(repo): |
66 return None, None, None |
66 return None, None, None |
67 movemark = node = None |
67 movemark = node = None |
68 topic = repo.currenttopic |
68 topic = repo.currenttopic |
69 if topic: |
69 if topic: |
70 revs = repo.revs('.::topic(%s)', topic) |
70 revs = repo.revs(b'.::topic(%s)', topic) |
71 else: |
71 else: |
72 revs = [] |
72 revs = [] |
73 if not revs: |
73 if not revs: |
74 return None, None, None |
74 return None, None, None |
75 node = revs.last() |
75 node = revs.last() |
76 if bookmarks.isactivewdirparent(repo): |
76 if bookmarks.isactivewdirparent(repo): |
77 movemark = repo['.'].node() |
77 movemark = repo[b'.'].node() |
78 return node, movemark, None |
78 return node, movemark, None |
79 |
79 |
80 def desthistedit(orig, ui, repo): |
80 def desthistedit(orig, ui, repo): |
81 if not common.hastopicext(repo): |
81 if not common.hastopicext(repo): |
82 return None |
82 return None |
83 if not (ui.config('histedit', 'defaultrev', None) is None |
83 if not (ui.config(b'histedit', b'defaultrev', None) is None |
84 and repo.currenttopic): |
84 and repo.currenttopic): |
85 return orig(ui, repo) |
85 return orig(ui, repo) |
86 revs = repo.revs('::. and stack()') |
86 revs = repo.revs(b'::. and stack()') |
87 if revs: |
87 if revs: |
88 return revs.min() |
88 return revs.min() |
89 return None |
89 return None |
90 |
90 |
91 def ngtip(repo, branch, all=False): |
91 def ngtip(repo, branch, all=False): |
105 return [tmap.branchtip(branch)] |
105 return [tmap.branchtip(branch)] |
106 |
106 |
107 def modsetup(ui): |
107 def modsetup(ui): |
108 """run a uisetup time to install all destinations wrapping""" |
108 """run a uisetup time to install all destinations wrapping""" |
109 extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch) |
109 extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch) |
110 bridx = destutil.destupdatesteps.index('branch') |
110 bridx = destutil.destupdatesteps.index(b'branch') |
111 destutil.destupdatesteps.insert(bridx, 'topic') |
111 destutil.destupdatesteps.insert(bridx, b'topic') |
112 destutil.destupdatestepmap['topic'] = _destupdatetopic |
112 destutil.destupdatestepmap[b'topic'] = _destupdatetopic |
113 extensions.wrapfunction(destutil, 'desthistedit', desthistedit) |
113 extensions.wrapfunction(destutil, 'desthistedit', desthistedit) |