Mercurial > hg
comparison mercurial/destutil.py @ 26720:6c22a17faa18
destupdate: extract validation logic
One of the main goal of having consolidated destination function is to allow
extension to play with this logic. We extract sub logic to make is wrapping more
practical.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 15 Oct 2015 14:10:57 +0100 |
parents | 9903261dcc81 |
children | 3d094fbedf74 |
comparison
equal
deleted
inserted
replaced
26719:8bed1eae99df | 26720:6c22a17faa18 |
---|---|
9 from . import ( | 9 from . import ( |
10 bookmarks, | 10 bookmarks, |
11 error, | 11 error, |
12 obsolete, | 12 obsolete, |
13 ) | 13 ) |
14 | |
15 def _destupdatevalidate(repo, rev, clean, check): | |
16 """validate that the destination comply to various rules | |
17 | |
18 This exists as its own function to help wrapping from extensions.""" | |
19 wc = repo[None] | |
20 p1 = wc.p1() | |
21 if not clean: | |
22 # Check that the update is linear. | |
23 # | |
24 # Mercurial do not allow update-merge for non linear pattern | |
25 # (that would be technically possible but was considered too confusing | |
26 # for user a long time ago) | |
27 # | |
28 # See mercurial.merge.update for details | |
29 if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): | |
30 dirty = wc.dirty(missing=True) | |
31 foreground = obsolete.foreground(repo, [p1.node()]) | |
32 if not repo[rev].node() in foreground: | |
33 if dirty: | |
34 msg = _("uncommitted changes") | |
35 hint = _("commit and merge, or update --clean to" | |
36 " discard changes") | |
37 raise error.UpdateAbort(msg, hint=hint) | |
38 elif not check: # destination is not a descendant. | |
39 msg = _("not a linear update") | |
40 hint = _("merge or update --check to force update") | |
41 raise error.UpdateAbort(msg, hint=hint) | |
14 | 42 |
15 def destupdate(repo, clean=False, check=False): | 43 def destupdate(repo, clean=False, check=False): |
16 """destination for bare update operation | 44 """destination for bare update operation |
17 | 45 |
18 return (rev, movemark, activemark) | 46 return (rev, movemark, activemark) |
66 # get the max revision for the given successors set, | 94 # get the max revision for the given successors set, |
67 # i.e. the 'tip' of a set | 95 # i.e. the 'tip' of a set |
68 node = repo.revs('max(%ln)', successors).first() | 96 node = repo.revs('max(%ln)', successors).first() |
69 rev = repo[node].rev() | 97 rev = repo[node].rev() |
70 | 98 |
71 if not clean: | 99 _destupdatevalidate(repo, rev, clean, check) |
72 # Check that the update is linear. | |
73 # | |
74 # Mercurial do not allow update-merge for non linear pattern | |
75 # (that would be technically possible but was considered too confusing | |
76 # for user a long time ago) | |
77 # | |
78 # See mercurial.merge.update for details | |
79 if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): | |
80 dirty = wc.dirty(missing=True) | |
81 foreground = obsolete.foreground(repo, [p1.node()]) | |
82 if not repo[rev].node() in foreground: | |
83 if dirty: | |
84 msg = _("uncommitted changes") | |
85 hint = _("commit and merge, or update --clean to" | |
86 " discard changes") | |
87 raise error.UpdateAbort(msg, hint=hint) | |
88 elif not check: # destination is not a descendant. | |
89 msg = _("not a linear update") | |
90 hint = _("merge or update --check to force update") | |
91 raise error.UpdateAbort(msg, hint=hint) | |
92 | 100 |
93 return rev, movemark, activemark | 101 return rev, movemark, activemark |
94 | 102 |
95 def destmerge(repo): | 103 def destmerge(repo): |
96 if repo._activebookmark: | 104 if repo._activebookmark: |