5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 from __future__ import absolute_import |
8 from __future__ import absolute_import |
9 |
9 |
10 from mercurial.i18n import _ |
|
11 from mercurial import ( |
10 from mercurial import ( |
12 copies, |
11 copies, |
13 error, |
|
14 extensions, |
12 extensions, |
15 merge, |
13 merge, |
16 ) |
14 ) |
17 |
15 |
18 def setup(): |
16 def setup(): |
19 def _manifestmerge(orig, repo, wctx, p2, pa, branchmerge, *args, **kwargs): |
|
20 """Filter updates to only lay out files that match the narrow spec.""" |
|
21 actions, diverge, renamedelete = orig( |
|
22 repo, wctx, p2, pa, branchmerge, *args, **kwargs) |
|
23 |
|
24 narrowmatch = repo.narrowmatch() |
|
25 if narrowmatch.always(): |
|
26 return actions, diverge, renamedelete |
|
27 |
|
28 nooptypes = set(['k']) # TODO: handle with nonconflicttypes |
|
29 nonconflicttypes = set('a am c cm f g r e'.split()) |
|
30 # We mutate the items in the dict during iteration, so iterate |
|
31 # over a copy. |
|
32 for f, action in list(actions.items()): |
|
33 if narrowmatch(f): |
|
34 pass |
|
35 elif not branchmerge: |
|
36 del actions[f] # just updating, ignore changes outside clone |
|
37 elif action[0] in nooptypes: |
|
38 del actions[f] # merge does not affect file |
|
39 elif action[0] in nonconflicttypes: |
|
40 raise error.Abort(_('merge affects file \'%s\' outside narrow, ' |
|
41 'which is not yet supported') % f, |
|
42 hint=_('merging in the other direction ' |
|
43 'may work')) |
|
44 else: |
|
45 raise error.Abort(_('conflict in file \'%s\' is outside ' |
|
46 'narrow clone') % f) |
|
47 |
|
48 return actions, diverge, renamedelete |
|
49 |
|
50 extensions.wrapfunction(merge, 'manifestmerge', _manifestmerge) |
|
51 |
|
52 def _checkcollision(orig, repo, wmf, actions): |
17 def _checkcollision(orig, repo, wmf, actions): |
53 narrowmatch = repo.narrowmatch() |
18 narrowmatch = repo.narrowmatch() |
54 if not narrowmatch.always(): |
19 if not narrowmatch.always(): |
55 wmf = wmf.matches(narrowmatch) |
20 wmf = wmf.matches(narrowmatch) |
56 if actions: |
21 if actions: |