Mercurial > hg
annotate mercurial/simplemerge.py @ 26351:8c7d8d5e1e0f
mercurial: add debugextensions command (issue4676)
Add debugextensions command to help users debug their extension
problems. If there are no extensions command prints nothing,
otherwise it prints names of extension modules. If quiet or
verbose option is not specified it prints(after extensions name)
last version of mercurial in which given module was tested for
non internal modules or not tested with user mercurial version.
If verbose is specified it prints following information for every
extension: extension name, import source, testedwith and buglink
information.
Extensions are printed sorted by extension name.
author | liscju <piotr.listkiewicz@gmail.com> |
---|---|
date | Thu, 10 Sep 2015 16:53:07 +0200 |
parents | ed12abab068e |
children | 56b2bcea2529 |
rev | line source |
---|---|
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
1 # Copyright (C) 2004, 2005 Canonical Ltd |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
2 # |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
3 # This program is free software; you can redistribute it and/or modify |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
5 # the Free Software Foundation; either version 2 of the License, or |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
6 # (at your option) any later version. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
7 # |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
8 # This program is distributed in the hope that it will be useful, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
11 # GNU General Public License for more details. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
12 # |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
15782
7de7630053cb
Remove FSF mailing address from GPL headers
Martin Geisler <mg@aragost.com>
parents:
15381
diff
changeset
|
14 # along with this program; if not, see <http://www.gnu.org/licenses/>. |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
15 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
16 # mbp: "you know that thing where cvs gives you conflict markers?" |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
17 # s: "i hate that." |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
18 |
25974
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
19 from __future__ import absolute_import |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
20 |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
21 import os |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
22 import sys |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
23 |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
24 from .i18n import _ |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
25 from . import ( |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
26 mdiff, |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
27 scmutil, |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
28 util, |
241a1324a180
simplemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22056
diff
changeset
|
29 ) |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
30 |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
31 class CantReprocessAndShowBase(Exception): |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
32 pass |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
33 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
34 def intersect(ra, rb): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
35 """Given two ranges return the range where they intersect or None. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
36 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
37 >>> intersect((0, 10), (0, 6)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
38 (0, 6) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
39 >>> intersect((0, 10), (5, 15)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
40 (5, 10) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
41 >>> intersect((0, 10), (10, 15)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
42 >>> intersect((0, 9), (10, 15)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
43 >>> intersect((0, 9), (7, 15)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
44 (7, 9) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
45 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
46 assert ra[0] <= ra[1] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
47 assert rb[0] <= rb[1] |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
48 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
49 sa = max(ra[0], rb[0]) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
50 sb = min(ra[1], rb[1]) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
51 if sa < sb: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
52 return sa, sb |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
53 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
54 return None |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
55 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
56 def compare_range(a, astart, aend, b, bstart, bend): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
57 """Compare a[astart:aend] == b[bstart:bend], without slicing. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
58 """ |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
8312
diff
changeset
|
59 if (aend - astart) != (bend - bstart): |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
60 return False |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
61 for ia, ib in zip(xrange(astart, aend), xrange(bstart, bend)): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
62 if a[ia] != b[ib]: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
63 return False |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
64 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
65 return True |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
66 |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
67 class Merge3Text(object): |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
68 """3-way merge of texts. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
69 |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
70 Given strings BASE, OTHER, THIS, tries to produce a combined text |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
71 incorporating the changes from both BASE->OTHER and BASE->THIS.""" |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
72 def __init__(self, basetext, atext, btext, base=None, a=None, b=None): |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
73 self.basetext = basetext |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
74 self.atext = atext |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
75 self.btext = btext |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
76 if base is None: |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
77 base = mdiff.splitnewlines(basetext) |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
78 if a is None: |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
79 a = mdiff.splitnewlines(atext) |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
80 if b is None: |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
81 b = mdiff.splitnewlines(btext) |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
82 self.base = base |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
83 self.a = a |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
84 self.b = b |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
85 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
86 def merge_lines(self, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
87 name_a=None, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
88 name_b=None, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
89 name_base=None, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
90 start_marker='<<<<<<<', |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
91 mid_marker='=======', |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
92 end_marker='>>>>>>>', |
26223
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
93 base_marker=None, |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
94 localorother=None): |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
95 """Return merge in cvs-like form. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
96 """ |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
97 self.conflicts = False |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
98 newline = '\n' |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
99 if len(self.a) > 0: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
100 if self.a[0].endswith('\r\n'): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
101 newline = '\r\n' |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
102 elif self.a[0].endswith('\r'): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
103 newline = '\r' |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
104 if name_a and start_marker: |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
105 start_marker = start_marker + ' ' + name_a |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
106 if name_b and end_marker: |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
107 end_marker = end_marker + ' ' + name_b |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
108 if name_base and base_marker: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
109 base_marker = base_marker + ' ' + name_base |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
110 merge_regions = self.merge_regions() |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
111 for t in merge_regions: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
112 what = t[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
113 if what == 'unchanged': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
114 for i in range(t[1], t[2]): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
115 yield self.base[i] |
12401
4cdaf1adafc8
backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents:
12387
diff
changeset
|
116 elif what == 'a' or what == 'same': |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
117 for i in range(t[1], t[2]): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
118 yield self.a[i] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
119 elif what == 'b': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
120 for i in range(t[1], t[2]): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
121 yield self.b[i] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
122 elif what == 'conflict': |
26223
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
123 if localorother == 'local': |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
124 for i in range(t[3], t[4]): |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
125 yield self.a[i] |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
126 elif localorother == 'other': |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
127 for i in range(t[5], t[6]): |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
128 yield self.b[i] |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
129 else: |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
130 self.conflicts = True |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
131 if start_marker is not None: |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
132 yield start_marker + newline |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
133 for i in range(t[3], t[4]): |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
134 yield self.a[i] |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
135 if base_marker is not None: |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
136 yield base_marker + newline |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
137 for i in range(t[1], t[2]): |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
138 yield self.base[i] |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
139 if mid_marker is not None: |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
140 yield mid_marker + newline |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
141 for i in range(t[5], t[6]): |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
142 yield self.b[i] |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
143 if end_marker is not None: |
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
144 yield end_marker + newline |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
145 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
146 raise ValueError(what) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
147 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
148 def merge_groups(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
149 """Yield sequence of line groups. Each one is a tuple: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
150 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
151 'unchanged', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
152 Lines unchanged from base |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
153 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
154 'a', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
155 Lines taken from a |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
156 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
157 'same', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
158 Lines taken from a (and equal to b) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
159 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
160 'b', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
161 Lines taken from b |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
162 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
163 'conflict', base_lines, a_lines, b_lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
164 Lines from base were changed to either a or b and conflict. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
165 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
166 for t in self.merge_regions(): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
167 what = t[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
168 if what == 'unchanged': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
169 yield what, self.base[t[1]:t[2]] |
12401
4cdaf1adafc8
backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents:
12387
diff
changeset
|
170 elif what == 'a' or what == 'same': |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
171 yield what, self.a[t[1]:t[2]] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
172 elif what == 'b': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
173 yield what, self.b[t[1]:t[2]] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
174 elif what == 'conflict': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
175 yield (what, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
176 self.base[t[1]:t[2]], |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
177 self.a[t[3]:t[4]], |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
178 self.b[t[5]:t[6]]) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
179 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
180 raise ValueError(what) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
181 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
182 def merge_regions(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
183 """Return sequences of matching and conflicting regions. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
184 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
185 This returns tuples, where the first value says what kind we |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
186 have: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
187 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
188 'unchanged', start, end |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
189 Take a region of base[start:end] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
190 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
191 'same', astart, aend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
192 b and a are different from base but give the same result |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
193 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
194 'a', start, end |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
195 Non-clashing insertion from a[start:end] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
196 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
197 Method is as follows: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
198 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
199 The two sequences align only on regions which match the base |
14549
48ec0763afbb
check-code: catch misspellings of descendant
Matt Mackall <mpm@selenic.com>
parents:
14329
diff
changeset
|
200 and both descendants. These are found by doing a two-way diff |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
201 of each one against the base, and then finding the |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
202 intersections between those regions. These "sync regions" |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
203 are by definition unchanged in both and easily dealt with. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
204 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
205 The regions in between can be in any of three cases: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
206 conflicted, or changed on only one side. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
207 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
208 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
209 # section a[0:ia] has been disposed of, etc |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
210 iz = ia = ib = 0 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
211 |
16683 | 212 for region in self.find_sync_regions(): |
213 zmatch, zend, amatch, aend, bmatch, bend = region | |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
214 #print 'match base [%d:%d]' % (zmatch, zend) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
215 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
216 matchlen = zend - zmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
217 assert matchlen >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
218 assert matchlen == (aend - amatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
219 assert matchlen == (bend - bmatch) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
220 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
221 len_a = amatch - ia |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
222 len_b = bmatch - ib |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
223 len_base = zmatch - iz |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
224 assert len_a >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
225 assert len_b >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
226 assert len_base >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
227 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
228 #print 'unmatched a=%d, b=%d' % (len_a, len_b) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
229 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
230 if len_a or len_b: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
231 # try to avoid actually slicing the lists |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
232 equal_a = compare_range(self.a, ia, amatch, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
233 self.base, iz, zmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
234 equal_b = compare_range(self.b, ib, bmatch, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
235 self.base, iz, zmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
236 same = compare_range(self.a, ia, amatch, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
237 self.b, ib, bmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
238 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
239 if same: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
240 yield 'same', ia, amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
241 elif equal_a and not equal_b: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
242 yield 'b', ib, bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
243 elif equal_b and not equal_a: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
244 yield 'a', ia, amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
245 elif not equal_a and not equal_b: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
246 yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
247 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
248 raise AssertionError("can't handle a=b=base but unmatched") |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
249 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
250 ia = amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
251 ib = bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
252 iz = zmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
253 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
254 # if the same part of the base was deleted on both sides |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
255 # that's OK, we can just skip it. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
256 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
257 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
258 if matchlen > 0: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
259 assert ia == amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
260 assert ib == bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
261 assert iz == zmatch |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
262 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
263 yield 'unchanged', zmatch, zend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
264 iz = zend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
265 ia = aend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
266 ib = bend |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
267 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
268 def find_sync_regions(self): |
14549
48ec0763afbb
check-code: catch misspellings of descendant
Matt Mackall <mpm@selenic.com>
parents:
14329
diff
changeset
|
269 """Return a list of sync regions, where both descendants match the base. |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
270 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
271 Generates a list of (base1, base2, a1, a2, b1, b2). There is |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
272 always a zero-length sync region at the end of all the files. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
273 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
274 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
275 ia = ib = 0 |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
276 amatches = mdiff.get_matching_blocks(self.basetext, self.atext) |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
277 bmatches = mdiff.get_matching_blocks(self.basetext, self.btext) |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
278 len_a = len(amatches) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
279 len_b = len(bmatches) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
280 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
281 sl = [] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
282 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
283 while ia < len_a and ib < len_b: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
284 abase, amatch, alen = amatches[ia] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
285 bbase, bmatch, blen = bmatches[ib] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
286 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
287 # there is an unconflicted block at i; how long does it |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
288 # extend? until whichever one ends earlier. |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
8312
diff
changeset
|
289 i = intersect((abase, abase + alen), (bbase, bbase + blen)) |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
290 if i: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
291 intbase = i[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
292 intend = i[1] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
293 intlen = intend - intbase |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
294 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
295 # found a match of base[i[0], i[1]]; this may be less than |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
296 # the region that matches in either one |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
297 assert intlen <= alen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
298 assert intlen <= blen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
299 assert abase <= intbase |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
300 assert bbase <= intbase |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
301 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
302 asub = amatch + (intbase - abase) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
303 bsub = bmatch + (intbase - bbase) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
304 aend = asub + intlen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
305 bend = bsub + intlen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
306 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
307 assert self.base[intbase:intend] == self.a[asub:aend], \ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
308 (self.base[intbase:intend], self.a[asub:aend]) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
309 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
310 assert self.base[intbase:intend] == self.b[bsub:bend] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
311 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
312 sl.append((intbase, intend, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
313 asub, aend, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
314 bsub, bend)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
315 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
316 # advance whichever one ends first in the base text |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
317 if (abase + alen) < (bbase + blen): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
318 ia += 1 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
319 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
320 ib += 1 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
321 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
322 intbase = len(self.base) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
323 abase = len(self.a) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
324 bbase = len(self.b) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
325 sl.append((intbase, intbase, abase, abase, bbase, bbase)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
326 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
327 return sl |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
328 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
329 def find_unconflicted(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
330 """Return a list of ranges in base that are not conflicted.""" |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
331 am = mdiff.get_matching_blocks(self.basetext, self.atext) |
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
332 bm = mdiff.get_matching_blocks(self.basetext, self.btext) |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
333 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
334 unc = [] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
335 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
336 while am and bm: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
337 # there is an unconflicted block at i; how long does it |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
338 # extend? until whichever one ends earlier. |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
339 a1 = am[0][0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
340 a2 = a1 + am[0][2] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
341 b1 = bm[0][0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
342 b2 = b1 + bm[0][2] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
343 i = intersect((a1, a2), (b1, b2)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
344 if i: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
345 unc.append(i) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
346 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
347 if a2 < b2: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
348 del am[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
349 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
350 del bm[0] |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
351 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
352 return unc |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
353 |
8269
bb9f13974d8e
simplemerge: use ui.warn() for warnings
Steve Borho <steve@borho.org>
parents:
7280
diff
changeset
|
354 def simplemerge(ui, local, base, other, **opts): |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
355 def readfile(filename): |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
356 f = open(filename, "rb") |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
357 text = f.read() |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
358 f.close() |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
359 if util.binary(text): |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
360 msg = _("%s looks like a binary file.") % filename |
14328
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
361 if not opts.get('quiet'): |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
362 ui.warn(_('warning: %s\n') % msg) |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
363 if not opts.get('text'): |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
364 raise util.Abort(msg) |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
365 return text |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
366 |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
367 mode = opts.get('mode','merge') |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
368 if mode == 'union': |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
369 name_a = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
370 name_b = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
371 name_base = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
372 else: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
373 name_a = local |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
374 name_b = other |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
375 name_base = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
376 labels = opts.get('label', []) |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
377 if len(labels) > 0: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
378 name_a = labels[0] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
379 if len(labels) > 1: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
380 name_b = labels[1] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
381 if len(labels) > 2: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
382 name_base = labels[2] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
383 if len(labels) > 3: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
384 raise util.Abort(_("can only specify three labels.")) |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
385 |
14328
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
386 try: |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
387 localtext = readfile(local) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
388 basetext = readfile(base) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
389 othertext = readfile(other) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
390 except util.Abort: |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
391 return 1 |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
392 |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
393 local = os.path.realpath(local) |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
394 if not opts.get('print'): |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
12401
diff
changeset
|
395 opener = scmutil.opener(os.path.dirname(local)) |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
396 out = opener(os.path.basename(local), "w", atomictemp=True) |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
397 else: |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
398 out = sys.stdout |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
399 |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
400 m3 = Merge3Text(basetext, localtext, othertext) |
26223
ed12abab068e
simplemerge: enable option to resolve conflicts one way
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26069
diff
changeset
|
401 extrakwargs = {"localorother": opts.get("localorother", None)} |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
402 if mode == 'union': |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
403 extrakwargs['start_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
404 extrakwargs['mid_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
405 extrakwargs['end_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
406 elif name_base is not None: |
22024
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
407 extrakwargs['base_marker'] = '|||||||' |
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
408 extrakwargs['name_base'] = name_base |
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
409 for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs): |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
410 out.write(line) |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
411 |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
412 if not opts.get('print'): |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14549
diff
changeset
|
413 out.close() |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
414 |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
415 if m3.conflicts and not mode == 'union': |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
416 if not opts.get('quiet'): |
8269
bb9f13974d8e
simplemerge: use ui.warn() for warnings
Steve Borho <steve@borho.org>
parents:
7280
diff
changeset
|
417 ui.warn(_("warning: conflicts during merge.\n")) |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
418 return 1 |