author | Sean Farley <sean@farley.io> |
Mon, 21 Mar 2016 21:25:04 -0700 | |
changeset 1920 | 2a28bd7eab31 |
parent 1912 | 692a1aa1350c |
child 1933 | ca8674a8fce4 |
permissions | -rw-r--r-- |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
1 |
from mercurial import error |
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
2 |
from mercurial import util |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
3 |
from mercurial import destutil |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
4 |
from mercurial import extensions |
1892
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
5 |
from mercurial import bookmarks |
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
6 |
from mercurial.i18n import _ |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
7 |
|
1878
c44f161575ba
compat: adapt to change in mercurial core
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1871
diff
changeset
|
8 |
def _destmergebranch(orig, repo, action='merge', sourceset=None, onheadcheck=True): |
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
9 |
p1 = repo['.'] |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
10 |
top = p1.topic() |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
11 |
if top: |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
12 |
heads = repo.revs('heads(topic(.)::topic(.))') |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
13 |
if p1.rev() not in heads: |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
14 |
raise error.Abort(_("not at topic head, update or explicit")) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
15 |
elif 1 == len(heads): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
16 |
# should look at all branch involved but... later |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
17 |
bhead = ngtip(repo, p1.branch(), all=True) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
18 |
if not bhead: |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
19 |
raise error.Abort(_("nothing to merge")) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
20 |
elif 1 == len(bhead): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
21 |
return bhead.first() |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
22 |
else: |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
23 |
raise error.Abort(_("branch '%s' has %d heads - " |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
24 |
"please merge with an explicit rev") |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
25 |
% (p1.branch(), len(bhead)), |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
26 |
hint=_("run 'hg heads .' to see heads")) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
27 |
elif 2 == len(heads): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
28 |
heads = [r for r in heads if r != p1.rev()] |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
29 |
# XXX: bla bla bla bla bla |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
30 |
if 1 < len(heads): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
31 |
raise error.Abort(_('working directory not at a head revision'), |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
32 |
hint=_("use 'hg update' or merge with an " |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
33 |
"explicit revision")) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
34 |
return heads[0] |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
35 |
elif 2 < len(heads): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
36 |
raise error.Abort(_("topic '%s' has %d heads - " |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
37 |
"please merge with an explicit rev") |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
38 |
% (top, len(heads))) |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
39 |
else: |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
40 |
assert False # that's impossible |
1902
93cf0ddb5234
destination: fix 'hg pull --rebase'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
41 |
if getattr(orig, 'func_default', ()): # version above hg-3.7 |
1878
c44f161575ba
compat: adapt to change in mercurial core
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1871
diff
changeset
|
42 |
return orig(repo, action, sourceset, onheadcheck) |
c44f161575ba
compat: adapt to change in mercurial core
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1871
diff
changeset
|
43 |
else: |
c44f161575ba
compat: adapt to change in mercurial core
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1871
diff
changeset
|
44 |
return orig(repo) |
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
45 |
|
1892
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
46 |
def _destupdatetopic(repo, clean, check): |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
47 |
"""decide on an update destination from current topic""" |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
48 |
movemark = node = None |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
49 |
topic = repo.currenttopic |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
50 |
revs = repo.revs('.::topic("%s")' % topic) |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
51 |
if not revs: |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
52 |
return None, None, None |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
53 |
node = revs.last() |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
54 |
if bookmarks.isactivewdirparent(repo): |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
55 |
movemark = repo['.'].node() |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
56 |
return node, movemark, None |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
57 |
|
1911
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
58 |
def desthistedit(orig, ui, repo): |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
59 |
if not (ui.config('histedit', 'defaultrev', None) is None |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
60 |
and repo.currenttopic): |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
61 |
return orig(ui, repo) |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
62 |
revs = repo.revs('::. and stack()') |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
63 |
if revs: |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
64 |
return revs.min() |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
65 |
return None |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
66 |
|
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
67 |
def setupdest(): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
68 |
if util.safehasattr(destutil, '_destmergebranch'): |
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
69 |
extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch) |
1891
077c40f206d1
rebase: test default rebase destination behavior
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1878
diff
changeset
|
70 |
rebase = extensions.find('rebase') |
077c40f206d1
rebase: test default rebase destination behavior
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1878
diff
changeset
|
71 |
if (util.safehasattr(rebase, '_destrebase') |
077c40f206d1
rebase: test default rebase destination behavior
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1878
diff
changeset
|
72 |
# logic not shared with merge yet < hg-3.8 |
077c40f206d1
rebase: test default rebase destination behavior
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1878
diff
changeset
|
73 |
and not util.safehasattr(rebase, '_definesets')): |
077c40f206d1
rebase: test default rebase destination behavior
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1878
diff
changeset
|
74 |
extensions.wrapfunction(rebase, '_destrebase', _destmergebranch) |
1892
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
75 |
if util.safehasattr(destutil, 'destupdatesteps'): |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
76 |
bridx = destutil.destupdatesteps.index('branch') |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
77 |
destutil.destupdatesteps.insert(bridx, 'topic') |
b1fadc089b82
update: change default update destination to take topic in account
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1891
diff
changeset
|
78 |
destutil.destupdatestepmap['topic'] = _destupdatetopic |
1911
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
79 |
if util.safehasattr(destutil, 'desthistedit'): |
442a7cb8404e
histedit: restrict default edited set to current topic when possible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1902
diff
changeset
|
80 |
extensions.wrapfunction(destutil, 'desthistedit', desthistedit) |
1871
58ef5699fb35
merge: use topic to pick default destination
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1870
diff
changeset
|
81 |
|
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
82 |
def ngtip(repo, branch, all=False): |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
83 |
"""tip new generation""" |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
84 |
## search for untopiced heads of branch |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
85 |
# could be heads((::branch(x) - topic())) |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
86 |
# but that is expensive |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
87 |
# |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
88 |
# we should write plain code instead |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
89 |
subquery = '''heads( |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
90 |
parents( |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
91 |
ancestor( |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
92 |
(head() and branch(%s) |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
93 |
or (topic() and branch(%s))))) |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
94 |
::(head() and branch(%s)) |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
95 |
- topic())''' |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
96 |
if not all: |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
97 |
subquery = 'max(%s)' % subquery |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
98 |
return repo.revs(subquery, branch, branch, branch) |