Mercurial > hg
annotate mercurial/simplemerge.py @ 26217:0d0a0837895d
hgweb: remove proxy to hgweb instance
We were temporarily routing attributes until all request-specific
attributes from hgweb were moved to requestcontext. We have finally
reached that juncture and we can remove the proxy.
At this point, only the repo instance is prone to race conditions
between threads. This will be dealt with shortly.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 22 Aug 2015 17:50:28 -0700 |
parents | 09d6725cbc60 |
children | ed12abab068e |
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='>>>>>>>', |
22023
f18830651811
simplemerge: burn "minimal" feature to the ground
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21272
diff
changeset
|
93 base_marker=None): |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
94 """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
|
95 """ |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
96 self.conflicts = False |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
97 newline = '\n' |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
98 if len(self.a) > 0: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
99 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
|
100 newline = '\r\n' |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
101 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
|
102 newline = '\r' |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 merge_regions = self.merge_regions() |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
110 for t in merge_regions: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
111 what = t[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
112 if what == 'unchanged': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
113 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
|
114 yield self.base[i] |
12401
4cdaf1adafc8
backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents:
12387
diff
changeset
|
115 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
|
116 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
|
117 yield self.a[i] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
118 elif what == 'b': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
119 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
|
120 yield self.b[i] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
121 elif what == 'conflict': |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
122 self.conflicts = True |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
123 if start_marker is not None: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
124 yield start_marker + newline |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
125 for i in range(t[3], t[4]): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
126 yield self.a[i] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
127 if base_marker is not None: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
128 yield base_marker + newline |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
129 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
|
130 yield self.base[i] |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
131 if mid_marker is not None: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
132 yield mid_marker + newline |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
133 for i in range(t[5], t[6]): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
134 yield self.b[i] |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
135 if end_marker is not None: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
136 yield end_marker + newline |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
137 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
138 raise ValueError(what) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
139 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
140 def merge_groups(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
141 """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
|
142 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
143 'unchanged', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
144 Lines unchanged from base |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
145 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
146 'a', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
147 Lines taken from a |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
148 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
149 'same', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
150 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
|
151 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
152 'b', lines |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
153 Lines taken from b |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
154 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
155 '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
|
156 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
|
157 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
158 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
|
159 what = t[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
160 if what == 'unchanged': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
161 yield what, self.base[t[1]:t[2]] |
12401
4cdaf1adafc8
backout most of 4f8067c94729
Matt Mackall <mpm@selenic.com>
parents:
12387
diff
changeset
|
162 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
|
163 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
|
164 elif what == 'b': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
165 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
|
166 elif what == 'conflict': |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
167 yield (what, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
172 raise ValueError(what) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
173 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
174 def merge_regions(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
175 """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
|
176 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
177 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
|
178 have: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
179 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
180 'unchanged', start, end |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
181 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
|
182 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
183 'same', astart, aend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
184 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
|
185 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
186 'a', start, end |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
187 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
|
188 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
189 Method is as follows: |
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 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
197 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
|
198 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
|
199 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
200 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
201 # 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
|
202 iz = ia = ib = 0 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
203 |
16683 | 204 for region in self.find_sync_regions(): |
205 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
|
206 #print 'match base [%d:%d]' % (zmatch, zend) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
207 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
208 matchlen = zend - zmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
209 assert matchlen >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
210 assert matchlen == (aend - amatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
211 assert matchlen == (bend - bmatch) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
212 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
213 len_a = amatch - ia |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
214 len_b = bmatch - ib |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
215 len_base = zmatch - iz |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
216 assert len_a >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
217 assert len_b >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
218 assert len_base >= 0 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
219 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
220 #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
|
221 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
222 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
|
223 # 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
|
224 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
|
225 self.base, iz, zmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
226 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
|
227 self.base, iz, zmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
228 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
|
229 self.b, ib, bmatch) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
230 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
231 if same: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
232 yield 'same', ia, amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
233 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
|
234 yield 'b', ib, bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
235 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
|
236 yield 'a', ia, amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
237 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
|
238 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
|
239 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
240 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
|
241 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
242 ia = amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
243 ib = bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
244 iz = zmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
245 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
246 # 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
|
247 # 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
|
248 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
249 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
250 if matchlen > 0: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
251 assert ia == amatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
252 assert ib == bmatch |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
253 assert iz == zmatch |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
254 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
255 yield 'unchanged', zmatch, zend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
256 iz = zend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
257 ia = aend |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
258 ib = bend |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
259 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
260 def find_sync_regions(self): |
14549
48ec0763afbb
check-code: catch misspellings of descendant
Matt Mackall <mpm@selenic.com>
parents:
14329
diff
changeset
|
261 """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
|
262 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
263 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
|
264 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
|
265 """ |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
266 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
267 ia = ib = 0 |
4363
2e3c54fb79a3
actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4362
diff
changeset
|
268 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
|
269 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
|
270 len_a = len(amatches) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
271 len_b = len(bmatches) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
272 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
273 sl = [] |
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 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
|
276 abase, amatch, alen = amatches[ia] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
277 bbase, bmatch, blen = bmatches[ib] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
278 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
279 # 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
|
280 # extend? until whichever one ends earlier. |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
8312
diff
changeset
|
281 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
|
282 if i: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
283 intbase = i[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
284 intend = i[1] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
285 intlen = intend - intbase |
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 # 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
|
288 # 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
|
289 assert intlen <= alen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
290 assert intlen <= blen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
291 assert abase <= intbase |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
292 assert bbase <= intbase |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
293 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
294 asub = amatch + (intbase - abase) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
295 bsub = bmatch + (intbase - bbase) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
296 aend = asub + intlen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
297 bend = bsub + intlen |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
298 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
299 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
|
300 (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
|
301 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
302 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
|
303 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
304 sl.append((intbase, intend, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
305 asub, aend, |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
306 bsub, bend)) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
307 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
308 # 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
|
309 if (abase + alen) < (bbase + blen): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
310 ia += 1 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
311 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
312 ib += 1 |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
313 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
314 intbase = len(self.base) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
315 abase = len(self.a) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
316 bbase = len(self.b) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
317 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
|
318 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
319 return sl |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
320 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
321 def find_unconflicted(self): |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
322 """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
|
323 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
|
324 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
|
325 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
326 unc = [] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
327 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
328 while am and bm: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
329 # 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
|
330 # 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
|
331 a1 = am[0][0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
332 a2 = a1 + am[0][2] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
333 b1 = bm[0][0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
334 b2 = b1 + bm[0][2] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
335 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
|
336 if i: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
337 unc.append(i) |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
338 |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
339 if a2 < b2: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
340 del am[0] |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
341 else: |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
342 del bm[0] |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4408
diff
changeset
|
343 |
4362
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
344 return unc |
465b9ea02868
Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
345 |
8269
bb9f13974d8e
simplemerge: use ui.warn() for warnings
Steve Borho <steve@borho.org>
parents:
7280
diff
changeset
|
346 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
|
347 def readfile(filename): |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
348 f = open(filename, "rb") |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
349 text = f.read() |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
350 f.close() |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
351 if util.binary(text): |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 raise util.Abort(msg) |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
357 return text |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
358 |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
359 mode = opts.get('mode','merge') |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
360 if mode == 'union': |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
361 name_a = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
362 name_b = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
363 name_base = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
364 else: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
365 name_a = local |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
366 name_b = other |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
367 name_base = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
368 labels = opts.get('label', []) |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
369 if len(labels) > 0: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
370 name_a = labels[0] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
371 if len(labels) > 1: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
372 name_b = labels[1] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
373 if len(labels) > 2: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
374 name_base = labels[2] |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
375 if len(labels) > 3: |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
376 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
|
377 |
14328
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
378 try: |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
379 localtext = readfile(local) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
380 basetext = readfile(base) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
381 othertext = readfile(other) |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
382 except util.Abort: |
3c65cdcf3ba6
simplemerge: do not allow binary files to abort an entire merge
Steve Borho <steve@borho.org>
parents:
12401
diff
changeset
|
383 return 1 |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
384 |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
385 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
|
386 if not opts.get('print'): |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
12401
diff
changeset
|
387 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
|
388 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
|
389 else: |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
390 out = sys.stdout |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
391 |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
392 m3 = Merge3Text(basetext, localtext, othertext) |
22024
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
393 extrakwargs = {} |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
394 if mode == 'union': |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
395 extrakwargs['start_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
396 extrakwargs['mid_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
397 extrakwargs['end_marker'] = None |
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
398 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
|
399 extrakwargs['base_marker'] = '|||||||' |
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
400 extrakwargs['name_base'] = name_base |
372ae2745acf
simplemerge: support three labels when merging
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
401 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
|
402 out.write(line) |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
403 |
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
404 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
|
405 out.close() |
4364
d5c3a70f8422
polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4363
diff
changeset
|
406 |
26069
09d6725cbc60
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers
Erik Huelsmann <ehuels@gmail.com>
parents:
25974
diff
changeset
|
407 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
|
408 if not opts.get('quiet'): |
8269
bb9f13974d8e
simplemerge: use ui.warn() for warnings
Steve Borho <steve@borho.org>
parents:
7280
diff
changeset
|
409 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
|
410 return 1 |